[Python-checkins] distutils2: Remove unneeded imports, pepeightize
tarek.ziade
python-checkins at python.org
Sun Dec 26 14:21:45 CET 2010
tarek.ziade pushed cc438627130d to distutils2:
http://hg.python.org/distutils2/rev/cc438627130d
changeset: 840:cc438627130d
user: ?ric Araujo <merwok at netwok.org>
date: Mon Nov 22 02:40:51 2010 +0100
summary:
Remove unneeded imports, pepeightize
files:
distutils2/_backport/sysconfig.py
diff --git a/distutils2/_backport/sysconfig.py b/distutils2/_backport/sysconfig.py
--- a/distutils2/_backport/sysconfig.py
+++ b/distutils2/_backport/sysconfig.py
@@ -1,8 +1,6 @@
-"""Provide access to Python's configuration information.
-
-"""
+"""Provide access to Python's configuration information."""
+import os
import sys
-import os
import re
from os.path import pardir, realpath
from ConfigParser import RawConfigParser
@@ -18,6 +16,7 @@
_SCHEMES.read(_CONFIG_FILE)
_VAR_REPL = re.compile(r'\{([^{]*?)\}')
+
def _expand_globals(config):
if config.has_section('globals'):
globals = config.items('globals')
@@ -38,11 +37,13 @@
#
for section in config.sections():
variables = dict(config.items(section))
+
def _replacer(matchobj):
name = matchobj.group(1)
if name in variables:
return variables[name]
return matchobj.group(0)
+
for option, value in config.items(section):
config.set(section, option, _VAR_REPL.sub(_replacer, value))
@@ -69,6 +70,7 @@
if os.name == "nt" and "\\pcbuild\\amd64" in _PROJECT_BASE[-14:].lower():
_PROJECT_BASE = realpath(os.path.join(_PROJECT_BASE, pardir, pardir))
+
def is_python_build():
for fn in ("Setup.dist", "Setup.local"):
if os.path.isfile(os.path.join(_PROJECT_BASE, "Modules", fn)):
@@ -84,7 +86,8 @@
def _subst_vars(path, local_vars):
- """In the string `path`, replace tokens like {some.thing} with the corresponding value from the map `local_vars`.
+ """In the string `path`, replace tokens like {some.thing} with the
+ corresponding value from the map `local_vars`.
If there is no corresponding value, leave the token unchanged.
"""
@@ -97,6 +100,7 @@
return matchobj.group(0)
return _VAR_REPL.sub(_replacer, path)
+
def _extend_dict(target_dict, other_dict):
target_keys = target_dict.keys()
for key, value in other_dict.items():
@@ -104,6 +108,7 @@
continue
target_dict[key] = value
+
def _expand_vars(scheme, vars):
res = {}
if vars is None:
@@ -116,14 +121,17 @@
res[key] = os.path.normpath(_subst_vars(value, vars))
return res
+
def _get_default_scheme():
if os.name == 'posix':
# the default scheme for posix is posix_prefix
return 'posix_prefix'
return os.name
+
def _getuserbase():
env_base = os.environ.get("PYTHONUSERBASE", None)
+
def joinuser(*args):
return os.path.expanduser(os.path.join(*args))
@@ -157,7 +165,6 @@
optional dictionary is passed in as the second argument, it is
used instead of a new dictionary.
"""
- import re
# Regexes needed for parsing Makefile (and similar syntaxes,
# like old-style Setup files).
_variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
@@ -255,7 +262,6 @@
if name not in done:
done[name] = value
-
else:
# bogus variable reference; just drop it since we can't deal
variables.remove(name)
@@ -315,6 +321,7 @@
if _PYTHON_BUILD:
vars['LDSHARED'] = vars['BLDSHARED']
+
def _init_non_posix(vars):
"""Initialize the module as appropriate for NT"""
# set basic install directories
@@ -338,7 +345,6 @@
optional dictionary is passed in as the second argument, it is
used instead of a new dictionary.
"""
- import re
if vars is None:
vars = {}
define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
@@ -351,8 +357,10 @@
m = define_rx.match(line)
if m:
n, v = m.group(1, 2)
- try: v = int(v)
- except ValueError: pass
+ try:
+ v = int(v)
+ except ValueError:
+ pass
vars[n] = v
else:
m = undef_rx.match(line)
@@ -360,6 +368,7 @@
vars[m.group(1)] = 0
return vars
+
def get_config_h_filename():
"""Return the path of pyconfig.h."""
if _PYTHON_BUILD:
@@ -371,15 +380,18 @@
inc_dir = get_path('platinclude')
return os.path.join(inc_dir, 'pyconfig.h')
+
def get_scheme_names():
"""Return a tuple containing the schemes names."""
return tuple(sorted(_SCHEMES.sections()))
+
def get_path_names():
"""Return a tuple containing the paths names."""
# xxx see if we want a static list
return _SCHEMES.options('posix_prefix')
+
def get_paths(scheme=_get_default_scheme(), vars=None, expand=True):
"""Return a mapping containing an install scheme.
@@ -391,6 +403,7 @@
else:
return dict(_SCHEMES.items(scheme))
+
def get_path(name, scheme=_get_default_scheme(), vars=None, expand=True):
"""Return a path corresponding to the scheme.
@@ -398,6 +411,7 @@
"""
return get_paths(scheme, vars, expand)[name]
+
def get_config_vars(*args):
"""With no arguments, return a dictionary of all configuration
variables relevant for the current platform.
@@ -408,7 +422,6 @@
With arguments, return a list of values that result from looking up
each argument in the configuration variable dictionary.
"""
- import re
global _CONFIG_VARS
if _CONFIG_VARS is None:
_CONFIG_VARS = {}
@@ -440,7 +453,6 @@
else:
_CONFIG_VARS['srcdir'] = realpath(_CONFIG_VARS['srcdir'])
-
# 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
@@ -456,7 +468,7 @@
_CONFIG_VARS['srcdir'] = os.path.normpath(srcdir)
if sys.platform == 'darwin':
- kernel_version = os.uname()[2] # Kernel version (8.4.3)
+ kernel_version = os.uname()[2] # Kernel version (8.4.3)
major_version = int(kernel_version.split('.')[0])
if major_version < 8:
@@ -522,6 +534,7 @@
else:
return _CONFIG_VARS
+
def get_config_var(name):
"""Return the value of a single variable using the dictionary returned by
'get_config_vars()'.
@@ -530,6 +543,7 @@
"""
return get_config_vars().get(name)
+
def get_platform():
"""Return a string that identifies the current platform.
@@ -555,7 +569,6 @@
For other non-POSIX platforms, currently just returns 'sys.platform'.
"""
- import re
if os.name == 'nt':
# sniff sys.version for architecture.
prefix = " bit ("
@@ -563,7 +576,7 @@
if i == -1:
return sys.platform
j = sys.version.find(")", i)
- look = sys.version[i+len(prefix):j].lower()
+ look = sys.version[i + len(prefix):j].lower()
if look == 'amd64':
return 'win-amd64'
if look == 'itanium':
@@ -600,7 +613,7 @@
return "%s-%s.%s" % (osname, version, release)
elif osname[:6] == "cygwin":
osname = "cygwin"
- rel_re = re.compile (r'[\d.]+')
+ rel_re = re.compile(r'[\d.]+')
m = rel_re.match(release)
if m:
release = m.group()
@@ -675,19 +688,19 @@
machine = 'universal'
else:
raise ValueError(
- "Don't know machine value for archs=%r"%(archs,))
+ "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:
+ if sys.maxint >= (2 ** 32):
machine = 'x86_64'
elif machine in ('PowerPC', 'Power_Macintosh'):
# Pick a sane name for the PPC architecture.
# See 'i386' case
- if sys.maxint >= 2**32:
+ if sys.maxint >= (2 ** 32):
machine = 'ppc64'
else:
machine = 'ppc'
@@ -698,12 +711,14 @@
def get_python_version():
return _PY_VERSION_SHORT
+
def _print_dict(title, data):
for index, (key, value) in enumerate(sorted(data.items())):
if index == 0:
print '%s: ' % (title)
print '\t%s = "%s"' % (key, value)
+
def _main():
"""Display all information sysconfig detains."""
print 'Platform: "%s"' % get_platform()
@@ -714,5 +729,6 @@
print
_print_dict('Variables', get_config_vars())
+
if __name__ == '__main__':
_main()
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list