Skip to content

Commit 03c6c31

Browse files
committed
DOC: Attempt to find versioneer version when building docs
1 parent cc20e28 commit 03c6c31

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

doc/tools/build_modref_templates.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# stdlib imports
66
import sys
77
import re
8+
import os
89
from os.path import join as pjoin
910

1011
# local imports
@@ -48,12 +49,25 @@ def abort(error):
4849

4950
installed_version = V(module.__version__)
5051

51-
info_file = pjoin('..', package, 'info.py')
52-
info_lines = open(info_file).readlines()
53-
source_version = '.'.join([v.split('=')[1].strip(" '\n.")
54-
for v in info_lines if re.match(
55-
'^_version_(major|minor|micro|extra)', v
56-
)])
52+
version_file = pjoin('..', package, '_version.py')
53+
source_version = None
54+
if os.path.exists(version_file):
55+
# Versioneer
56+
from runpy import run_path
57+
try:
58+
source_version = run_path(version_file)['get_versions']()['version']
59+
except (FileNotFoundError, KeyError):
60+
pass
61+
if source_version == '0+unknown':
62+
source_version = None
63+
if source_version is None:
64+
# Legacy fall-back
65+
info_file = pjoin('..', package, 'info.py')
66+
info_lines = open(info_file).readlines()
67+
source_version = '.'.join([v.split('=')[1].strip(" '\n.")
68+
for v in info_lines if re.match(
69+
'^_version_(major|minor|micro|extra)', v
70+
)])
5771
print('***', source_version)
5872

5973
if source_version != installed_version:

0 commit comments

Comments
 (0)