|
2 | 2 | import sys |
3 | 3 | import re |
4 | 4 | import json |
5 | | -import subprocess |
6 | 5 | import urllib.request |
7 | 6 |
|
8 | 7 | from sphinx.errors import SphinxError |
|
21 | 20 | # Explicitly put the extensions directory to Python path |
22 | 21 | sys.path.append(os.path.abspath('_extensions')) |
23 | 22 |
|
24 | | -# Detect whether the build happens on ReadTheDocs |
25 | | -IS_READTHEDOCS = os.environ.get('READTHEDOCS') == 'True' |
26 | | - |
27 | | -# Specify paths |
28 | | -docs_dir = os.path.dirname(__file__) |
29 | | -project_dir = os.path.join(docs_dir, '..') |
30 | | -node_modules_bin_dir = os.path.join(project_dir, 'node_modules', '.bin') |
31 | | - |
32 | | -# Install all npm dependencies if on ReadTheDocs. This requires the latest |
33 | | -# ReadTheDocs build image, which supports Node.js out of the box. This is |
34 | | -# specified in the readthedocs.yml in the root of the project. |
35 | | -if IS_READTHEDOCS: |
36 | | - subprocess.check_call('npm install', cwd=project_dir, shell=True) |
37 | | - |
38 | | -# Load package.json data |
39 | | -with open(os.path.join(project_dir, 'package.json')) as f: |
40 | | - package_json = json.load(f) |
41 | | - |
42 | 23 |
|
43 | 24 | # -- General configuration ------------------------------------------------ |
44 | 25 |
|
|
66 | 47 | copyright = 'Apiary Czech Republic, s.r.o.' |
67 | 48 | author = 'Apiary' |
68 | 49 |
|
69 | | -# The version info for the project you're documenting, acts as replacement for |
70 | | -# |version| and |release|, also used in various other places throughout the |
71 | | -# built documents. |
72 | | -def get_release(): |
73 | | - try: |
74 | | - # Is internet available? this is to be able to generate docs |
75 | | - # e.g. in train without internet connection |
76 | | - urllib.request.urlopen('https://www.npmjs.com/package/dredd', timeout=3) |
77 | | - except urllib.request.URLError as e: |
78 | | - if IS_READTHEDOCS: |
79 | | - # ReadTheDocs have problem to connect to npm, fail fast |
80 | | - raise SphinxError('Could not determine Dredd version: {}'.format(e)) |
81 | | - else: |
82 | | - # Offline local development, use dummy release number |
83 | | - return package_json['version'] |
84 | | - else: |
85 | | - # Online, ask Semantic Release what would be the next version |
86 | | - sem_rel_bin = os.path.join(node_modules_bin_dir, 'semantic-release') |
87 | | - sem_rel_output = subprocess.getoutput('{} pre'.format(sem_rel_bin)) |
88 | | - match = re.search(r'determined version (\d+\.\d+\.\d+)', sem_rel_output, re.I) |
89 | | - if match: |
90 | | - # Semantic Release would use this version number |
91 | | - return match.group(1) |
92 | | - |
93 | | - # Semantic Release wasn't able to determine a new version number, |
94 | | - # either because of some error or because there are no changes which |
95 | | - # would bump the version number. Stick to the latest released version. |
96 | | - return subprocess.getoutput('npm view dredd version').strip() |
97 | | - |
98 | | -# The full version, including alpha/beta/rc tags. |
99 | | -release = get_release() |
100 | | -if not re.match(r'\d+\.\d+\.\d+', release): |
101 | | - raise SphinxError("'{}' does not look like version number".format(release)) |
102 | | - |
103 | | -# The short X.Y version. |
104 | | -version = release |
| 50 | +# The project version (2.6) and release (2.6.0rc1) numbers. Figuring this |
| 51 | +# out for Dredd is tricky (because of Semantic Release), so it's hardcoded. |
| 52 | +version = 'latest' |
| 53 | +release = 'latest' |
105 | 54 |
|
106 | 55 | # List of patterns, relative to source directory, that match files and |
107 | 56 | # directories to ignore when looking for source files. |
|
0 commit comments