本文整理汇总了Python中sysconfig.get_config_vars函数的典型用法代码示例。如果您正苦于以下问题:Python get_config_vars函数的具体用法?Python get_config_vars怎么用?Python get_config_vars使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_config_vars函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: python_is_optimized
def python_is_optimized():
cflags = sysconfig.get_config_vars()['PY_CFLAGS']
final_opt = ""
for opt in cflags.split():
if opt.startswith('-O'):
final_opt = opt
return (final_opt and final_opt != '-O0')
示例2: python_is_optimized
def python_is_optimized():
cflags = sysconfig.get_config_vars()["PY_CFLAGS"]
final_opt = ""
for opt in cflags.split():
if opt.startswith("-O"):
final_opt = opt
return final_opt not in ("", "-O0", "-Og")
示例3: get_tag
def get_tag(self):
supported_tags = pep425tags.get_supported()
purity = self.distribution.is_pure()
impl_ver = get_impl_ver()
abi_tag = 'none'
plat_name = 'any'
impl_name = 'py'
if purity:
wheel = self.distribution.get_option_dict('wheel')
if 'universal' in wheel:
# please don't define this in your global configs
val = wheel['universal'][1].strip()
if val.lower() in ('1', 'true', 'yes'):
impl_name = 'py2.py3'
impl_ver = ''
tag = (impl_name + impl_ver, abi_tag, plat_name)
else:
plat_name = self.plat_name
if plat_name is None:
plat_name = get_platform()
plat_name = plat_name.replace('-', '_').replace('.', '_')
impl_name = get_abbr_impl()
# PEP 3149 -- no SOABI in Py 2
# For PyPy?
# "pp%s%s" % (sys.pypy_version_info.major,
# sys.pypy_version_info.minor)
abi_tag = sysconfig.get_config_vars().get('SOABI', abi_tag)
if abi_tag.startswith('cpython-'):
abi_tag = 'cp' + abi_tag.rsplit('-', 1)[-1]
tag = (impl_name + impl_ver, abi_tag, plat_name)
# XXX switch to this alternate implementation for non-pure:
assert tag == supported_tags[0]
return tag
示例4: test_version_int
def test_version_int(self):
source = self.mkdtemp()
target = self.mkdtemp()
expected = self.write_sample_scripts(source)
cmd = self.get_build_scripts_cmd(target,
[os.path.join(source, fn)
for fn in expected])
cmd.finalize_options()
# http://bugs.python.org/issue4524
#
# On linux-g++-32 with command line `./configure --enable-ipv6
# --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
try:
cmd.run()
finally:
if old is not None:
sysconfig._CONFIG_VARS['VERSION'] = old
built = os.listdir(target)
for name in expected:
self.assertTrue(name in built)
示例5: get_tag
def get_tag(self):
supported_tags = pep425tags.get_supported()
if self.distribution.is_pure():
if self.universal:
impl = 'py2.py3'
else:
impl = self.python_tag
tag = (impl, 'none', 'any')
else:
plat_name = self.plat_name
if plat_name is None:
plat_name = get_platform()
plat_name = plat_name.replace('-', '_').replace('.', '_')
impl_name = get_abbr_impl()
impl_ver = get_impl_ver()
# PEP 3149 -- no SOABI in Py 2
# For PyPy?
# "pp%s%s" % (sys.pypy_version_info.major,
# sys.pypy_version_info.minor)
abi_tag = sysconfig.get_config_vars().get('SOABI', 'none')
if abi_tag.startswith('cpython-'):
abi_tag = 'cp' + abi_tag.rsplit('-', 1)[-1]
tag = (impl_name + impl_ver, abi_tag, plat_name)
# XXX switch to this alternate implementation for non-pure:
assert tag == supported_tags[0]
return tag
示例6: test_main
def test_main():
cflags = sysconfig.get_config_vars()["PY_CFLAGS"]
final_opt = ""
for opt in cflags.split():
if opt.startswith("-O"):
final_opt = opt
if final_opt and final_opt != "-O0":
raise unittest.SkipTest("Python was built with compiler optimizations, " "tests can't reliably succeed")
run_unittest(PrettyPrintTests, PyListTests, StackNavigationTests, PyBtTests, PyPrintTests, PyLocalsTests)
示例7: customize_compiler
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:
if ar_flags is not None:
archiver = ar + ' ' + ar_flags
else:
# see if its the proper default value
# mmm I don't want to backport the makefile
archiver = ar + ' rc'
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
示例8: get_context
def get_context(self):
ret = {}
try:
ret['sysconfig'] = sysconfig.get_config_vars()
except:
pass
try:
ret['paths'] = sysconfig.get_paths()
except:
pass
return ret
示例9: build_extensions
def build_extensions(self):
if sys.platform.startswith("linux"):
# Allow a custom C compiler through the environment variables. This
# allows Komodo to build using a gcc compiler that's not first on
# the path.
compiler = os.environ.get('CC')
if compiler is not None:
import sysconfig
(ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS')
args = {}
args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags
self.compiler.set_executables(**args)
elif sys.platform == "darwin":
compiler = os.environ.get('CC')
if compiler is not None:
import sysconfig
(ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS')
args = {}
# clang does not support the '-std=gnu99' option - so remove it.
cflags = cflags.replace('-std=gnu99', '')
args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags
self.compiler.set_executables(**args)
build_ext.build_extensions(self)
示例10: run
def run(args):
assert len(args) == 0
import_modules()
import time
t_start = time.time()
from libtbx import introspection
import os
import sysconfig
print "After script imports:"
print " wall clock time: %.2f" % (time.time() - t_start)
print
mb = 1024 * 1024
lib = os.path.join(
os.environ["LIBTBX_BUILD"], # intentionally not using libtbx.env for speed
"lib")
ext_so = []
for node in os.listdir(lib):
pylibext = sysconfig.get_config_vars("SO")[0]
if (node.endswith("_ext" + pylibext)):
ext_so.append(node.split(".")[0])
ext_so.sort(cmp_so)
print "Before importing extensions:"
vmi = introspection.virtual_memory_info()
vmi.show(prefix=" ")
prev_vms = vmi.get_bytes('VmSize:')
prev_rss = vmi.get_bytes('VmRSS:')
print " wall clock time: %.2f" % (time.time() - t_start)
print
for so in ext_so:
t0 = time.time()
exec("import %s" % so)
vmi = introspection.virtual_memory_info()
vms = vmi.get_bytes('VmSize:')
rss = vmi.get_bytes('VmRSS:')
if (vms is not None) : # won't work on Mac
print "%.2f %3.0f %3.0f %s" % (
time.time()-t0, (vms-prev_vms)/mb, (rss-prev_rss)/mb, so)
else :
assert (sys.platform in ["darwin", "win32"])
print "%.2f %s" % (time.time()-t0, so)
prev_vms = vms
prev_rss = rss
print
print "After importing all extensions:"
introspection.virtual_memory_info().show(prefix=" ")
print " wall clock time: %.2f" % (time.time() - t_start)
print
示例11: find_boost_cflags
def find_boost_cflags():
# Get Boost dir (code copied from ufc/src/utils/python/ufc_utils/build.py)
# Set a default directory for the boost installation
if sys.platform == "darwin":
# Use Brew as default
default = os.path.join(os.path.sep, "usr", "local")
else:
default = os.path.join(os.path.sep, "usr")
# If BOOST_DIR is not set use default directory
boost_inc_dir = ""
boost_lib_dir = ""
boost_math_tr1_lib = "boost_math_tr1"
boost_dir = os.getenv("BOOST_DIR", default)
boost_is_found = False
for inc_dir in ["", "include"]:
if os.path.isfile(os.path.join(boost_dir, inc_dir, "boost",
"version.hpp")):
boost_inc_dir = os.path.join(boost_dir, inc_dir)
break
libdir_multiarch = "lib/" + sysconfig.get_config_vars().get("MULTIARCH", "")
for lib_dir in ["", "lib", libdir_multiarch, "lib64"]:
for ext in [".so", "-mt.so", ".dylib", "-mt.dylib"]:
_lib = os.path.join(boost_dir, lib_dir, "lib" + boost_math_tr1_lib
+ ext)
if os.path.isfile(_lib):
if "-mt" in _lib:
boost_math_tr1_lib += "-mt"
boost_lib_dir = os.path.join(boost_dir, lib_dir)
break
if boost_inc_dir != "" and boost_lib_dir != "":
boost_is_found = True
if boost_is_found:
boost_cflags = " -I%s -L%s" % (boost_inc_dir, boost_lib_dir)
boost_linkflags = "-l%s" % boost_math_tr1_lib
else:
boost_cflags = ""
boost_linkflags = ""
info_red("""The Boost library was not found.
If Boost is installed in a nonstandard location,
set the environment variable BOOST_DIR.
Forms using bessel functions will fail to build.
""")
return boost_cflags, boost_linkflags
示例12: test_version_int
def test_version_int(self):
source = self.mkdtemp()
target = self.mkdtemp()
expected = self.write_sample_scripts(source)
cmd = self.get_build_scripts_cmd(target, [os.path.join(source, fn) for fn in expected])
cmd.finalize_options()
old = sysconfig.get_config_vars().get("VERSION")
sysconfig._CONFIG_VARS["VERSION"] = 4
try:
cmd.run()
finally:
if old is not None:
sysconfig._CONFIG_VARS["VERSION"] = old
built = os.listdir(target)
for name in expected:
self.assertIn(name, built)
return
示例13: get_python_dynlib
def get_python_dynlib():
"""
python -c "import utool; print(utool.get_python_dynlib())"
get_python_dynlib
Returns:
?: dynlib
Example:
>>> # DOCTEST_DISABLE
>>> from utool.util_cplat import * # NOQA
>>> dynlib = get_python_dynlib()
>>> print(dynlib)
/usr/lib/x86_64-linux-gnu/libpython2.7.so
"""
import sysconfig
cfgvars = sysconfig.get_config_vars()
dynlib = os.path.join(cfgvars['LIBDIR'], cfgvars['MULTIARCH'], cfgvars['LDLIBRARY'])
if not exists(dynlib):
dynlib = os.path.join(cfgvars['LIBDIR'], cfgvars['LDLIBRARY'])
assert exists(dynlib)
return dynlib
示例14: test_ext_fullpath
def test_ext_fullpath(self):
ext = sysconfig.get_config_vars()['SO']
# building lxml.etree inplace
#etree_c = os.path.join(self.tmp_dir, 'lxml.etree.c')
#etree_ext = Extension('lxml.etree', [etree_c])
#dist = Distribution({'name': 'lxml', 'ext_modules': [etree_ext]})
dist = Distribution()
cmd = build_ext(dist)
cmd.inplace = True
cmd.distribution.package_dir = 'src'
cmd.distribution.packages = ['lxml', 'lxml.html']
curdir = os.getcwd()
wanted = os.path.join(curdir, 'src', 'lxml', 'etree' + ext)
path = cmd.get_ext_fullpath('lxml.etree')
self.assertEqual(wanted, path)
# building lxml.etree not inplace
cmd.inplace = False
cmd.build_lib = os.path.join(curdir, 'tmpdir')
wanted = os.path.join(curdir, 'tmpdir', 'lxml', 'etree' + ext)
path = cmd.get_ext_fullpath('lxml.etree')
self.assertEqual(wanted, path)
# building twisted.runner.portmap not inplace
build_py = cmd.get_finalized_command('build_py')
build_py.package_dir = None
cmd.distribution.packages = ['twisted', 'twisted.runner.portmap']
path = cmd.get_ext_fullpath('twisted.runner.portmap')
wanted = os.path.join(curdir, 'tmpdir', 'twisted', 'runner',
'portmap' + ext)
self.assertEqual(wanted, path)
# building twisted.runner.portmap inplace
cmd.inplace = True
path = cmd.get_ext_fullpath('twisted.runner.portmap')
wanted = os.path.join(curdir, 'twisted', 'runner', 'portmap' + ext)
self.assertEqual(wanted, path)
示例15: hasattr
import unittest
from attic.helpers import st_mtime_ns
from attic.xattr import get_all
try:
import llfuse
# Does this version of llfuse support ns precision?
have_fuse_mtime_ns = hasattr(llfuse.EntryAttributes, 'st_mtime_ns')
except ImportError:
have_fuse_mtime_ns = False
# The mtime get/set precison varies on different OS and Python versions
if 'HAVE_FUTIMENS' in getattr(posix, '_have_functions', []):
st_mtime_ns_round = 0
elif 'HAVE_UTIMES' in sysconfig.get_config_vars():
st_mtime_ns_round = -6
else:
st_mtime_ns_round = -9
has_mtime_ns = sys.version >= '3.3'
utime_supports_fd = os.utime in getattr(os, 'supports_fd', {})
class AtticTestCase(unittest.TestCase):
"""
"""
assert_in = unittest.TestCase.assertIn
assert_not_in = unittest.TestCase.assertNotIn
assert_equal = unittest.TestCase.assertEqual