Skip to content

Commit

Permalink
leverage importlib.metadata in docs/conf.py (#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 ca12c29
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
1 change: 1 addition & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ sphinx:

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

formats:
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 ca12c29

Please sign in to comment.