37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
"""Numéro de version du paquet, fourni au moment de la construction.
|
|
|
|
Aucun numéro n'est écrit dans le dépôt (``dynamic = ["version"]`` dans
|
|
pyproject.toml). Ordre de recherche :
|
|
|
|
1. ``SHORTSTATS_VERSION`` : passé par la construction de l'image Docker
|
|
(argument ``VERSION``), qui n'a pas l'historique git ;
|
|
2. ``scripts/version.sh`` : calculé d'après les étiquettes git (installation
|
|
depuis le dépôt, CI) ;
|
|
3. ``0+inconnue`` : ni l'un ni l'autre (archive sans historique).
|
|
|
|
Le code ne s'en sert qu'à titre d'information (affichage, ``--version``) :
|
|
``shortstats.__version__`` le relit dans les métadonnées du paquet installé.
|
|
"""
|
|
|
|
import os
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
from setuptools import setup
|
|
|
|
UNKNOWN = "0+inconnue"
|
|
|
|
|
|
def version() -> str:
|
|
given = os.environ.get("SHORTSTATS_VERSION", "").strip()
|
|
if given:
|
|
return given
|
|
script = Path(__file__).resolve().parent / "scripts" / "version.sh"
|
|
try:
|
|
out = subprocess.run(["sh", str(script)], capture_output=True, text=True, check=True, timeout=30)
|
|
return out.stdout.strip() or UNKNOWN
|
|
except (OSError, subprocess.SubprocessError):
|
|
return UNKNOWN
|
|
|
|
|
|
setup(version=version())
|