@@ -92,16 +92,45 @@ def inspect_python_install(python=sys.executable):
92
92
MAGIC_NUMBER = _imp .get_magic ()
93
93
94
94
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
+
95
121
def _inspect_python_install (executable , prefix , base_prefix ,
96
122
platlibdir , stdlib_dir ,
97
123
version_info , platform , implementation_name ,
98
124
** _ignored ):
99
125
is_venv = prefix != base_prefix
100
126
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
105
134
is_dev = True
106
135
else :
107
136
major , minor = version_info [:2 ]
@@ -162,5 +191,7 @@ def _get_raw_info():
162
191
163
192
if __name__ == '__main__' :
164
193
info = _get_raw_info ()
194
+ (info ['_base_executable' ], info ['_is_dev' ], info ['_is_venv' ],
195
+ ) = _inspect_python_install (** info )
165
196
json .dump (info , sys .stdout , indent = 4 )
166
197
print ()
0 commit comments