From e620ff2cbef7acad90ec49f9baaae64dd5a4a0b8 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Mon, 4 Dec 2023 16:35:36 +0100 Subject: [PATCH] BREAK: move to `helpers.get_package_version()` (#7) --- src/sphinx_api_relink/__init__.py | 12 ------------ src/sphinx_api_relink/helpers.py | 11 +++++++++++ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/sphinx_api_relink/__init__.py b/src/sphinx_api_relink/__init__.py index 166659b..8240987 100644 --- a/src/sphinx_api_relink/__init__.py +++ b/src/sphinx_api_relink/__init__.py @@ -1,7 +1,6 @@ from __future__ import annotations import shutil -import sys from pathlib import Path from typing import TYPE_CHECKING, Any @@ -11,22 +10,11 @@ from sphinx.domains.python import parse_reftarget from sphinx.ext.apidoc import main as sphinx_apidoc -if sys.version_info < (3, 8): - from importlib_metadata import version -else: - from importlib.metadata import version - if TYPE_CHECKING: from sphinx.application import Sphinx from sphinx.environment import BuildEnvironment -def get_version(package_name: str) -> str: - """Get the version (MAJOR.MINOR.PATCH) of a Python package.""" - v = version(package_name) - return ".".join(v.split(".")[:3]) - - def setup(app: Sphinx) -> dict[str, Any]: app.add_config_value("api_target_substitutions", default={}, rebuild="env") app.add_config_value("api_target_types", default={}, rebuild="env") diff --git a/src/sphinx_api_relink/helpers.py b/src/sphinx_api_relink/helpers.py index da7a728..f9a97c0 100644 --- a/src/sphinx_api_relink/helpers.py +++ b/src/sphinx_api_relink/helpers.py @@ -7,6 +7,11 @@ import re import sys +if sys.version_info < (3, 8): + from importlib_metadata import version +else: + from importlib.metadata import version + __VERSION_REMAPPING: dict[str, dict[str, str]] = {} @@ -32,6 +37,12 @@ def get_execution_mode() -> str: return "off" +def get_package_version(package_name: str) -> str: + """Get the version (MAJOR.MINOR.PATCH) of a Python package.""" + v = version(package_name) + return ".".join(v.split(".")[:3]) + + def pin( package_name: str, version_remapping: dict[str, dict[str, str]] | None = None ) -> str: