Skip to content

Commit 2e4a3e8

Browse files
committed
Unified reading VERSION
1 parent 12bdf8f commit 2e4a3e8

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

docs/conf.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@
88

99
import datetime
1010
import pathlib
11+
import sys
12+
package_dir = pathlib.Path(__file__).parent.parent / 'lxmlh'
13+
sys.path.insert(0, str(package_dir.resolve()))
14+
15+
from version import __version__
1116

1217
project = 'lxmlh'
1318
copyright = f'{datetime.date.today().year}, Mina Sami'
1419
author = 'Mina Sami'
15-
16-
version_file = pathlib.Path(__file__).parent.parent / 'lxmlh' / 'VERSION'
17-
# Read the version number from VERSION file
18-
with open(version_file, 'r', encoding='UTF-8') as vf:
19-
# The full version, including alpha/beta/rc tags
20-
release_list = vf.read().strip().split('.')
21-
release = '.'.join(release_list)
20+
release = __version__
2221

2322
# -- General configuration ---------------------------------------------------
2423
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

lxmlh/__init__.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
"""lxmlh."""
2-
import importlib.metadata
3-
from typing import Tuple, Union
4-
52
from .config import TIMESTAMP_FORMAT, TYPE_DEFAULTS, TYPE_FUNC_MAP
63
from .helpers import (
74
create_attribute,
@@ -21,6 +18,7 @@
2118
validate_file,
2219
validate_zip_file,
2320
)
21+
from .version import __version__
2422

2523
__all__ = (
2624
"__version__",
@@ -42,18 +40,3 @@
4240
"validate_file",
4341
"validate_zip_file",
4442
)
45-
46-
47-
def _get_version_tuple() -> Tuple[Union[int, str]]:
48-
def as_integer(string: str) -> Union[int, str]:
49-
try:
50-
return int(string)
51-
except ValueError: # pragma: no cover
52-
return string # pragma: no cover
53-
54-
return tuple(
55-
as_integer(v) for v in importlib.metadata.version("lxmlh").strip().split(".")
56-
)
57-
58-
59-
__version__ = _get_version_tuple()

lxmlh/version.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""Version information for lxmlh package."""
2+
import pathlib
3+
4+
5+
def _get_version():
6+
"""Return the version number."""
7+
versionFile = pathlib.Path(__file__).parent / "VERSION"
8+
# Read the version number from VERSION file
9+
with open(versionFile, "r", encoding="UTF-8") as vf:
10+
# The full version, including alpha/beta/rc tags
11+
versionList = vf.read().strip().split(".")
12+
return ".".join(versionList)
13+
14+
15+
__version__ = _get_version()

0 commit comments

Comments
 (0)