|
1 | 1 | #!/usr/bin/env python3 |
2 | | -# -*- coding: utf-8 -*- |
3 | 2 | # |
4 | 3 | # python-semver documentation build configuration file |
5 | 4 | # |
|
16 | 15 | # add these directories to sys.path here. If the directory is relative to the |
17 | 16 | # documentation root, use os.path.abspath to make it absolute, like shown here. |
18 | 17 | # |
19 | | -import codecs |
20 | | -from datetime import date |
| 18 | + |
21 | 19 | import os |
22 | 20 | import re |
23 | | -import sys |
| 21 | +from datetime import date |
| 22 | +from pathlib import Path |
24 | 23 |
|
25 | | -SRC_DIR = os.path.abspath("../src/") |
26 | | -sys.path.insert(0, SRC_DIR) |
27 | | -# from semver import __version__ # noqa: E402 |
| 24 | +SRC_DIR = Path(__file__).absolute().parent.parent / "src" |
28 | 25 | YEAR = date.today().year |
29 | 26 |
|
30 | 27 |
|
31 | | -def read(*parts): |
32 | | - """ |
33 | | - Build an absolute path from *parts* and and return the contents of the |
34 | | - resulting file. Assume UTF-8 encoding. |
35 | | - """ |
36 | | - here = os.path.abspath(os.path.dirname(__file__)) |
37 | | - with codecs.open(os.path.join(here, *parts), "rb", "utf-8") as f: |
38 | | - return f.read() |
39 | | - |
40 | | - |
41 | | -def find_version(*file_paths): |
| 28 | +def find_version(path: Path) -> str: |
42 | 29 | """ |
43 | 30 | Build a path from *file_paths* and search for a ``__version__`` |
44 | 31 | string inside. |
45 | 32 | """ |
46 | | - version_file = read(*file_paths) |
47 | | - version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M) |
| 33 | + content = Path(path).read_text(encoding="utf-8") |
| 34 | + |
| 35 | + version_match = re.search( |
| 36 | + r"^__version__ = ['\"]([^'\"]*)['\"]", |
| 37 | + content, |
| 38 | + re.MULTILINE |
| 39 | + ) |
48 | 40 | if version_match: |
49 | 41 | return version_match.group(1) |
| 42 | + |
50 | 43 | raise RuntimeError("Unable to find version string.") |
51 | 44 |
|
52 | 45 |
|
@@ -86,14 +79,14 @@ def find_version(*file_paths): |
86 | 79 | # General information about the project. |
87 | 80 | project = "python-semver" |
88 | 81 | copyright = f"{YEAR}, Kostiantyn Rybnikov and all" |
89 | | -author = "Kostiantyn Rybnikov and all" |
| 82 | +author = "Kostiantyn Rybnikov, Tom Schraitle, Sebastien Celles, and others" |
90 | 83 |
|
91 | 84 | # The version info for the project you're documenting, acts as replacement for |
92 | 85 | # |version| and |release|, also used in various other places throughout the |
93 | 86 | # built documents. |
94 | 87 | # |
95 | 88 | # The short X.Y version. |
96 | | -release = find_version("../src/semver/__about__.py") |
| 89 | +release = find_version(SRC_DIR / "semver/__about__.py") |
97 | 90 | # The full version, including alpha/beta/rc tags. |
98 | 91 | version = release # .rsplit(u".", 1)[0] |
99 | 92 |
|
@@ -174,7 +167,7 @@ def find_version(*file_paths): |
174 | 167 | "github_button": True, |
175 | 168 | #: |
176 | 169 | "github_type": "star", |
177 | | - #: whether to apply a ‘Fork me on Github’ banner |
| 170 | + #: whether to apply a "Fork me on Github" banner |
178 | 171 | #: in the top right corner of the page: |
179 | 172 | # "github_banner": True, |
180 | 173 | # |
|
0 commit comments