Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
efc2ae7c
Commit
efc2ae7c
authored
Jan 23, 2010
by
Tarek Ziadé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
taking sysconfig out of distutils
parent
aa70d631
Changes
29
Hide whitespace changes
Inline
Side-by-side
Showing
29 changed files
with
307 additions
and
985 deletions
+307
-985
ccompiler.py
ccompiler.py
+52
-0
command/bdist.py
command/bdist.py
+1
-1
command/bdist_dumb.py
command/bdist_dumb.py
+2
-2
command/bdist_wininst.py
command/bdist_wininst.py
+2
-2
command/build.py
command/build.py
+2
-1
command/build_clib.py
command/build_clib.py
+1
-1
command/build_ext.py
command/build_ext.py
+18
-19
command/build_scripts.py
command/build_scripts.py
+5
-5
command/config.py
command/config.py
+1
-1
command/install.py
command/install.py
+40
-123
core.py
core.py
+1
-1
cygwinccompiler.py
cygwinccompiler.py
+2
-2
extension.py
extension.py
+9
-3
msvc9compiler.py
msvc9compiler.py
+5
-5
sysconfig.py
sysconfig.py
+66
-542
tests/support.py
tests/support.py
+8
-0
tests/test_build.py
tests/test_build.py
+1
-1
tests/test_build_clib.py
tests/test_build_clib.py
+1
-2
tests/test_build_ext.py
tests/test_build_ext.py
+8
-9
tests/test_build_scripts.py
tests/test_build_scripts.py
+3
-3
tests/test_ccompiler.py
tests/test_ccompiler.py
+24
-2
tests/test_cygwinccompiler.py
tests/test_cygwinccompiler.py
+1
-2
tests/test_extension.py
tests/test_extension.py
+2
-0
tests/test_install.py
tests/test_install.py
+34
-19
tests/test_sysconfig.py
tests/test_sysconfig.py
+3
-30
tests/test_unixccompiler.py
tests/test_unixccompiler.py
+1
-1
tests/test_util.py
tests/test_util.py
+6
-36
unixccompiler.py
unixccompiler.py
+6
-4
util.py
util.py
+2
-168
No files found.
ccompiler.py
View file @
efc2ae7c
...
...
@@ -18,6 +18,58 @@ from distutils.dep_util import newer_group
from
distutils.util
import
split_quoted
,
execute
from
distutils
import
log
_sysconfig
=
__import__
(
'sysconfig'
)
def
customize_compiler
(
compiler
):
"""Do any platform-specific customization of a CCompiler instance.
Mainly needed on Unix, so we can plug in the information that
varies across Unices and is stored in Python's Makefile.
"""
if
compiler
.
compiler_type
==
"unix"
:
(
cc
,
cxx
,
opt
,
cflags
,
ccshared
,
ldshared
,
so_ext
,
ar
,
ar_flags
)
=
\
_sysconfig
.
get_config_vars
(
'CC'
,
'CXX'
,
'OPT'
,
'CFLAGS'
,
'CCSHARED'
,
'LDSHARED'
,
'SO'
,
'AR'
,
'ARFLAGS'
)
if
'CC'
in
os
.
environ
:
cc
=
os
.
environ
[
'CC'
]
if
'CXX'
in
os
.
environ
:
cxx
=
os
.
environ
[
'CXX'
]
if
'LDSHARED'
in
os
.
environ
:
ldshared
=
os
.
environ
[
'LDSHARED'
]
if
'CPP'
in
os
.
environ
:
cpp
=
os
.
environ
[
'CPP'
]
else
:
cpp
=
cc
+
" -E"
# not always
if
'LDFLAGS'
in
os
.
environ
:
ldshared
=
ldshared
+
' '
+
os
.
environ
[
'LDFLAGS'
]
if
'CFLAGS'
in
os
.
environ
:
cflags
=
opt
+
' '
+
os
.
environ
[
'CFLAGS'
]
ldshared
=
ldshared
+
' '
+
os
.
environ
[
'CFLAGS'
]
if
'CPPFLAGS'
in
os
.
environ
:
cpp
=
cpp
+
' '
+
os
.
environ
[
'CPPFLAGS'
]
cflags
=
cflags
+
' '
+
os
.
environ
[
'CPPFLAGS'
]
ldshared
=
ldshared
+
' '
+
os
.
environ
[
'CPPFLAGS'
]
if
'AR'
in
os
.
environ
:
ar
=
os
.
environ
[
'AR'
]
if
'ARFLAGS'
in
os
.
environ
:
archiver
=
ar
+
' '
+
os
.
environ
[
'ARFLAGS'
]
else
:
archiver
=
ar
+
' '
+
ar_flags
cc_cmd
=
cc
+
' '
+
cflags
compiler
.
set_executables
(
preprocessor
=
cpp
,
compiler
=
cc_cmd
,
compiler_so
=
cc_cmd
+
' '
+
ccshared
,
compiler_cxx
=
cxx
,
linker_so
=
ldshared
,
linker_exe
=
cc
,
archiver
=
archiver
)
compiler
.
shared_lib_extension
=
so_ext
class
CCompiler
:
"""Abstract base class to define the interface that must be implemented
by real compiler classes. Also has some utility methods used by
...
...
command/bdist.py
View file @
efc2ae7c
...
...
@@ -6,10 +6,10 @@ distribution)."""
__revision__
=
"$Id$"
import
os
from
sysconfig
import
get_platform
from
distutils.core
import
Command
from
distutils.errors
import
DistutilsPlatformError
,
DistutilsOptionError
from
distutils.util
import
get_platform
def
show_formats
():
...
...
command/bdist_dumb.py
View file @
efc2ae7c
...
...
@@ -8,11 +8,11 @@ __revision__ = "$Id$"
import
os
from
sysconfig
import
get_python_version
,
get_platform
from
distutils.core
import
Command
from
distutils.util
import
get_platform
from
distutils.dir_util
import
remove_tree
,
ensure_relative
from
distutils.errors
import
DistutilsPlatformError
from
distutils.sysconfig
import
get_python_version
from
distutils
import
log
class
bdist_dumb
(
Command
):
...
...
command/bdist_wininst.py
View file @
efc2ae7c
...
...
@@ -9,11 +9,11 @@ import sys
import
os
import
string
from
sysconfig
import
get_python_version
,
get_platform
from
distutils.core
import
Command
from
distutils.util
import
get_platform
from
distutils.dir_util
import
remove_tree
from
distutils.errors
import
DistutilsOptionError
,
DistutilsPlatformError
from
distutils.sysconfig
import
get_python_version
from
distutils
import
log
class
bdist_wininst
(
Command
):
...
...
command/build.py
View file @
efc2ae7c
...
...
@@ -5,9 +5,10 @@ Implements the Distutils 'build' command."""
__revision__
=
"$Id$"
import
sys
,
os
from
sysconfig
import
get_platform
from
distutils.core
import
Command
from
distutils.errors
import
DistutilsOptionError
from
distutils.util
import
get_platform
def
show_compilers
():
from
distutils.ccompiler
import
show_compilers
...
...
command/build_clib.py
View file @
efc2ae7c
...
...
@@ -19,7 +19,7 @@ __revision__ = "$Id$"
import
os
from
distutils.core
import
Command
from
distutils.errors
import
DistutilsSetupError
from
distutils.
sysconfig
import
customize_compiler
from
distutils.
ccompiler
import
customize_compiler
from
distutils
import
log
def
show_compilers
():
...
...
command/build_ext.py
View file @
efc2ae7c
...
...
@@ -9,13 +9,14 @@ __revision__ = "$Id$"
import
sys
,
os
,
re
from
warnings
import
warn
from
sysconfig
import
get_platform
from
distutils.core
import
Command
from
distutils.errors
import
(
CCompilerError
,
DistutilsError
,
CompileError
,
DistutilsSetupError
,
DistutilsPlatformError
)
from
distutils.sysconfig
import
customize_compiler
,
get_python_version
from
distutils.errors
import
*
from
distutils.ccompiler
import
customize_compiler
from
distutils.dep_util
import
newer_group
from
distutils.extension
import
Extension
from
distutils.util
import
get_platform
from
distutils
import
log
# this keeps compatibility from 2.3 to 2.5
...
...
@@ -173,8 +174,7 @@ class build_ext(Command):
self
.
user
=
None
def
finalize_options
(
self
):
from
distutils
import
sysconfig
_sysconfig
=
__import__
(
'sysconfig'
)
self
.
set_undefined_options
(
'build'
,
(
'build_lib'
,
'build_lib'
),
(
'build_temp'
,
'build_temp'
),
...
...
@@ -191,8 +191,8 @@ class build_ext(Command):
# Make sure Python's include directories (for Python.h, pyconfig.h,
# etc.) are in the include search path.
py_include
=
sysconfig
.
get_python_inc
(
)
plat_py_include
=
sysconfig
.
get_python_inc
(
plat_specific
=
1
)
py_include
=
_sysconfig
.
get_path
(
'include'
)
plat_py_include
=
_sysconfig
.
get_path
(
'platinclude'
)
if
self
.
include_dirs
is
None
:
self
.
include_dirs
=
self
.
distribution
.
include_dirs
or
[]
if
isinstance
(
self
.
include_dirs
,
str
):
...
...
@@ -270,7 +270,7 @@ class build_ext(Command):
if
sys
.
executable
.
startswith
(
os
.
path
.
join
(
sys
.
exec_prefix
,
"bin"
)):
# building third party extensions
self
.
library_dirs
.
append
(
os
.
path
.
join
(
sys
.
prefix
,
"lib"
,
"python"
+
get_python_version
(),
"python"
+
_sysconfig
.
get_python_version
(),
"config"
))
else
:
# building python standard extensions
...
...
@@ -278,13 +278,13 @@ class build_ext(Command):
# for extensions under Linux or Solaris with a shared Python library,
# Python's library directory must be appended to library_dirs
sysconfig
.
get_config_var
(
'Py_ENABLE_SHARED'
)
_
sysconfig
.
get_config_var
(
'Py_ENABLE_SHARED'
)
if
((
sys
.
platform
.
startswith
(
'linux'
)
or
sys
.
platform
.
startswith
(
'gnu'
)
or
sys
.
platform
.
startswith
(
'sunos'
))
and
sysconfig
.
get_config_var
(
'Py_ENABLE_SHARED'
)):
and
_
sysconfig
.
get_config_var
(
'Py_ENABLE_SHARED'
)):
if
sys
.
executable
.
startswith
(
os
.
path
.
join
(
sys
.
exec_prefix
,
"bin"
)):
# building third party extensions
self
.
library_dirs
.
append
(
sysconfig
.
get_config_var
(
'LIBDIR'
))
self
.
library_dirs
.
append
(
_
sysconfig
.
get_config_var
(
'LIBDIR'
))
else
:
# building python standard extensions
self
.
library_dirs
.
append
(
'.'
)
...
...
@@ -719,13 +719,13 @@ class build_ext(Command):
of the file from which it will be loaded (eg. "foo/bar.so", or
"foo\bar.pyd").
"""
from
distutils.sysconfig
import
get_config_var
_sysconfig
=
__import__
(
'sysconfig'
)
ext_path
=
ext_name
.
split
(
'.'
)
# OS/2 has an 8 character module (extension) limit :-(
if
os
.
name
==
"os2"
:
ext_path
[
len
(
ext_path
)
-
1
]
=
ext_path
[
len
(
ext_path
)
-
1
][:
8
]
# extensions in debug_mode are named 'module_d.pyd' under windows
so_ext
=
get_config_var
(
'SO'
)
so_ext
=
_sysconfig
.
get_config_var
(
'SO'
)
if
os
.
name
==
'nt'
and
self
.
debug
:
return
os
.
path
.
join
(
*
ext_path
)
+
'_d'
+
so_ext
return
os
.
path
.
join
(
*
ext_path
)
+
so_ext
...
...
@@ -785,14 +785,13 @@ class build_ext(Command):
# extensions, it is a reference to the original list
return
ext
.
libraries
+
[
pythonlib
]
elif
sys
.
platform
[:
6
]
==
"atheos"
:
from
distutils
import
sysconfig
_sysconfig
=
__import__
(
'sysconfig'
)
template
=
"python%d.%d"
pythonlib
=
(
template
%
(
sys
.
hexversion
>>
24
,
(
sys
.
hexversion
>>
16
)
&
0xff
))
# Get SHLIBS from Makefile
extra
=
[]
for
lib
in
sysconfig
.
get_config_var
(
'SHLIBS'
).
split
():
for
lib
in
_
sysconfig
.
get_config_var
(
'SHLIBS'
).
split
():
if
lib
.
startswith
(
'-l'
):
extra
.
append
(
lib
[
2
:])
else
:
...
...
@@ -806,8 +805,8 @@ class build_ext(Command):
return
ext
.
libraries
else
:
from
distutils
import
sysconfig
if
sysconfig
.
get_config_var
(
'Py_ENABLE_SHARED'
):
_sysconfig
=
__import__
(
'sysconfig'
)
if
_
sysconfig
.
get_config_var
(
'Py_ENABLE_SHARED'
):
template
=
"python%d.%d"
pythonlib
=
(
template
%
(
sys
.
hexversion
>>
24
,
(
sys
.
hexversion
>>
16
)
&
0xff
))
...
...
command/build_scripts.py
View file @
efc2ae7c
...
...
@@ -6,7 +6,6 @@ __revision__ = "$Id$"
import
os
,
re
from
stat
import
ST_MODE
from
distutils
import
sysconfig
from
distutils.core
import
Command
from
distutils.dep_util
import
newer
from
distutils.util
import
convert_path
...
...
@@ -57,6 +56,7 @@ class build_scripts (Command):
ie. starts with "
\
#!
"
and contains "python"), then adjust the first
line to refer to the current Python interpreter as we copy.
"""
_sysconfig
=
__import__
(
'sysconfig'
)
self
.
mkpath
(
self
.
build_dir
)
outfiles
=
[]
for
script
in
self
.
scripts
:
...
...
@@ -94,16 +94,16 @@ class build_scripts (Command):
self
.
build_dir
)
if
not
self
.
dry_run
:
outf
=
open
(
outfile
,
"w"
)
if
not
sysconfig
.
python_build
:
if
not
_sysconfig
.
is_python_build
()
:
outf
.
write
(
"#!%s%s
\
n
"
%
(
self
.
executable
,
post_interp
))
else
:
outf
.
write
(
"#!%s%s
\
n
"
%
(
os
.
path
.
join
(
sysconfig
.
get_config_var
(
"BINDIR"
),
"python%s%s"
%
(
sysconfig
.
get_config_var
(
"VERSION"
),
sysconfig
.
get_config_var
(
"EXE"
))),
_
sysconfig
.
get_config_var
(
"BINDIR"
),
"python%s%s"
%
(
_
sysconfig
.
get_config_var
(
"VERSION"
),
_
sysconfig
.
get_config_var
(
"EXE"
))),
post_interp
))
outf
.
writelines
(
f
.
readlines
())
outf
.
close
()
...
...
command/config.py
View file @
efc2ae7c
...
...
@@ -16,7 +16,7 @@ import re
from
distutils.core
import
Command
from
distutils.errors
import
DistutilsExecError
from
distutils.
sysconfig
import
customize_compiler
from
distutils.
ccompiler
import
customize_compiler
from
distutils
import
log
LANG_EXT
=
{
'c'
:
'.c'
,
'c++'
:
'.cxx'
}
...
...
command/install.py
View file @
efc2ae7c
...
...
@@ -7,115 +7,25 @@ __revision__ = "$Id$"
import
sys
import
os
from
sysconfig
import
(
get_config_vars
,
get_platform
,
get_paths
,
get_path
,
get_config_var
)
from
distutils
import
log
from
distutils.core
import
Command
from
distutils.debug
import
DEBUG
from
distutils.sysconfig
import
get_config_vars
from
distutils.errors
import
DistutilsPlatformError
from
distutils.file_util
import
write_file
from
distutils.util
import
convert_path
,
subst_vars
,
change_root
from
distutils.util
import
get_platform
from
distutils.util
import
convert_path
,
change_root
from
distutils.errors
import
DistutilsOptionError
# this keeps compatibility from 2.3 to 2.5
if
sys
.
version
<
"2.6"
:
USER_BASE
=
None
USER_SITE
=
None
HAS_USER_SITE
=
False
else
:
from
site
import
USER_BASE
from
site
import
USER_SITE
HAS_USER_SITE
=
True
if
sys
.
version
<
"2.2"
:
WINDOWS_SCHEME
=
{
'purelib'
:
'$base'
,
'platlib'
:
'$base'
,
'headers'
:
'$base/Include/$dist_name'
,
'scripts'
:
'$base/Scripts'
,
'data'
:
'$base'
,
}
else
:
WINDOWS_SCHEME
=
{
'purelib'
:
'$base/Lib/site-packages'
,
'platlib'
:
'$base/Lib/site-packages'
,
'headers'
:
'$base/Include/$dist_name'
,
'scripts'
:
'$base/Scripts'
,
'data'
:
'$base'
,
}
INSTALL_SCHEMES
=
{
'unix_prefix'
:
{
'purelib'
:
'$base/lib/python$py_version_short/site-packages'
,
'platlib'
:
'$platbase/lib/python$py_version_short/site-packages'
,
'headers'
:
'$base/include/python$py_version_short/$dist_name'
,
'scripts'
:
'$base/bin'
,
'data'
:
'$base'
,
},
'unix_home'
:
{
'purelib'
:
'$base/lib/python'
,
'platlib'
:
'$base/lib/python'
,
'headers'
:
'$base/include/python/$dist_name'
,
'scripts'
:
'$base/bin'
,
'data'
:
'$base'
,
},
'nt'
:
WINDOWS_SCHEME
,
'mac'
:
{
'purelib'
:
'$base/Lib/site-packages'
,
'platlib'
:
'$base/Lib/site-packages'
,
'headers'
:
'$base/Include/$dist_name'
,
'scripts'
:
'$base/Scripts'
,
'data'
:
'$base'
,
},
'os2'
:
{
'purelib'
:
'$base/Lib/site-packages'
,
'platlib'
:
'$base/Lib/site-packages'
,
'headers'
:
'$base/Include/$dist_name'
,
'scripts'
:
'$base/Scripts'
,
'data'
:
'$base'
,
},
}
# user site schemes
if
HAS_USER_SITE
:
INSTALL_SCHEMES
[
'nt_user'
]
=
{
'purelib'
:
'$usersite'
,
'platlib'
:
'$usersite'
,
'headers'
:
'$userbase/Python$py_version_nodot/Include/$dist_name'
,
'scripts'
:
'$userbase/Scripts'
,
'data'
:
'$userbase'
,
}
INSTALL_SCHEMES
[
'unix_user'
]
=
{
'purelib'
:
'$usersite'
,
'platlib'
:
'$usersite'
,
'headers'
:
'$userbase/include/python$py_version_short/$dist_name'
,
'scripts'
:
'$userbase/bin'
,
'data'
:
'$userbase'
,
}
INSTALL_SCHEMES
[
'mac_user'
]
=
{
'purelib'
:
'$usersite'
,
'platlib'
:
'$usersite'
,
'headers'
:
'$userbase/$py_version_short/include/$dist_name'
,
'scripts'
:
'$userbase/bin'
,
'data'
:
'$userbase'
,
}
INSTALL_SCHEMES
[
'os2_home'
]
=
{
'purelib'
:
'$usersite'
,
'platlib'
:
'$usersite'
,
'headers'
:
'$userbase/include/python$py_version_short/$dist_name'
,
'scripts'
:
'$userbase/bin'
,
'data'
:
'$userbase'
,
}
# The keys to an installation scheme; if any new types of files are to be
# installed, be sure to add an entry to every installation scheme above,
# and to SCHEME_KEYS here.
SCHEME_KEYS
=
(
'purelib'
,
'platlib'
,
'headers'
,
'scripts'
,
'data'
)
def
_subst_vars
(
s
,
local_vars
):
try
:
return
s
.
format
(
**
local_vars
)
except
KeyError
:
try
:
return
s
.
format
(
**
os
.
environ
)
except
KeyError
,
var
:
raise
AttributeError
(
'{%s}'
%
var
)
class
install
(
Command
):
...
...
@@ -182,11 +92,10 @@ class install(Command):
boolean_options
=
[
'compile'
,
'force'
,
'skip-build'
]
if
HAS_USER_SITE
:
user_options
.
append
((
'user'
,
None
,
"install in user site-package '%s'"
%
USER_SITE
))
boolean_options
.
append
(
'user'
)
user_options
.
append
((
'user'
,
None
,
"install in user site-package '%s'"
%
\
get_path
(
'purelib'
,
'%s_user'
%
os
.
name
)))
boolean_options
.
append
(
'user'
)
negative_opt
=
{
'no-compile'
:
'compile'
}
...
...
@@ -216,8 +125,8 @@ class install(Command):
self
.
install_lib
=
None
# set to either purelib or platlib
self
.
install_scripts
=
None
self
.
install_data
=
None
self
.
install_userbase
=
USER_BASE
self
.
install_usersite
=
USER_SITE
self
.
install_userbase
=
get_config_var
(
'userbase'
)
self
.
install_usersite
=
get_path
(
'purelib'
,
'%s_user'
%
os
.
name
)
self
.
compile
=
None
self
.
optimize
=
None
...
...
@@ -327,7 +236,9 @@ class install(Command):
# about needing recursive variable expansion (shudder).
py_version
=
sys
.
version
.
split
()[
0
]
(
prefix
,
exec_prefix
)
=
get_config_vars
(
'prefix'
,
'exec_prefix'
)
prefix
,
exec_prefix
,
srcdir
=
get_config_vars
(
'prefix'
,
'exec_prefix'
,
'srcdir'
)
self
.
config_vars
=
{
'dist_name'
:
self
.
distribution
.
get_name
(),
'dist_version'
:
self
.
distribution
.
get_version
(),
'dist_fullname'
:
self
.
distribution
.
get_fullname
(),
...
...
@@ -338,12 +249,11 @@ class install(Command):
'prefix'
:
prefix
,
'sys_exec_prefix'
:
exec_prefix
,
'exec_prefix'
:
exec_prefix
,
'srcdir'
:
srcdir
,
}
if
HAS_USER_SITE
:
self
.
config_vars
[
'userbase'
]
=
self
.
install_userbase
self
.
config_vars
[
'usersite'
]
=
self
.
install_usersite
self
.
config_vars
[
'userbase'
]
=
self
.
install_userbase
self
.
config_vars
[
'usersite'
]
=
self
.
install_usersite
self
.
expand_basedirs
()
self
.
dump_dirs
(
"post-expand_basedirs()"
)
...
...
@@ -447,10 +357,10 @@ class install(Command):
raise
DistutilsPlatformError
(
"User base directory is not specified"
)
self
.
install_base
=
self
.
install_platbase
=
self
.
install_userbase
self
.
select_scheme
(
"
un
ix_user"
)
self
.
select_scheme
(
"
pos
ix_user"
)
elif
self
.
home
is
not
None
:
self
.
install_base
=
self
.
install_platbase
=
self
.
home
self
.
select_scheme
(
"
un
ix_home"
)
self
.
select_scheme
(
"
pos
ix_home"
)
else
:
if
self
.
prefix
is
None
:
if
self
.
exec_prefix
is
not
None
:
...
...
@@ -466,7 +376,7 @@ class install(Command):
self
.
install_base
=
self
.
prefix
self
.
install_platbase
=
self
.
exec_prefix
self
.
select_scheme
(
"
un
ix_prefix"
)
self
.
select_scheme
(
"
pos
ix_prefix"
)
def
finalize_other
(
self
):
"""Finalizes options for non-posix platforms"""
...
...
@@ -478,7 +388,7 @@ class install(Command):
self
.
select_scheme
(
os
.
name
+
"_user"
)
elif
self
.
home
is
not
None
:
self
.
install_base
=
self
.
install_platbase
=
self
.
home
self
.
select_scheme
(
"
un
ix_home"
)
self
.
select_scheme
(
"
pos
ix_home"
)
else
:
if
self
.
prefix
is
None
:
self
.
prefix
=
os
.
path
.
normpath
(
sys
.
prefix
)
...
...
@@ -493,11 +403,15 @@ class install(Command):
def
select_scheme
(
self
,
name
):
"""Sets the install directories by applying the install schemes."""
# it's the caller's problem if they supply a bad name!
scheme
=
INSTALL_SCHEMES
[
name
]
for
key
in
SCHEME_KEYS
:
scheme
=
get_paths
(
name
,
expand
=
False
)
for
key
,
value
in
scheme
.
items
():
if
key
==
'platinclude'
:
key
=
'headers'
value
=
os
.
path
.
join
(
value
,
self
.
distribution
.
get_name
())
attrname
=
'install_'
+
key
if
getattr
(
self
,
attrname
)
is
None
:
setattr
(
self
,
attrname
,
scheme
[
key
])
if
hasattr
(
self
,
attrname
):
if
getattr
(
self
,
attrname
)
is
None
:
setattr
(
self
,
attrname
,
value
)
def
_expand_attrs
(
self
,
attrs
):
for
attr
in
attrs
:
...
...
@@ -505,7 +419,10 @@ class install(Command):
if
val
is
not
None
:
if
os
.
name
==
'posix'
or
os
.
name
==
'nt'
:
val
=
os
.
path
.
expanduser
(
val
)
val
=
subst_vars
(
val
,
self
.
config_vars
)
try
:
val
=
_subst_vars
(
val
,
self
.
config_vars
)
except
:
import
pdb
;
pdb
.
set_trace
()
setattr
(
self
,
attr
,
val
)
def
expand_basedirs
(
self
):
...
...
core.py
View file @
efc2ae7c
...
...
@@ -35,7 +35,7 @@ usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
def
gen_usage
(
script_name
):
script
=
os
.
path
.
basename
(
script_name
)
return
USAGE
%
vars
()
return
USAGE
%
{
'script'
:
script
}
# Some mild magic to control the behaviour of 'setup()' from 'run_setup()'.
...
...
cygwinccompiler.py
View file @
efc2ae7c
...
...
@@ -337,7 +337,7 @@ def check_config_h():
# XXX since this function also checks sys.version, it's not strictly a
# "pyconfig.h" check -- should probably be renamed...
from
distutils
import
sysconfig
_sysconfig
=
__import__
(
'sysconfig'
)
# if sys.version contains GCC then python was compiled with GCC, and the
# pyconfig.h file should be OK
...
...
@@ -345,7 +345,7 @@ def check_config_h():
return
CONFIG_H_OK
,
"sys.version mentions 'GCC'"
# let's see if __GNUC__ is mentioned in python.h
fn
=
sysconfig
.
get_config_h_filename
()
fn
=
_
sysconfig
.
get_config_h_filename
()
try
:
with
open
(
fn
)
as
config_h
:
if
"__GNUC__"
in
config_h
.
read
():
...
...
extension.py
View file @
efc2ae7c
...
...
@@ -134,14 +134,17 @@ class Extension:
def
read_setup_file
(
filename
):
"""Reads a Setup file and returns Extension instances."""
from
distutils.sysconfig
import
(
parse_makefile
,
expand_makefile_vars
,
warnings
.
warn
(
'distutils.extensions.read_setup_file is deprecated. '
'It will be removed in the next Python release.'
)
_sysconfig
=
__import__
(
'sysconfig'
)
from
distutils.sysconfig
import
(
expand_makefile_vars
,
_variable_rx
)
from
distutils.text_file
import
TextFile
from
distutils.util
import
split_quoted
# First pass over the file to gather "VAR = VALUE" assignments.
vars
=
parse_makefile
(
filename
)
vars
=
_sysconfig
.
_
parse_makefile
(
filename
)
# Second pass to gobble up the real content: lines of the form
# <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...]
...
...
@@ -161,7 +164,10 @@ def read_setup_file(filename):
file
.
warn
(
"'%s' lines not handled yet"
%
line
)
continue
line
=
expand_makefile_vars
(
line
,
vars
)
with
warnings
.
catch_warnings
():
warnings
.
simplefilter
(
"ignore"
)
line
=
expand_makefile_vars
(
line
,
vars
)
words
=
split_quoted
(
line
)
# NB. this parses a slightly different syntax than the old
...
...
msvc9compiler.py
View file @
efc2ae7c
...
...
@@ -23,10 +23,10 @@ from distutils.errors import (DistutilsExecError, DistutilsPlatformError,
CompileError
,
LibError
,
LinkError
)
from
distutils.ccompiler
import
CCompiler
,
gen_lib_options
from
distutils
import
log
from
distutils.util
import
get_platform
import
_winreg
_sysconfig
=
__import__
(
'sysconfig'
)
RegOpenKeyEx
=
_winreg
.
OpenKeyEx
RegEnumKey
=
_winreg
.
EnumKey
RegEnumValue
=
_winreg
.
EnumValue
...
...
@@ -327,7 +327,7 @@ class MSVCCompiler(CCompiler) :
# multi-init means we would need to check platform same each time...
assert not self.initialized, "
don
't init multiple times"
if plat_name is None:
plat_name = get_platform()
plat_name =
_sysconfig.
get_platform()
# sanity check for platforms to prevent obscure errors later.
ok_plats = '
win32
', '
win
-
amd64
', '
win
-
ia64
'
if plat_name not in ok_plats:
...
...
@@ -348,12 +348,12 @@ class MSVCCompiler(CCompiler) :
# On AMD64, 'vcvars32.bat amd64' is a native build env; to cross
# compile use 'x86' (ie, it runs the x86 compiler directly)
# No idea how itanium handles this, if at all.
if
plat_name
==
get_platform
()
or
plat_name
==
'win32'
:
if
plat_name
==
_sysconfig
.
get_platform
()
or
plat_name
==
'win32'
:
# native build or cross-compile to win32
plat_spec
=
PLAT_TO_VCVARS
[
plat_name
]
else
:
# cross compile from win32 -> some 64bit
plat_spec
=
PLAT_TO_VCVARS
[
get_platform
()]
+
'_'
+
\
plat_spec
=
PLAT_TO_VCVARS
[
_sysconfig
.
get_platform
()]
+
'_'
+
\
PLAT_TO_VCVARS
[
plat_name
]
vc_env
=
query_vcvarsall
(
VERSION
,
plat_spec
)
...
...
sysconfig.py
View file @
efc2ae7c
...
...
@@ -7,58 +7,42 @@ available.
Written by: Fred L. Drake, Jr.
Email: <fdrake@acm.org>
**This module has been moved out of Distutils and will be removed from
Python in the next version (3.2)**
"""
__revision__
=
"$Id$"
import
os
import
re
import
sys
from
distutils.errors
import
DistutilsPlatformError
# These are needed in a couple of spots, so just compute them once.
PREFIX
=
os
.
path
.
normpath
(
sys
.
prefix
)
EXEC_PREFIX
=
os
.
path
.
normpath
(
sys
.
exec_prefix
)
# Path to the base directory of the project. On Windows the binary may
# live in project/PCBuild9. If we're dealing with an x64 Windows build,
# it'll live in project/PCbuild/amd64.
project_base
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
sys
.
executable
))
if
os
.
name
==
"nt"
and
"pcbuild"
in
project_base
[
-
8
:].
lower
():
project_base
=
os
.
path
.
abspath
(
os
.
path
.
join
(
project_base
,
os
.
path
.
pardir
))
# PC/VS7.1
if
os
.
name
==
"nt"
and
"
\
\
pc
\
\
v"
in
project_base
[
-
10
:].
lower
():
project_base
=
os
.
path
.
abspath
(
os
.
path
.
join
(
project_base
,
os
.
path
.
pardir
,
os
.
path
.
pardir
))
# PC/AMD64
if
os
.
name
==
"nt"
and
"
\
\
pcbuild
\
\
amd64"
in
project_base
[
-
14
:].
lower
():
project_base
=
os
.
path
.
abspath
(
os
.
path
.
join
(
project_base
,
os
.
path
.
pardir
,
os
.
path
.
pardir
))
# python_build: (Boolean) if true, we're either building Python or
# building an extension with an un-installed Python, so we use
# different (hard-wired) directories.
# Setup.local is available for Makefile builds including VPATH builds,
# Setup.dist is available on Windows
def
_python_build
():
for
fn
in
(
"Setup.dist"
,
"Setup.local"
):
if
os
.
path
.
isfile
(
os
.
path
.
join
(
project_base
,
"Modules"
,
fn
)):
return
True
return
False
python_build
=
_python_build
()
from
warnings
import
warn
# importing sysconfig from Lib
# to avoid this module to shadow it
_sysconfig
=
__import__
(
'sysconfig'
)
def
get_python_version
():
"""Return a string containing the major and minor Python version,
leaving off the patchlevel. Sample return values could be '1.5'
or '2.2'.
"""
return
sys
.
version
[:
3
]
_DEPRECATION_MSG
=
(
"distutils.sysconfig.%s is deprecated. "
"Use the APIs provided by the sysconfig module instead"
)
def
_get_project_base
():
return
_sysconfig
.
_PROJECT_BASE
project_base
=
_get_project_base
()
class
_DeprecatedBool
(
int
):
def
__nonzero__
(
self
):
warn
(
_DEPRECATION_MSG
%
'get_python_version'
,
DeprecationWarning
)
return
super
(
_DeprecatedBool
,
self
).
__nonzero__
()
def
_python_build
():
return
_DeprecatedBool
(
_sysconfig
.
is_python_build
())
python_build
=
_python_build
()
def
get_python_inc
(
plat_specific
=
0
,
prefix
=
None
):
"""Return the directory containing installed Python header files.
"""This function is deprecated.
Return the directory containing installed Python header files.
If 'plat_specific' is false (the default), this is the path to the
non-platform-specific header files, i.e. Python.h and so on;
...
...
@@ -68,39 +52,22 @@ def get_python_inc(plat_specific=0, prefix=None):
If 'prefix' is supplied, use it instead of sys.prefix or
sys.exec_prefix -- i.e., ignore 'plat_specific'.
"""
if
prefix
is
None
:
prefix
=
plat_specific
and
EXEC_PREFIX
or
PREFIX
if
os
.
name
==
"posix"
:
if
python_build
:
# Assume the executable is in the build directory. The
# pyconfig.h file should be in the same directory. Since
# the build directory may not be the source directory, we
# must use "srcdir" from the makefile to find the "Include"
# directory.
base
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
sys
.
executable
))
if
plat_specific
:
return
base
else
:
incdir
=
os
.
path
.
join
(
get_config_var
(
'srcdir'
),
'Include'
)
return
os
.
path
.
normpath
(
incdir
)
return
os
.
path
.
join
(
prefix
,
"include"
,
"python"
+
get_python_version
())
elif
os
.
name
==
"nt"
:
return
os
.
path
.
join
(
prefix
,
"include"
)
elif
os
.
name
==
"mac"
:
if
plat_specific
:
return
os
.
path
.
join
(
prefix
,
"Mac"
,
"Include"
)
else
:
return
os
.
path
.
join
(
prefix
,
"Include"
)
elif
os
.
name
==
"os2"
:
return
os
.
path
.
join
(
prefix
,
"Include"
)
warn
(
_DEPRECATION_MSG
%
'get_python_inc'
,
DeprecationWarning
)
get_path
=
_sysconfig
.
get_path
if
prefix
is
not
None
:
vars
=
{
'base'
:
prefix
}
return
get_path
(
'include'
,
vars
=
vars
)
if
not
plat_specific
:
return
get_path
(
'include'
)
else
:
raise
DistutilsPlatformError
(
"I don't know where Python installs its C header files "
"on platform '%s'"
%
os
.
name
)
return
get_path
(
'platinclude'
)
def
get_python_lib
(
plat_specific
=
False
,
standard_lib
=
False
,
prefix
=
None
):
"""This function is deprecated.
def
get_python_lib
(
plat_specific
=
0
,
standard_lib
=
0
,
prefix
=
None
):
"""Return the directory containing the Python library (standard or
Return the directory containing the Python library (standard or
site additions).
If 'plat_specific' is true, return the directory containing
...
...
@@ -113,153 +80,33 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
If 'prefix' is supplied, use it instead of sys.prefix or
sys.exec_prefix -- i.e., ignore 'plat_specific'.
"""
if
prefix
is
None
:
prefix
=
plat_specific
and
EXEC_PREFIX
or
PREFIX
if
os
.
name
==
"posix"
:
libpython
=
os
.
path
.
join
(
prefix
,
"lib"
,
"python"
+
get_python_version
())
if
standard_lib
:
return
libpython
else
:
return
os
.
path
.
join
(
libpython
,
"site-packages"
)
elif
os
.
name
==
"nt"
:
if
standard_lib
:
return
os
.
path
.
join
(
prefix
,
"Lib"
)
warn
(
_DEPRECATION_MSG
%
'get_python_lib'
,
DeprecationWarning
)
vars
=
{}
get_path
=
_sysconfig
.
get_path
if
prefix
is
not
None
:
if
plat_specific
:
vars
[
'platbase'
]
=
prefix
else
:
if
get_python_version
()
<
"2.2"
:
return
prefix
else
:
return
os
.
path
.
join
(
prefix
,
"Lib"
,
"site-packages"
)
vars
[
'base'
]
=
prefix
elif
os
.
name
==
"mac"
:
if
standard_lib
:
if
plat_specific
:
if
standard_lib
:
return
os
.
path
.
join
(
prefix
,
"Lib"
,
"lib-dynload"
)
else
:
return
os
.
path
.
join
(
prefix
,
"Lib"
,
"site-packages"
)
else
:
if
standard_lib
:
return
os
.
path
.
join
(
prefix
,
"Lib"
)
else
:
return
os
.
path
.
join
(
prefix
,
"Lib"
,
"site-packages"
)
elif
os
.
name
==
"os2"
:
if
standard_lib
:
return
os
.
path
.
join
(
prefix
,
"Lib"
)
return
get_path
(
'platstdlib'
,
vars
=
vars
)
else
:
return
os
.
path
.
join
(
prefix
,
"Lib"
,
"site-packages"
)
return
get_path
(
'stdlib'
,
vars
=
vars
)
else
:
raise
DistutilsPlatformError
(
"I don't know where Python installs its library "
"on platform '%s'"
%
os
.
name
)
def
customize_compiler
(
compiler
):
"""Do any platform-specific customization of a CCompiler instance.
Mainly needed on Unix, so we can plug in the information that
varies across Unices and is stored in Python's Makefile.
"""
if
compiler
.
compiler_type
==
"unix"
:
(
cc
,
cxx
,
opt
,
cflags
,
ccshared
,
ldshared
,
so_ext
,
ar
,
ar_flags
)
=
\
get_config_vars
(
'CC'
,
'CXX'
,
'OPT'
,
'CFLAGS'
,
'CCSHARED'
,
'LDSHARED'
,
'SO'
,
'AR'
,
'ARFLAGS'
)
if
'CC'
in
os
.
environ
:
cc
=
os
.
environ
[
'CC'
]
if
'CXX'
in
os
.
environ
:
cxx
=
os
.
environ
[
'CXX'
]
if
'LDSHARED'
in
os
.
environ
:
ldshared
=
os
.
environ
[
'LDSHARED'
]
if
'CPP'
in
os
.
environ
:
cpp
=
os
.
environ
[
'CPP'
]
else
:
cpp
=
cc
+
" -E"
# not always
if
'LDFLAGS'
in
os
.
environ
:
ldshared
=
ldshared
+
' '
+
os
.
environ
[
'LDFLAGS'
]
if
'CFLAGS'
in
os
.
environ
:
cflags
=
opt
+
' '
+
os
.
environ
[
'CFLAGS'
]
ldshared
=
ldshared
+
' '
+
os
.
environ
[
'CFLAGS'
]
if
'CPPFLAGS'
in
os
.
environ
:
cpp
=
cpp
+
' '
+
os
.
environ
[
'CPPFLAGS'
]
cflags
=
cflags
+
' '
+
os
.
environ
[
'CPPFLAGS'
]
ldshared
=
ldshared
+
' '
+
os
.
environ
[
'CPPFLAGS'
]
if
'AR'
in
os
.
environ
:
ar
=
os
.
environ
[
'AR'
]
if
'ARFLAGS'
in
os
.
environ
:
archiver
=
ar
+
' '
+
os
.
environ
[
'ARFLAGS'
]
else
:
archiver
=
ar
+
' '
+
ar_flags
cc_cmd
=
cc
+
' '
+
cflags
compiler
.
set_executables
(
preprocessor
=
cpp
,
compiler
=
cc_cmd
,
compiler_so
=
cc_cmd
+
' '
+
ccshared
,
compiler_cxx
=
cxx
,
linker_so
=
ldshared
,
linker_exe
=
cc
,
archiver
=
archiver
)
compiler
.
shared_lib_extension
=
so_ext
def
get_config_h_filename
():
"""Return full pathname of installed pyconfig.h file."""
if
python_build
:
if
os
.
name
==
"nt"
:
inc_dir
=
os
.
path
.
join
(
project_base
,
"PC"
)
if
plat_specific
:
return
get_path
(
'platlib'
,
vars
=
vars
)
else
:
inc_dir
=
project_base
else
:
inc_dir
=
get_python_inc
(
plat_specific
=
1
)
if
get_python_version
()
<
'2.2'
:
config_h
=
'config.h'
else
:
# The name of the config.h file changed in 2.2
config_h
=
'pyconfig.h'
return
os
.
path
.
join
(
inc_dir
,
config_h
)
return
get_path
(
'purelib'
,
vars
=
vars
)
def
get_makefile_filename
():
"""Return full pathname of installed Makefile from the Python build."""
if
python_build
:
return
os
.
path
.
join
(
os
.
path
.
dirname
(
sys
.
executable
),
"Makefile"
)
lib_dir
=
get_python_lib
(
plat_specific
=
1
,
standard_lib
=
1
)
return
os
.
path
.
join
(
lib_dir
,
"config"
,
"Makefile"
)
"""This function is deprecated.
def
parse_config_h
(
fp
,
g
=
None
):
"""Parse a config.h-style file.
A dictionary containing name/value pairs is returned. If an
optional dictionary is passed in as the second argument, it is
used instead of a new dictionary.
Return full pathname of installed Makefile from the Python build.
"""
if
g
is
None
:
g
=
{}
define_rx
=
re
.
compile
(
"#define ([A-Z][A-Za-z0-9_]+) (.*)
\
n
"
)
undef_rx
=
re
.
compile
(
"/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/
\
n
"
)
#
while
1
:
line
=
fp
.
readline
()
if
not
line
:
break
m
=
define_rx
.
match
(
line
)
if
m
:
n
,
v
=
m
.
group
(
1
,
2
)
try
:
v
=
int
(
v
)
except
ValueError
:
pass
g
[
n
]
=
v
else
:
m
=
undef_rx
.
match
(
line
)
if
m
:
g
[
m
.
group
(
1
)]
=
0
return
g
warn
(
_DEPRECATION_MSG
%
'get_makefile_filename'
,
DeprecationWarning
)
return
_sysconfig
.
_get_makefile_filename
()
# Regexes needed for parsing Makefile (and similar syntaxes,
# like old-style Setup files).
...
...
@@ -268,91 +115,29 @@ _findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
_findvar2_rx = re.compile(r"
\
$
{([
A
-
Za
-
z
][
A
-
Za
-
z0
-
9
_
]
*
)}
")
def parse_makefile(fn, g=None):
"""Parse a Makefile-style file.
"""This function is deprecated.
Parse a Makefile-style file.
A dictionary containing name/value pairs is returned. If an
optional dictionary is passed in as the second argument, it is
used instead of a new dictionary.
"""
from distutils.text_file import TextFile
fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1)
if g is None:
g = {}
done = {}
notdone = {}
while 1:
line = fp.readline()
if line is None: # eof
break
m = _variable_rx.match(line)
if m:
n, v = m.group(1, 2)
v = v.strip()
# `$$' is a literal `$' in make
tmpv = v.replace('$$', '')
if "
$
" in tmpv:
notdone[n] = v
else:
try:
v = int(v)
except ValueError:
# insert literal `$'
done[n] = v.replace('$$', '$')
else:
done[n] = v
# do variable interpolation here
while notdone:
for name in notdone.keys():
value = notdone[name]
m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
if m:
n = m.group(1)
found = True
if n in done:
item = str(done[n])
elif n in notdone:
# get it on a subsequent round
found = False
elif n in os.environ:
# do it like make: fall back to environment
item = os.environ[n]
else:
done[n] = item = ""
if found:
after = value[m.end():]
value = value[:m.start()] + item + after
if "
$
" in after:
notdone[name] = value
else:
try: value = int(value)
except ValueError:
done[name] = value.strip()
else:
done[name] = value
del notdone[name]
else:
# bogus variable reference; just drop it since we can't deal
del notdone[name]
fp.close()
# save the results in the global dictionary
g.update(done)
return g
warn(_DEPRECATION_MSG % 'parse_makefile', DeprecationWarning)
return _sysconfig._parse_makefile(fn, g)
def expand_makefile_vars(s, vars):
"""Expand Makefile-style variables -- "
$
{
foo
}
" or "
$
(
foo
)
" -- in
"""This function is deprecated.
Expand Makefile-style variables -- "
$
{
foo
}
" or "
$
(
foo
)
" -- in
'string' according to 'vars' (a dictionary mapping variable names to
values). Variables not present in 'vars' are silently expanded to the
empty string. The variable values in 'vars' should not contain further
variable expansions; if 'vars' is the output of 'parse_makefile()',
you're fine. Returns a variable-expanded version of 's'.
"""
warn('this function will be removed in then next version of Python',
DeprecationWarning)
# This algorithm does multiple expansion, so if vars['foo'] contains
# "
$
{
bar
}
", it will expand ${foo} to ${bar}, and then expand
...
...
@@ -368,264 +153,3 @@ def expand_makefile_vars(s, vars):
else:
break
return s
_config_vars = None
def _init_posix():
"""Initialize the module as appropriate for POSIX systems."""
g = {}
# load the installed Makefile:
try:
filename = get_makefile_filename()
parse_makefile(filename, g)
except IOError, msg:
my_msg = "
invalid
Python
installation
:
unable
to
open
%
s
" % filename
if hasattr(msg, "
strerror
"):
my_msg = my_msg + "
(
%
s
)
" % msg.strerror
raise DistutilsPlatformError(my_msg)
# load the installed pyconfig.h:
try:
filename = get_config_h_filename()
parse_config_h(file(filename), g)
except IOError, msg:
my_msg = "
invalid
Python
installation
:
unable
to
open
%
s
" % filename
if hasattr(msg, "
strerror
"):
my_msg = my_msg + "
(
%
s
)
" % msg.strerror
raise DistutilsPlatformError(my_msg)
# On MacOSX we need to check the setting of the environment variable
# MACOSX_DEPLOYMENT_TARGET: configure bases some choices on it so
# it needs to be compatible.
# If it isn't set we set it to the configure-time value
if sys.platform == 'darwin' and 'MACOSX_DEPLOYMENT_TARGET' in g:
cfg_target = g['MACOSX_DEPLOYMENT_TARGET']
cur_target = os.getenv('MACOSX_DEPLOYMENT_TARGET', '')
if cur_target == '':
cur_target = cfg_target
os.putenv('MACOSX_DEPLOYMENT_TARGET', cfg_target)
elif map(int, cfg_target.split('.')) > map(int, cur_target.split('.')):
my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: now "
%
s
" but "
%
s
" during configure'
% (cur_target, cfg_target))
raise DistutilsPlatformError(my_msg)
# On AIX, there are wrong paths to the linker scripts in the Makefile
# -- these paths are relative to the Python source, but when installed
# the scripts are in another directory.
if python_build:
g['LDSHARED'] = g['BLDSHARED']
elif get_python_version() < '2.1':
# The following two branches are for 1.5.2 compatibility.
if sys.platform == 'aix4': # what about AIX 3.x ?
# Linker script is in the config directory, not in Modules as the
# Makefile says.
python_lib = get_python_lib(standard_lib=1)
ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
python_exp = os.path.join(python_lib, 'config', 'python.exp')
g['LDSHARED'] = "
%
s
%
s
-
bI
:
%
s
" % (ld_so_aix, g['CC'], python_exp)
elif sys.platform == 'beos':
# Linker script is in the config directory. In the Makefile it is
# relative to the srcdir, which after installation no longer makes
# sense.
python_lib = get_python_lib(standard_lib=1)
linkerscript_path = g['LDSHARED'].split()[0]
linkerscript_name = os.path.basename(linkerscript_path)
linkerscript = os.path.join(python_lib, 'config',
linkerscript_name)
# XXX this isn't the right place to do this: adding the Python
# library to the link, if needed, should be in the "
build_ext
"
# command. (It's also needed for non-MS compilers on Windows, and
# it's taken care of for them by the 'build_ext.get_libraries()'
# method.)
g['LDSHARED'] = ("
%
s
-
L
%
s
/
lib
-
lpython
%
s
" %
(linkerscript, PREFIX, get_python_version()))
global _config_vars
_config_vars = g
def _init_nt():
"""Initialize the module as appropriate for NT"""
g = {}
# set basic install directories
g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
# XXX hmmm.. a normal install puts include files here
g['INCLUDEPY'] = get_python_inc(plat_specific=0)
g['SO'] = '.pyd'
g['EXE'] = "
.
exe
"
g['VERSION'] = get_python_version().replace("
.
", "")
g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
global _config_vars
_config_vars = g
def _init_mac():
"""Initialize the module as appropriate for Macintosh systems"""
g = {}
# set basic install directories
g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
# XXX hmmm.. a normal install puts include files here
g['INCLUDEPY'] = get_python_inc(plat_specific=0)
import MacOS
if not hasattr(MacOS, 'runtimemodel'):
g['SO'] = '.ppc.slb'
else:
g['SO'] = '.%s.slb' % MacOS.runtimemodel
# XXX are these used anywhere?
g['install_lib'] = os.path.join(EXEC_PREFIX, "
Lib
")
g['install_platlib'] = os.path.join(EXEC_PREFIX, "
Mac
", "
Lib
")
# These are used by the extension module build
g['srcdir'] = ':'
global _config_vars
_config_vars = g
def _init_os2():
"""Initialize the module as appropriate for OS/2"""
g = {}
# set basic install directories
g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
# XXX hmmm.. a normal install puts include files here
g['INCLUDEPY'] = get_python_inc(plat_specific=0)
g['SO'] = '.pyd'
g['EXE'] = "
.
exe
"
global _config_vars
_config_vars = g
def get_config_vars(*args):
"""With no arguments, return a dictionary of all configuration
variables relevant for the current platform. Generally this includes
everything needed to build extensions and install both pure modules and
extensions. On Unix, this means every variable defined in Python's
installed Makefile; on Windows and Mac OS it's a much smaller set.
With arguments, return a list of values that result from looking up
each argument in the configuration variable dictionary.
"""
global _config_vars
if _config_vars is None:
func = globals().get("
_init_
" + os.name)
if func:
func()
else:
_config_vars = {}
# Normalized versions of prefix and exec_prefix are handy to have;
# in fact, these are the standard versions used most places in the
# Distutils.
_config_vars['prefix'] = PREFIX
_config_vars['exec_prefix'] = EXEC_PREFIX
if 'srcdir' not in _config_vars:
_config_vars['srcdir'] = project_base
# Convert srcdir into an absolute path if it appears necessary.
# Normally it is relative to the build directory. However, during
# testing, for example, we might be running a non-installed python
# from a different directory.
if python_build and os.name == "
posix
":
base = os.path.dirname(os.path.abspath(sys.executable))
if (not os.path.isabs(_config_vars['srcdir']) and
base != os.getcwd()):
# srcdir is relative and we are not in the same directory
# as the executable. Assume executable is in the build
# directory and make srcdir absolute.
srcdir = os.path.join(base, _config_vars['srcdir'])
_config_vars['srcdir'] = os.path.normpath(srcdir)
if sys.platform == 'darwin':
kernel_version = os.uname()[2] # Kernel version (8.4.3)
major_version = int(kernel_version.split('.')[0])
if major_version < 8:
# On Mac OS X before 10.4, check if -arch and -isysroot
# are in CFLAGS or LDFLAGS and remove them if they are.
# This is needed when building extensions on a 10.3 system
# using a universal build of python.
for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
# a number of derived variables. These need to be
# patched up as well.
'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
flags = _config_vars[key]
flags = re.sub('-arch
\
s+
\
w+
\
s
'
, ' ', flags)
flags = re.sub('-isysroot [^
\
t
]*', ' ', flags)
_config_vars[key] = flags
else:
# Allow the user to override the architecture flags using
# an environment variable.
# NOTE: This name was introduced by Apple in OSX 10.5 and
# is used by several scripting languages distributed with
# that OS release.
if 'ARCHFLAGS' in os.environ:
arch = os.environ['ARCHFLAGS']
for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
# a number of derived variables. These need to be
# patched up as well.
'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
flags = _config_vars[key]
flags = re.sub('-arch
\
s+
\
w+
\
s
'
, ' ', flags)
flags = flags + ' ' + arch
_config_vars[key] = flags
# If we're on OSX 10.5 or later and the user tries to
# compiles an extension using an SDK that is not present
# on the current machine it is better to not use an SDK
# than to fail.
#
# The major usecase for this is users using a Python.org
# binary installer on OSX 10.6: that installer uses
# the 10.4u SDK, but that SDK is not installed by default
# when you install Xcode.
#
m = re.search('-isysroot
\
s+(
\
S+)', _config_vars['CFLAGS'])
if m is not None:
sdk = m.group(1)
if not os.path.exists(sdk):
for key in ('LDFLAGS', 'BASECFLAGS', 'LDSHARED',
# a number of derived variables. These need to be
# patched up as well.
'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
flags = _config_vars[key]
flags = re.sub('-isysroot
\
s+
\
S+(
\
s|$)
'
, ' ', flags)
_config_vars[key] = flags
if args:
vals = []
for name in args:
vals.append(_config_vars.get(name))
return vals
else:
return _config_vars
def get_config_var(name):
"""Return the value of a single variable using the dictionary
returned by 'get_config_vars()'. Equivalent to
get_config_vars().get(name)
"""
return get_config_vars().get(name)
tests/support.py
View file @
efc2ae7c
...
...
@@ -3,11 +3,19 @@ import os
import
shutil
import
tempfile
from
copy
import
deepcopy
import
warnings
from
distutils
import
log
from
distutils.log
import
DEBUG
,
INFO
,
WARN
,
ERROR
,
FATAL
from
distutils.core
import
Distribution
def
capture_warnings
(
func
):
def
_capture_warnings
(
*
args
,
**
kw
):
with
warnings
.
catch_warnings
():
warnings
.
simplefilter
(
"ignore"
)
return
func
(
*
args
,
**
kw
)
return
_capture_warnings
class
LoggingSilencer
(
object
):
def
setUp
(
self
):
...
...
tests/test_build.py
View file @
efc2ae7c
...
...
@@ -5,7 +5,7 @@ import sys
from
distutils.command.build
import
build
from
distutils.tests
import
support
from
distutils.util
import
get_platform
from
sysconfig
import
get_platform
class
BuildTestCase
(
support
.
TempdirManager
,
support
.
LoggingSilencer
,
...
...
tests/test_build_clib.py
View file @
efc2ae7c
...
...
@@ -120,8 +120,7 @@ class BuildCLibTestCase(support.TempdirManager,
# before we run the command, we want to make sure
# all commands are present on the system
# by creating a compiler and checking its executables
from
distutils.ccompiler
import
new_compiler
from
distutils.sysconfig
import
customize_compiler
from
distutils.ccompiler
import
new_compiler
,
customize_compiler
compiler
=
new_compiler
()
customize_compiler
(
compiler
)
...
...
tests/test_build_ext.py
View file @
efc2ae7c
...
...
@@ -9,7 +9,7 @@ from test.test_support import captured_stdout
from
distutils.core
import
Extension
,
Distribution
from
distutils.command.build_ext
import
build_ext
from
distutils
import
sysconfig
import
sysconfig
from
distutils.tests
import
support
from
distutils.extension
import
Extension
from
distutils.errors
import
(
UnknownFileError
,
DistutilsSetupError
,
...
...
@@ -105,17 +105,17 @@ class BuildExtTestCase(support.TempdirManager,
old
=
sys
.
platform
sys
.
platform
=
'sunos'
# fooling finalize_options
from
distutils.sysconfig
import
_config_vars
old_var
=
_
config_vars
.
get
(
'Py_ENABLE_SHARED'
)
_
config_vars
[
'Py_ENABLE_SHARED'
]
=
1
from
sysconfig
import
_CONFIG_VARS
old_var
=
_
CONFIG_VARS
.
get
(
'Py_ENABLE_SHARED'
)
_
CONFIG_VARS
[
'Py_ENABLE_SHARED'
]
=
1
try
:
cmd
.
ensure_finalized
()
finally
:
sys
.
platform
=
old
if
old_var
is
None
:
del
_
config_vars
[
'Py_ENABLE_SHARED'
]
del
_
CONFIG_VARS
[
'Py_ENABLE_SHARED'
]
else
:
_
config_vars
[
'Py_ENABLE_SHARED'
]
=
old_var
_
CONFIG_VARS
[
'Py_ENABLE_SHARED'
]
=
old_var
# make sure we get some library dirs under solaris
self
.
assertTrue
(
len
(
cmd
.
library_dirs
)
>
0
)
...
...
@@ -177,11 +177,10 @@ class BuildExtTestCase(support.TempdirManager,
cmd
=
build_ext
(
dist
)
cmd
.
finalize_options
()
from
distutils
import
sysconfig
py_include
=
sysconfig
.
get_python_inc
()
py_include
=
sysconfig
.
get_path
(
'include'
)
self
.
assertTrue
(
py_include
in
cmd
.
include_dirs
)
plat_py_include
=
sysconfig
.
get_p
ython_inc
(
plat_specific
=
1
)
plat_py_include
=
sysconfig
.
get_p
ath
(
'platinclude'
)
self
.
assertTrue
(
plat_py_include
in
cmd
.
include_dirs
)
# make sure cmd.libraries is turned into a list
...
...
tests/test_build_scripts.py
View file @
efc2ae7c
...
...
@@ -5,7 +5,7 @@ import unittest
from
distutils.command.build_scripts
import
build_scripts
from
distutils.core
import
Distribution
from
distutils
import
sysconfig
import
sysconfig
from
distutils.tests
import
support
...
...
@@ -91,12 +91,12 @@ class BuildScriptsTestCase(support.TempdirManager,
# --with-suffix=3`, python is compiled okay but the build scripts
# failed when writing the name of the executable
old
=
sysconfig
.
get_config_vars
().
get
(
'VERSION'
)
sysconfig
.
_
config_vars
[
'VERSION'
]
=
4
sysconfig
.
_
CONFIG_VARS
[
'VERSION'
]
=
4
try
:
cmd
.
run
()
finally
:
if
old
is
not
None
:
sysconfig
.
_
config_vars
[
'VERSION'
]
=
old
sysconfig
.
_
CONFIG_VARS
[
'VERSION'
]
=
old
built
=
os
.
listdir
(
target
)
for
name
in
expected
:
...
...
tests/test_ccompiler.py
View file @
efc2ae7c
...
...
@@ -3,8 +3,10 @@ import os
import
unittest
from
test.test_support
import
captured_stdout
from
distutils.ccompiler
import
gen_lib_options
,
CCompiler
from
distutils.ccompiler
import
(
gen_lib_options
,
CCompiler
,
get_default_compiler
,
customize_compiler
)
from
distutils
import
debug
from
distutils.tests
import
support
class
FakeCompiler
(
object
):
def
library_dir_option
(
self
,
dir
):
...
...
@@ -19,7 +21,7 @@ class FakeCompiler(object):
def
library_option
(
self
,
lib
):
return
"-l"
+
lib
class
CCompilerTestCase
(
unittest
.
TestCase
):
class
CCompilerTestCase
(
support
.
EnvironGuard
,
unittest
.
TestCase
):
def
test_gen_lib_options
(
self
):
compiler
=
FakeCompiler
()
...
...
@@ -52,6 +54,26 @@ class CCompilerTestCase(unittest.TestCase):
finally
:
debug
.
DEBUG
=
False
def
test_customize_compiler
(
self
):
# not testing if default compiler is not unix
if
get_default_compiler
()
!=
'unix'
:
return
os
.
environ
[
'AR'
]
=
'my_ar'
os
.
environ
[
'ARFLAGS'
]
=
'-arflags'
# make sure AR gets caught
class
compiler
:
compiler_type
=
'unix'
def
set_executables
(
self
,
**
kw
):
self
.
exes
=
kw
comp
=
compiler
()
customize_compiler
(
comp
)
self
.
assertEquals
(
comp
.
exes
[
'archiver'
],
'my_ar -arflags'
)
def
test_suite
():
return
unittest
.
makeSuite
(
CCompilerTestCase
)
...
...
tests/test_cygwinccompiler.py
View file @
efc2ae7c
...
...
@@ -3,6 +3,7 @@ import unittest
import
sys
import
os
import
warnings
import
sysconfig
from
test.test_support
import
check_warnings
from
test.test_support
import
captured_stdout
...
...
@@ -22,13 +23,11 @@ class CygwinCCompilerTestCase(support.TempdirManager,
super
(
CygwinCCompilerTestCase
,
self
).
setUp
()
self
.
version
=
sys
.
version
self
.
python_h
=
os
.
path
.
join
(
self
.
mkdtemp
(),
'python.h'
)
from
distutils
import
sysconfig
self
.
old_get_config_h_filename
=
sysconfig
.
get_config_h_filename
sysconfig
.
get_config_h_filename
=
self
.
_get_config_h_filename
def
tearDown
(
self
):
sys
.
version
=
self
.
version
from
distutils
import
sysconfig
sysconfig
.
get_config_h_filename
=
self
.
old_get_config_h_filename
super
(
CygwinCCompilerTestCase
,
self
).
tearDown
()
...
...
tests/test_extension.py
View file @
efc2ae7c
...
...
@@ -5,9 +5,11 @@ import warnings
from
test.test_support
import
check_warnings
from
distutils.extension
import
read_setup_file
,
Extension
from
distutils.tests.support
import
capture_warnings
class
ExtensionTestCase
(
unittest
.
TestCase
):
@
capture_warnings
def
test_read_setup_file
(
self
):
# trying to read a Setup file
# (sample extracted from the PyGame project)
...
...
tests/test_install.py
View file @
efc2ae7c
...
...
@@ -5,12 +5,14 @@ import os.path
import
sys
import
unittest
import
site
import
sysconfig
from
sysconfig
import
(
get_scheme_names
,
_CONFIG_VARS
,
_INSTALL_SCHEMES
,
get_config_var
,
get_path
)
from
test.test_support
import
captured_stdout
from
distutils.command.install
import
install
from
distutils.command
import
install
as
install_module
from
distutils.command.install
import
INSTALL_SCHEMES
from
distutils.core
import
Distribution
from
distutils.errors
import
DistutilsOptionError
...
...
@@ -36,9 +38,23 @@ class InstallTestCase(support.TempdirManager,
build_lib
=
os
.
path
.
join
(
builddir
,
"lib"
),
)
cmd
=
install
(
dist
)
cmd
.
home
=
destination
cmd
.
ensure_finalized
()
posix_prefix
=
_INSTALL_SCHEMES
[
'posix_prefix'
]
old_posix_prefix
=
posix_prefix
[
'platinclude'
]
posix_prefix
[
'platinclude'
]
=
\
'{platbase}/include/python{py_version_short}'
posix_home
=
_INSTALL_SCHEMES
[
'posix_home'
]
old_posix_home
=
posix_home
[
'platinclude'
]
posix_home
[
'platinclude'
]
=
'{base}/include/python'
try
:
cmd
=
install
(
dist
)
cmd
.
home
=
destination
cmd
.
ensure_finalized
()
finally
:
posix_home
[
'platinclude'
]
=
old_posix_home
posix_prefix
[
'platinclude'
]
=
old_posix_prefix
self
.
assertEqual
(
cmd
.
install_base
,
destination
)
self
.
assertEqual
(
cmd
.
install_platbase
,
destination
)
...
...
@@ -63,18 +79,19 @@ class InstallTestCase(support.TempdirManager,
return
# preparing the environement for the test
self
.
old_user_base
=
site
.
USER_BASE
self
.
old_user_site
=
site
.
USER_SITE
self
.
old_user_base
=
get_config_var
(
'userbase'
)
self
.
old_user_site
=
get_path
(
'purelib'
,
'%s_user'
%
os
.
name
)
self
.
tmpdir
=
self
.
mkdtemp
()
self
.
user_base
=
os
.
path
.
join
(
self
.
tmpdir
,
'B'
)
self
.
user_site
=
os
.
path
.
join
(
self
.
tmpdir
,
'S'
)
site
.
USER_BASE
=
self
.
user_base
site
.
USER_SITE
=
self
.
user_site
install_module
.
USER_BASE
=
self
.
user_base
install_module
.
USER_SITE
=
self
.
user_site
_CONFIG_VARS
[
'userbase'
]
=
self
.
user_base
scheme
=
_INSTALL_SCHEMES
[
'%s_user'
%
os
.
name
]
scheme
[
'purelib'
]
=
self
.
user_site
def
_expanduser
(
path
):
return
self
.
tmpdir
if
path
[
0
]
==
'~'
:
path
=
os
.
path
.
normpath
(
self
.
tmpdir
)
+
path
[
1
:]
return
path
self
.
old_expand
=
os
.
path
.
expanduser
os
.
path
.
expanduser
=
_expanduser
...
...
@@ -82,19 +99,17 @@ class InstallTestCase(support.TempdirManager,
# this is the actual test
self
.
_test_user_site
()
finally
:
site
.
USER_BASE
=
self
.
old_user_base
site
.
USER_SITE
=
self
.
old_user_site
install_module
.
USER_BASE
=
self
.
old_user_base
install_module
.
USER_SITE
=
self
.
old_user_site
_CONFIG_VARS
[
'userbase'
]
=
self
.
old_user_base
scheme
[
'purelib'
]
=
self
.
old_user_site
os
.
path
.
expanduser
=
self
.
old_expand
def
_test_user_site
(
self
):
for
key
in
(
'nt_user'
,
'unix_user'
,
'os2_home'
):
self
.
assertTrue
(
key
in
INSTALL_SCHEMES
)
schemes
=
get_scheme_names
()
for
key
in
(
'nt_user'
,
'posix_user'
,
'os2_home'
):
self
.
assertTrue
(
key
in
schemes
)
dist
=
Distribution
({
'name'
:
'xx'
})
cmd
=
install
(
dist
)
# making sure the user option is there
options
=
[
name
for
name
,
short
,
lable
in
cmd
.
user_options
]
...
...
@@ -185,7 +200,7 @@ class InstallTestCase(support.TempdirManager,
with
open
(
cmd
.
record
)
as
f
:
self
.
assertEquals
(
len
(
f
.
readlines
()),
1
)
def
test_debug_mode
(
self
):
def
_
test_debug_mode
(
self
):
# this covers the code called when DEBUG is set
old_logs_len
=
len
(
self
.
logs
)
install_module
.
DEBUG
=
True
...
...
tests/test_sysconfig.py
View file @
efc2ae7c
...
...
@@ -4,7 +4,6 @@ import test
import
unittest
from
distutils
import
sysconfig
from
distutils.ccompiler
import
get_default_compiler
from
distutils.tests
import
support
from
test.test_support
import
TESTFN
...
...
@@ -27,10 +26,6 @@ class SysconfigTestCase(support.EnvironGuard,
elif
os
.
path
.
isdir
(
path
):
shutil
.
rmtree
(
path
)
def
test_get_config_h_filename
(
self
):
config_h
=
sysconfig
.
get_config_h_filename
()
self
.
assertTrue
(
os
.
path
.
isfile
(
config_h
),
config_h
)
def
test_get_python_lib
(
self
):
lib_dir
=
sysconfig
.
get_python_lib
()
# XXX doesn't work on Linux when Python was never installed before
...
...
@@ -38,6 +33,9 @@ class SysconfigTestCase(support.EnvironGuard,
# test for pythonxx.lib?
self
.
assertNotEqual
(
sysconfig
.
get_python_lib
(),
sysconfig
.
get_python_lib
(
prefix
=
TESTFN
))
_sysconfig
=
__import__
(
'sysconfig'
)
res
=
sysconfig
.
get_python_lib
(
True
,
True
)
self
.
assertEquals
(
_sysconfig
.
get_path
(
'platstdlib'
),
res
)
def
test_get_python_inc
(
self
):
inc_dir
=
sysconfig
.
get_python_inc
()
...
...
@@ -48,31 +46,6 @@ class SysconfigTestCase(support.EnvironGuard,
python_h
=
os
.
path
.
join
(
inc_dir
,
"Python.h"
)
self
.
assertTrue
(
os
.
path
.
isfile
(
python_h
),
python_h
)
def
test_get_config_vars
(
self
):
cvars
=
sysconfig
.
get_config_vars
()
self
.
assertTrue
(
isinstance
(
cvars
,
dict
))
self
.
assertTrue
(
cvars
)
def
test_customize_compiler
(
self
):
# not testing if default compiler is not unix
if
get_default_compiler
()
!=
'unix'
:
return
os
.
environ
[
'AR'
]
=
'my_ar'
os
.
environ
[
'ARFLAGS'
]
=
'-arflags'
# make sure AR gets caught
class
compiler
:
compiler_type
=
'unix'
def
set_executables
(
self
,
**
kw
):
self
.
exes
=
kw
comp
=
compiler
()
sysconfig
.
customize_compiler
(
comp
)
self
.
assertEquals
(
comp
.
exes
[
'archiver'
],
'my_ar -arflags'
)
def
test_parse_makefile_base
(
self
):
self
.
makefile
=
test
.
test_support
.
TESTFN
fd
=
open
(
self
.
makefile
,
'w'
)
...
...
tests/test_unixccompiler.py
View file @
efc2ae7c
"""Tests for distutils.unixccompiler."""
import
sys
import
unittest
import
sysconfig
from
distutils
import
sysconfig
from
distutils.unixccompiler
import
UnixCCompiler
class
UnixCCompilerTestCase
(
unittest
.
TestCase
):
...
...
tests/test_util.py
View file @
efc2ae7c
...
...
@@ -6,15 +6,14 @@ from copy import copy
from
StringIO
import
StringIO
import
subprocess
from
sysconfig
import
get_config_vars
,
get_platform
from
distutils.errors
import
DistutilsPlatformError
,
DistutilsByteCompileError
from
distutils.util
import
(
get_platform
,
convert_path
,
change_root
,
from
distutils.util
import
(
convert_path
,
change_root
,
check_environ
,
split_quoted
,
strtobool
,
rfc822_escape
,
get_compiler_versions
,
_find_exe_version
,
_MAC_OS_X_LD_VERSION
,
byte_compile
)
from
distutils
import
util
from
distutils.sysconfig
import
get_config_vars
from
distutils
import
sysconfig
from
distutils.tests
import
support
from
distutils.version
import
LooseVersion
...
...
@@ -44,7 +43,7 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
self
.
join
=
os
.
path
.
join
self
.
isabs
=
os
.
path
.
isabs
self
.
splitdrive
=
os
.
path
.
splitdrive
self
.
_config_vars
=
copy
(
sysconfig
.
_config_vars
)
#
self._config_vars = copy(sysconfig._config_vars)
# patching os.uname
if
hasattr
(
os
,
'uname'
):
...
...
@@ -78,7 +77,7 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
os
.
uname
=
self
.
uname
else
:
del
os
.
uname
sysconfig
.
_config_vars
=
copy
(
self
.
_config_vars
)
#
sysconfig._config_vars = copy(self._config_vars)
util
.
find_executable
=
self
.
old_find_executable
subprocess
.
Popen
=
self
.
old_popen
sys
.
old_stdout
=
self
.
old_stdout
...
...
@@ -91,7 +90,7 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
def
_get_uname
(
self
):
return
self
.
_uname
def
test_get_platform
(
self
):
def
_
test_get_platform
(
self
):
# windows XP, 32bits
os
.
name
=
'nt'
...
...
@@ -119,26 +118,6 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
sys
.
version
=
(
'2.5 (r25:51918, Sep 19 2006, 08:49:13) '
'
\
n
[GCC 4.0.1 (Apple Computer, Inc. build 5341)]'
)
sys
.
platform
=
'darwin'
self
.
_set_uname
((
'Darwin'
,
'macziade'
,
'8.11.1'
,
(
'Darwin Kernel Version 8.11.1: '
'Wed Oct 10 18:23:28 PDT 2007; '
'root:xnu-792.25.20~1/RELEASE_I386'
),
'PowerPC'
))
os
.
environ
[
'MACOSX_DEPLOYMENT_TARGET'
]
=
'10.3'
get_config_vars
()[
'CFLAGS'
]
=
(
'-fno-strict-aliasing -DNDEBUG -g '
'-fwrapv -O3 -Wall -Wstrict-prototypes'
)
maxint
=
sys
.
maxint
try
:
sys
.
maxint
=
2147483647
self
.
assertEquals
(
get_platform
(),
'macosx-10.3-ppc'
)
sys
.
maxint
=
9223372036854775807
self
.
assertEquals
(
get_platform
(),
'macosx-10.3-ppc64'
)
finally
:
sys
.
maxint
=
maxint
self
.
_set_uname
((
'Darwin'
,
'macziade'
,
'8.11.1'
,
(
'Darwin Kernel Version 8.11.1: '
'Wed Oct 10 18:23:28 PDT 2007; '
...
...
@@ -148,15 +127,7 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
get_config_vars
()[
'CFLAGS'
]
=
(
'-fno-strict-aliasing -DNDEBUG -g '
'-fwrapv -O3 -Wall -Wstrict-prototypes'
)
maxint
=
sys
.
maxint
try
:
sys
.
maxint
=
2147483647
self
.
assertEquals
(
get_platform
(),
'macosx-10.3-i386'
)
sys
.
maxint
=
9223372036854775807
self
.
assertEquals
(
get_platform
(),
'macosx-10.3-x86_64'
)
finally
:
sys
.
maxint
=
maxint
self
.
assertEquals
(
get_platform
(),
'macosx-10.3-i386'
)
# macbook with fat binaries (fat, universal or fat64)
os
.
environ
[
'MACOSX_DEPLOYMENT_TARGET'
]
=
'10.4'
...
...
@@ -201,7 +172,6 @@ class UtilTestCase(support.EnvironGuard, unittest.TestCase):
self
.
assertEquals
(
get_platform
(),
'macosx-10.4-%s'
%
(
arch
,))
# linux debian sarge
os
.
name
=
'posix'
sys
.
version
=
(
'2.3.5 (#1, Jul 4 2007, 17:28:59) '
...
...
unixccompiler.py
View file @
efc2ae7c
...
...
@@ -18,7 +18,6 @@ __revision__ = "$Id$"
import
os
,
sys
from
types
import
StringType
,
NoneType
from
distutils
import
sysconfig
from
distutils.dep_util
import
newer
from
distutils.ccompiler
import
\
CCompiler
,
gen_preprocess_options
,
gen_lib_options
...
...
@@ -26,6 +25,7 @@ from distutils.errors import \
DistutilsExecError
,
CompileError
,
LibError
,
LinkError
from
distutils
import
log
# XXX Things not currently handled:
# * optimization/debug/warning flags; we just use whatever's in Python's
# Makefile and live with it. Is this adequate? If not, we might
...
...
@@ -75,7 +75,7 @@ def _darwin_compiler_fixup(compiler_so, cc_args):
if
'ARCHFLAGS'
in
os
.
environ
and
not
stripArch
:
# User specified different -arch flags in the environ,
# see also
distutils.
sysconfig
# see also
the
sysconfig
compiler_so
=
compiler_so
+
os
.
environ
[
'ARCHFLAGS'
].
split
()
if
stripSysroot
:
...
...
@@ -283,7 +283,9 @@ class UnixCCompiler(CCompiler):
# this time, there's no way to determine this information from
# the configuration data stored in the Python installation, so
# we use this hack.
compiler
=
os
.
path
.
basename
(
sysconfig
.
get_config_var
(
"CC"
))
_sysconfig
=
__import__
(
'sysconfig'
)
compiler
=
os
.
path
.
basename
(
_sysconfig
.
get_config_var
(
"CC"
))
if
sys
.
platform
[:
6
]
==
"darwin"
:
# MacOSX's linker doesn't understand the -R flag at all
return
"-L"
+
dir
...
...
@@ -298,7 +300,7 @@ class UnixCCompiler(CCompiler):
# use it anyway. Since distutils has always passed in
# -Wl whenever gcc was used in the past it is probably
# safest to keep doing so.
if
sysconfig
.
get_config_var
(
"GNULD"
)
==
"yes"
:
if
_
sysconfig
.
get_config_var
(
"GNULD"
)
==
"yes"
:
# GNU ld needs an extra option to get a RUNPATH
# instead of just an RPATH.
return
"-Wl,--enable-new-dtags,-R"
+
dir
...
...
util.py
View file @
efc2ae7c
...
...
@@ -15,173 +15,7 @@ from distutils import log
from
distutils.version
import
LooseVersion
from
distutils.errors
import
DistutilsByteCompileError
def
get_platform
():
"""Return a string that identifies the current platform.
This is used mainly to distinguish platform-specific build directories and
platform-specific built distributions. Typically includes the OS name
and version and the architecture (as supplied by 'os.uname()'),
although the exact information included depends on the OS; eg. for IRIX
the architecture isn't particularly important (IRIX only runs on SGI
hardware), but for Linux the kernel version isn't particularly
important.
Examples of returned values:
linux-i586
linux-alpha (?)
solaris-2.6-sun4u
irix-5.3
irix64-6.2
Windows will return one of:
win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc)
win-ia64 (64bit Windows on Itanium)
win32 (all others - specifically, sys.platform is returned)
For other non-POSIX platforms, currently just returns 'sys.platform'.
"""
if
os
.
name
==
'nt'
:
# sniff sys.version for architecture.
prefix
=
" bit ("
i
=
sys
.
version
.
find
(
prefix
)
if
i
==
-
1
:
return
sys
.
platform
j
=
sys
.
version
.
find
(
")"
,
i
)
look
=
sys
.
version
[
i
+
len
(
prefix
):
j
].
lower
()
if
look
==
'amd64'
:
return
'win-amd64'
if
look
==
'itanium'
:
return
'win-ia64'
return
sys
.
platform
if
os
.
name
!=
"posix"
or
not
hasattr
(
os
,
'uname'
):
# XXX what about the architecture? NT is Intel or Alpha,
# Mac OS is M68k or PPC, etc.
return
sys
.
platform
# Try to distinguish various flavours of Unix
(
osname
,
host
,
release
,
version
,
machine
)
=
os
.
uname
()
# Convert the OS name to lowercase, remove '/' characters
# (to accommodate BSD/OS), and translate spaces (for "Power Macintosh")
osname
=
osname
.
lower
().
replace
(
'/'
,
''
)
machine
=
machine
.
replace
(
' '
,
'_'
)
machine
=
machine
.
replace
(
'/'
,
'-'
)
if
osname
[:
5
]
==
"linux"
:
# At least on Linux/Intel, 'machine' is the processor --
# i386, etc.
# XXX what about Alpha, SPARC, etc?
return
"%s-%s"
%
(
osname
,
machine
)
elif
osname
[:
5
]
==
"sunos"
:
if
release
[
0
]
>=
"5"
:
# SunOS 5 == Solaris 2
osname
=
"solaris"
release
=
"%d.%s"
%
(
int
(
release
[
0
])
-
3
,
release
[
2
:])
# fall through to standard osname-release-machine representation
elif
osname
[:
4
]
==
"irix"
:
# could be "irix64"!
return
"%s-%s"
%
(
osname
,
release
)
elif
osname
[:
3
]
==
"aix"
:
return
"%s-%s.%s"
%
(
osname
,
version
,
release
)
elif
osname
[:
6
]
==
"cygwin"
:
osname
=
"cygwin"
rel_re
=
re
.
compile
(
r'[\
d.]+
')
m = rel_re.match(release)
if m:
release = m.group()
elif osname[:6] == "darwin":
#
# For our purposes, we'
ll
assume
that
the
system
version
from
# distutils' perspective is what MACOSX_DEPLOYMENT_TARGET is set
# to. This makes the compatibility story a bit more sane because the
# machine is going to compile and link as if it were
# MACOSX_DEPLOYMENT_TARGET.
from
distutils.sysconfig
import
get_config_vars
cfgvars
=
get_config_vars
()
macver
=
os
.
environ
.
get
(
'MACOSX_DEPLOYMENT_TARGET'
)
if
not
macver
:
macver
=
cfgvars
.
get
(
'MACOSX_DEPLOYMENT_TARGET'
)
if
1
:
# Always calculate the release of the running machine,
# needed to determine if we can build fat binaries or not.
macrelease
=
macver
# Get the system version. Reading this plist is a documented
# way to get the system version (see the documentation for
# the Gestalt Manager)
try
:
f
=
open
(
'/System/Library/CoreServices/SystemVersion.plist'
)
except
IOError
:
# We're on a plain darwin box, fall back to the default
# behaviour.
pass
else
:
m
=
re
.
search
(
r'<key>ProductUserVisibleVersion</key>\
s*
' +
r'
<
string
>
(.
*
?
)
</
string
>
', f.read())
f.close()
if m is not None:
macrelease = '
.
'.join(m.group(1).split('
.
')[:2])
# else: fall back to the default behaviour
if not macver:
macver = macrelease
if macver:
from distutils.sysconfig import get_config_vars
release = macver
osname = "macosx"
if (macrelease + '
.
') >= '
10.4
.
' and
\
'
-
arch
' in get_config_vars().get('
CFLAGS
', '').strip():
# The universal build will build fat binaries, but not on
# systems before 10.4
#
# Try to detect 4-way universal builds, those have machine-type
# '
universal
' instead of '
fat
'.
machine = '
fat
'
cflags = get_config_vars().get('
CFLAGS
')
archs = re.findall('
-
arch
\
s
+
(
\
S
+
)
', cflags)
archs.sort()
archs = tuple(archs)
if len(archs) == 1:
machine = archs[0]
elif archs == ('
i386
', '
ppc
'):
machine = '
fat
'
elif archs == ('
i386
', '
x86_64
'):
machine = '
intel
'
elif archs == ('
i386
', '
ppc
', '
x86_64
'):
machine = '
fat3
'
elif archs == ('
ppc64
', '
x86_64
'):
machine = '
fat64
'
elif archs == ('
i386
', '
ppc
', '
ppc64
', '
x86_64
'):
machine = '
universal
'
else:
raise ValueError(
"Don'
t
know
machine
value
for
archs
=%
r"%(archs,))
elif machine == 'i386':
# On OSX the machine type returned by uname is always the
# 32-bit variant, even if the executable architecture is
# the 64-bit variant
if sys.maxint >= 2**32:
machine = 'x86_64'
elif machine in ('PowerPC', 'Power_Macintosh'):
# Pick a sane name for the PPC architecture.
machine = 'ppc'
# See 'i386' case
if sys.maxint >= 2**32:
machine = 'ppc64'
return "
%
s
-%
s
-%
s
" % (osname, release, machine)
_sysconfig
=
__import__
(
'sysconfig'
)
def
convert_path
(
pathname
):
"""Return 'pathname' as a name that will work on the native filesystem.
...
...
@@ -269,7 +103,7 @@ def check_environ():
os
.
environ
[
'HOME'
]
=
pwd
.
getpwuid
(
os
.
getuid
())[
5
]
if
'PLAT'
not
in
os
.
environ
:
os.environ['PLAT'] = get_platform()
os
.
environ
[
'PLAT'
]
=
_sysconfig
.
get_platform
()
_environ_checked
=
1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment