Skip to content

Commit

Permalink
BREAK: move to helpers.get_package_version() (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer authored Dec 4, 2023
1 parent 429cbdb commit e620ff2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
12 changes: 0 additions & 12 deletions src/sphinx_api_relink/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import shutil
import sys
from pathlib import Path
from typing import TYPE_CHECKING, Any

Expand All @@ -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")
Expand Down
11 changes: 11 additions & 0 deletions src/sphinx_api_relink/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]] = {}


Expand All @@ -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:
Expand Down

0 comments on commit e620ff2

Please sign in to comment.