Skip to content

Commit

Permalink
leverage importlib.metadata in docs/conf.py (aio-libs#1161)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakob-keller committed Aug 21, 2024
1 parent d80e20d commit 54bf1ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ sphinx:

python:
install:
- requirements: docs/requirements.txt
- path: .
requirements: docs/requirements.txt

formats:
- htmlzip
Expand Down
29 changes: 11 additions & 18 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,19 @@
#
# needs_sphinx = '1.0'

import pathlib
import importlib.metadata
import re

_docs_path = pathlib.Path(__file__).parent
_version_path = _docs_path / '../aiobotocore/__init__.py'


with _version_path.open() as fp:
try:
_version_info = re.search(
r"^__version__ = '"
r"(?P<major>\d+)"
r"\.(?P<minor>\d+)"
r"\.(?P<patch>\d+)"
r"(?P<tag>.*)?'$",
fp.read(),
re.M,
).groupdict()
except IndexError:
raise RuntimeError('Unable to determine version.')
try:
_version_info = re.fullmatch(
r"(?P<major>\d+)"
r"\.(?P<minor>\d+)"
r"\.(?P<patch>\d+)"
r"(?P<tag>.*)?",
importlib.metadata.version('aiobotocore'),
).groupdict()
except IndexError:
raise RuntimeError('Unable to determine version.')

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
Expand Down

0 comments on commit 54bf1ec

Please sign in to comment.