Skip to content

Commit ffe94ed

Browse files
Fix the "is dev?" logic in inspect_python_install() (#149)
(fixes #144)
1 parent 4ba066e commit ffe94ed

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

pyperformance/_pythoninfo.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,45 @@ def inspect_python_install(python=sys.executable):
9292
MAGIC_NUMBER = _imp.get_magic()
9393

9494

95+
def _is_dev_stdlib(stdlib_dir):
96+
if os.path.basename(stdlib_dir) != 'Lib':
97+
return False
98+
srcdir = os.path.dirname(stdlib_dir)
99+
for filename in [
100+
os.path.join(srcdir, 'Python', 'pylifecycle.c'),
101+
os.path.join(srcdir, 'PCbuild', 'pythoncore.vcxproj'),
102+
]:
103+
if not os.path.exists(filename):
104+
return False
105+
return True
106+
107+
108+
def _is_dev_executable(executable, stdlib_dir):
109+
builddir = os.path.dirname(executable)
110+
if os.path.exists(os.path.join(builddir, 'pybuilddir.txt')):
111+
return True
112+
if os.name == 'nt':
113+
pcbuild = os.path.dirname(os.path.dirname(executable))
114+
if os.path.basename(pcbuild) == 'PCbuild':
115+
srcdir = os.path.dirname(pcbuild)
116+
if os.path.join(srcdir, 'Lib') == stdlib_dir:
117+
return True
118+
return False
119+
120+
95121
def _inspect_python_install(executable, prefix, base_prefix,
96122
platlibdir, stdlib_dir,
97123
version_info, platform, implementation_name,
98124
**_ignored):
99125
is_venv = prefix != base_prefix
100126

101-
if os.path.basename(stdlib_dir) == 'Lib':
102-
base_executable = os.path.join(os.path.dirname(stdlib_dir), 'python')
103-
if not os.path.exists(base_executable):
104-
raise NotImplementedError(base_executable)
127+
if (_is_dev_stdlib(stdlib_dir) and
128+
_is_dev_executable(executable, stdlib_dir)):
129+
# XXX What about venv?
130+
try:
131+
base_executable = sys._base_executable
132+
except AttributeError:
133+
base_executable = executable
105134
is_dev = True
106135
else:
107136
major, minor = version_info[:2]
@@ -162,5 +191,7 @@ def _get_raw_info():
162191

163192
if __name__ == '__main__':
164193
info = _get_raw_info()
194+
(info['_base_executable'], info['_is_dev'], info['_is_venv'],
195+
) = _inspect_python_install(**info)
165196
json.dump(info, sys.stdout, indent=4)
166197
print()

0 commit comments

Comments
 (0)