Skip to content

Commit afa2c3e

Browse files
committed
conf.py doc sphinx updt
1 parent 668e043 commit afa2c3e

1 file changed

Lines changed: 51 additions & 16 deletions

File tree

docs/conf.py

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,66 @@
11
# docs/source/conf.py
22

3+
import importlib.metadata
4+
import subprocess
35
import sys
6+
from importlib.metadata import PackageNotFoundError
47
from pathlib import Path
58

6-
# sys.path.insert(0, os.path.abspath("../.."))
7-
# using Path.resolve()
89
sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent))
9-
project = "biomassage"
10+
11+
project = "topsocnww3sp"
1012
copyright = "2026, umr-lops"
1113
author = "umr-lops"
12-
release = "0.1.0" # update to your actual version
1314

15+
16+
def get_version() -> str:
17+
"""Retrieve the package version dynamically."""
18+
# 1. Essayer d'importer depuis _version.py (généré par hatch-vcs)
19+
version_str = None
20+
try:
21+
# L'import est local car le fichier peut ne pas exister
22+
# (par ex. lors d'une compilation sans installation préalable)
23+
from topsocnww3sp._version import __version__ # noqa: PLC0415
24+
25+
version_str = __version__
26+
except ImportError:
27+
pass
28+
if version_str is not None:
29+
return version_str
30+
31+
# 2. Essayer via importlib.metadata (si le package est installé)
32+
try:
33+
return importlib.metadata.version("topsocnww3sp")
34+
except PackageNotFoundError:
35+
pass
36+
37+
# 3. Fallback : récupérer le tag git directement
38+
try:
39+
return subprocess.check_output(
40+
["git", "describe", "--tags", "--dirty=-dirty"],
41+
cwd=Path(__file__).parent.parent.parent,
42+
text=True,
43+
).strip()
44+
except (subprocess.CalledProcessError, FileNotFoundError):
45+
pass
46+
47+
# Valeur par défaut si tout échoue
48+
return "0.0.0+unknown"
49+
50+
51+
release = get_version()
52+
53+
# Extensions Sphinx
1454
extensions = [
15-
"myst_parser", # for Markdown/MyST support
16-
"sphinx.ext.autodoc", # generate API docs from docstrings
17-
"sphinx.ext.napoleon", # support NumPy/Google style docstrings
18-
"sphinx.ext.viewcode", # add links to source code
19-
"sphinx.ext.mathjax", # render math (e.g., $\rightarrow$)
20-
"sphinx.ext.intersphinx", # link to external documentation
21-
# 'nbsphinx', # uncomment if you want to execute notebooks
55+
"myst_parser",
56+
"sphinx.ext.autodoc",
57+
"sphinx.ext.napoleon",
58+
"sphinx.ext.viewcode",
59+
"sphinx.ext.mathjax",
60+
"sphinx.ext.intersphinx",
2261
]
2362

24-
# MyST-Parser configuration
63+
# Configuration MyST
2564
myst_enable_extensions = [
2665
"colon_fence",
2766
"deflist",
@@ -37,10 +76,6 @@
3776
]
3877
myst_heading_anchors = 3
3978

40-
# For notebook execution (requires jupyter)
41-
# myst_execute_notebooks = 'force' # or 'cache', 'off'
42-
43-
# Default highlighting for code blocks
4479
highlight_language = "bash"
4580

4681
templates_path = ["_templates"]

0 commit comments

Comments
 (0)