Skip to content

Commit 17aa9c4

Browse files
committed
Move get_python_lib and get_python_inc back to distutils.sysconfig
and deprecated them.
1 parent abc310b commit 17aa9c4

File tree

4 files changed

+91
-112
lines changed

4 files changed

+91
-112
lines changed

Doc/distutils/apiref.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,9 @@ for other parts of the :mod:`distutils` package.
15121512
meaning for other platforms will vary. The file is a platform-specific text
15131513
file, if it exists. This function is only useful on POSIX platforms.
15141514

1515+
The following functions are deprecated together with this module and they
1516+
have no direct replacement.
1517+
15151518

15161519
.. function:: get_python_inc([plat_specific[, prefix]])
15171520

Doc/library/sysconfig.rst

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -224,29 +224,6 @@ Other functions
224224

225225
Return the path of :file:`Makefile`.
226226

227-
The following functions have been moved here from :mod:`distutils.sysconfig`
228-
when this module has been deprecated.
229-
230-
.. function:: get_python_inc([plat_specific[, prefix]])
231-
232-
Return the directory for either the general or platform-dependent C include
233-
files. If *plat_specific* is true, the platform-dependent include directory is
234-
returned; if false or omitted, the platform-independent directory is returned.
235-
If *prefix* is given, it is used as either the prefix instead of
236-
:const:`PREFIX`, or as the exec-prefix instead of :const:`EXEC_PREFIX` if
237-
*plat_specific* is true.
238-
239-
240-
.. function:: get_python_lib([plat_specific[, standard_lib[, prefix]]])
241-
242-
Return the directory for either the general or platform-dependent library
243-
installation. If *plat_specific* is true, the platform-dependent include
244-
directory is returned; if false or omitted, the platform-independent directory
245-
is returned. If *prefix* is given, it is used as either the prefix instead of
246-
:const:`PREFIX`, or as the exec-prefix instead of :const:`EXEC_PREFIX` if
247-
*plat_specific* is true. If *standard_lib* is true, the directory for the
248-
standard library is returned rather than the directory for the installation of
249-
third-party extensions.
250227

251228
Using :mod:`sysconfig` as a script
252229
----------------------------------

Lib/distutils/sysconfig.py

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@
4444
get_config_var,
4545
get_config_vars,
4646
get_makefile_filename,
47-
get_python_inc,
4847
get_python_version,
49-
get_python_lib,
5048
)
5149

5250
# This is better than
@@ -78,7 +76,9 @@ def parse_makefile(fn, g=None):
7876
_init_nt = partial(_init_non_posix, _config_vars)
7977

8078

