Skip to content

Commit

Permalink
Use proper way to determine package version
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Feb 15, 2022
1 parent 8af3318 commit f3c9d75
Showing 1 changed file with 8 additions and 31 deletions.
39 changes: 8 additions & 31 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import codecs
import os
import re


def read(*parts):
"""
Build an absolute path from *parts* and and return the contents of the
resulting file. Assume UTF-8 encoding.
"""
here = os.path.abspath(os.path.dirname(__file__))
with codecs.open(os.path.join(here, *parts), "rb", "utf-8") as f:
return f.read()


def find_version(*file_paths):
"""
Build a path from *file_paths* and search for a ``__version__``
string inside.
"""
version_file = read(*file_paths)
version_match = re.search(
r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M
)
if version_match:
return version_match.group(1)
raise RuntimeError("Unable to find version string.")
from importlib import metadata


# If extensions (or modules to document with autodoc) are in another directory,
Expand Down Expand Up @@ -88,11 +62,11 @@ def find_version(*file_paths):
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#

# The full version, including alpha/beta/rc tags.
release = metadata.version("prometheus-async")
# The short X.Y version.
release = find_version("..", "src", project.replace("-", "_"), "__init__.py")
version = release.rsplit(".", 1)[0]
# The full version, including alpha/beta/rc tags.

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -314,10 +288,13 @@ def find_version(*file_paths):
# If true, do not generate a @detailmenu in the "Top" node's menu.
# texinfo_no_detailmenu = False

# GitHub has rate limits
linkcheck_ignore = [
# Rate limits
r"https://github.com/.*/(issues|pull)/\d+",
r"https://twitter.com/.*",
# Anchors are a problem
r"https://github.com/prometheus/client_python#twisted",
r"https://github.com/prometheus/client_python#counter",
]


Expand Down

0 comments on commit f3c9d75

Please sign in to comment.