|
1 | 1 | # docs/source/conf.py |
2 | 2 |
|
| 3 | +import importlib.metadata |
| 4 | +import subprocess |
3 | 5 | import sys |
| 6 | +from importlib.metadata import PackageNotFoundError |
4 | 7 | from pathlib import Path |
5 | 8 |
|
6 | | -# sys.path.insert(0, os.path.abspath("../..")) |
7 | | -# using Path.resolve() |
8 | 9 | sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent)) |
9 | | -project = "biomassage" |
| 10 | + |
| 11 | +project = "topsocnww3sp" |
10 | 12 | copyright = "2026, umr-lops" |
11 | 13 | author = "umr-lops" |
12 | | -release = "0.1.0" # update to your actual version |
13 | 14 |
|
| 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 |
14 | 54 | 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", |
22 | 61 | ] |
23 | 62 |
|
24 | | -# MyST-Parser configuration |
| 63 | +# Configuration MyST |
25 | 64 | myst_enable_extensions = [ |
26 | 65 | "colon_fence", |
27 | 66 | "deflist", |
|
37 | 76 | ] |
38 | 77 | myst_heading_anchors = 3 |
39 | 78 |
|
40 | | -# For notebook execution (requires jupyter) |
41 | | -# myst_execute_notebooks = 'force' # or 'cache', 'off' |
42 | | - |
43 | | -# Default highlighting for code blocks |
44 | 79 | highlight_language = "bash" |
45 | 80 |
|
46 | 81 | templates_path = ["_templates"] |
|
0 commit comments