81-
# customize_compiler is deprecated and won't be moved to another module
79+
# Following functions are deprecated together with this module and they
80+
# have no direct replacement
81+
8282
def customize_compiler(compiler):
8383
"""Do any platform-specific customization of a CCompiler instance.
8484
@@ -148,3 +148,88 @@ def customize_compiler(compiler):
148148
archiver=archiver)
149149

150150
compiler.shared_lib_extension = shlib_suffix
151+
152+
153+
def get_python_inc(plat_specific=0, prefix=None):
154+
"""Return the directory containing installed Python header files.
155+
156+
If 'plat_specific' is false (the default), this is the path to the
157+
non-platform-specific header files, i.e. Python.h and so on;
158+
otherwise, this is the path to platform-specific header files
159+
(namely pyconfig.h).
160+
161+
If 'prefix' is supplied, use it instead of sys.base_prefix or
162+
sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
163+
"""
164+
if prefix is None:
165+
prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
166+
if os.name == "posix":
167+
if python_build:
168+
# Assume the executable is in the build directory. The
169+
# pyconfig.h file should be in the same directory. Since
170+
# the build directory may not be the source directory, we
171+
# must use "srcdir" from the makefile to find the "Include"
172+
# directory.
173+
if plat_specific:
174+
return _sys_home or project_base
175+
else:
176+
incdir = os.path.join(get_config_var('srcdir'), 'Include')
177+
return os.path.normpath(incdir)
178+
python_dir = 'python' + get_python_version() + build_flags
179+
return os.path.join(prefix, "include", python_dir)
180+
elif os.name == "nt":
181+
if python_build:
182+
# Include both the include and PC dir to ensure we can find
183+
# pyconfig.h
184+
return (os.path.join(prefix, "include") + os.path.pathsep +
185+
os.path.join(prefix, "PC"))
186+
return os.path.join(prefix, "include")
187+
else:
188+
raise DistutilsPlatformError(
189+
"I don't know where Python installs its C header files "
190+
"on platform '%s'" % os.name)
191+
192+
193+
def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
194+
"""Return the directory containing the Python library (standard or
195+
site additions).
196+
197+
If 'plat_specific' is true, return the directory containing
198+
platform-specific modules, i.e. any module from a non-pure-Python
199+
module distribution; otherwise, return the platform-shared library
200+
directory. If 'standard_lib' is true, return the directory
201+
containing standard Python library modules; otherwise, return the
202+
directory for site-specific modules.
203+
204+
If 'prefix' is supplied, use it instead of sys.base_prefix or
205+
sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
206+
"""
207+
if prefix is None:
208+
if standard_lib:
209+
prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
210+
else:
211+
prefix = plat_specific and EXEC_PREFIX or PREFIX
212+
213+
if os.name == "posix":
214+
if plat_specific or standard_lib:
215+
# Platform-specific modules (any module from a non-pure-Python
216+
# module distribution) or standard Python library modules.
217+
libdir = sys.platlibdir
218+
else:
219+
# Pure Python
220+
libdir = "lib"
221+
libpython = os.path.join(prefix, libdir,
222+
"python" + get_python_version())
223+
if standard_lib:
224+
return libpython
225+
else:
226+
return os.path.join(libpython, "site-packages")
227+
elif os.name == "nt":
228+
if standard_lib:
229+
return os.path.join(prefix, "Lib")
230+
else:
231+
return os.path.join(prefix, "Lib", "site-packages")
232+
else:
233+
raise DistutilsPlatformError(
234+
"I don't know where Python installs its library "
235+
"on platform '%s'" % os.name)

Lib/sysconfig.py

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os
44
import sys
55
from os.path import pardir, realpath
6-
from distutils.errors import DistutilsPlatformError
76

87
__all__ = [
98
'get_config_h_filename',
@@ -717,91 +716,6 @@ def get_python_version():
717716
return _PY_VERSION_SHORT
718717

719718

720-
def get_python_inc(plat_specific=0, prefix=None):
721-
"""Return the directory containing installed Python header files.
722-
723-
If 'plat_specific' is false (the default), this is the path to the
724-
non-platform-specific header files, i.e. Python.h and so on;
725-
otherwise, this is the path to platform-specific header files
726-
(namely pyconfig.h).
727-
728-
If 'prefix' is supplied, use it instead of sys.base_prefix or
729-
sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
730-
"""
731-
if prefix is None:
732-
prefix = plat_specific and _BASE_EXEC_PREFIX or _BASE_PREFIX
733-
if os.name == "posix":
734-
if _PYTHON_BUILD:
735-
# Assume the executable is in the build directory. The
736-
# pyconfig.h file should be in the same directory. Since
737-
# the build directory may not be the source directory, we
738-
# must use "srcdir" from the makefile to find the "Include"
739-
# directory.
740-
if plat_specific:
741-
return _sys_home or _PROJECT_BASE
742-
else:
743-
incdir = os.path.join(get_config_var('srcdir'), 'Include')
744-
return os.path.normpath(incdir)
745-
python_dir = 'python' + get_python_version() + build_flags
746-
return os.path.join(prefix, "include", python_dir)
747-
elif os.name == "nt":
748-
if _PYTHON_BUILD:
749-
# Include both the include and PC dir to ensure we can find
750-
# pyconfig.h
751-
return (os.path.join(prefix, "include") + os.path.pathsep +
752-
os.path.join(prefix, "PC"))
753-
return os.path.join(prefix, "include")
754-
else:
755-
raise DistutilsPlatformError(
756-
"I don't know where Python installs its C header files "
757-
"on platform '%s'" % os.name)
758-
759-
760-
def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
761-
"""Return the directory containing the Python library (standard or
762-
site additions).
763-
764-
If 'plat_specific' is true, return the directory containing
765-
platform-specific modules, i.e. any module from a non-pure-Python
766-
module distribution; otherwise, return the platform-shared library
767-
directory. If 'standard_lib' is true, return the directory
768-
containing standard Python library modules; otherwise, return the
769-
directory for site-specific modules.
770-
771-
If 'prefix' is supplied, use it instead of sys.base_prefix or
772-
sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
773-
"""
774-
if prefix is None:
775-
if standard_lib:
776-
prefix = plat_specific and _BASE_EXEC_PREFIX or _BASE_PREFIX
777-
else:
778-
prefix = plat_specific and _EXEC_PREFIX or _PREFIX
779-
780-
if os.name == "posix":
781-
if plat_specific or standard_lib:
782-
# Platform-specific modules (any module from a non-pure-Python
783-
# module distribution) or standard Python library modules.
784-
libdir = sys.platlibdir
785-
else:
786-
# Pure Python
787-
libdir = "lib"
788-
libpython = os.path.join(prefix, libdir,
789-
"python" + get_python_version())
790-
if standard_lib:
791-
return libpython
792-
else:
793-
return os.path.join(libpython, "site-packages")
794-
elif os.name == "nt":
795-
if standard_lib:
796-
return os.path.join(prefix, "Lib")
797-
else:
798-
return os.path.join(prefix, "Lib", "site-packages")
799-
else:
800-
raise DistutilsPlatformError(
801-
"I don't know where Python installs its library "
802-
"on platform '%s'" % os.name)
803-
804-
805719
def expand_makefile_vars(s, vars):
806720
"""Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
807721
'string' according to 'vars' (a dictionary mapping variable names to

0 commit comments

Comments
 (0)