本文整理汇总了Python中sysconfig.get_config_var函数的典型用法代码示例。如果您正苦于以下问题:Python get_config_var函数的具体用法?Python get_config_var怎么用?Python get_config_var使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_config_var函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_getsitepackages
def test_getsitepackages(self):
site.PREFIXES = ['xoxo']
dirs = site.getsitepackages()
if (sys.platform == "darwin" and
sysconfig.get_config_var("PYTHONFRAMEWORK")):
# OS X framework builds
site.PREFIXES = ['Python.framework']
dirs = site.getsitepackages()
self.assertEqual(len(dirs), 2)
wanted = os.path.join('/Library',
sysconfig.get_config_var("PYTHONFRAMEWORK"),
'%d.%d' % sys.version_info[:2],
'site-packages')
self.assertEqual(dirs[1], wanted)
elif os.sep == '/':
# OS X non-framwework builds, Linux, FreeBSD, etc
self.assertEqual(len(dirs), 1)
wanted = os.path.join('xoxo', 'lib',
'python%d.%d' % sys.version_info[:2],
'site-packages')
self.assertEqual(dirs[0], wanted)
else:
# other platforms
self.assertEqual(len(dirs), 2)
self.assertEqual(dirs[0], 'xoxo')
wanted = os.path.join('xoxo', 'lib', 'site-packages')
self.assertEqual(dirs[1], wanted)
示例2: copy_python_lib
def copy_python_lib(dest):
files = []
if sys.platform == 'win32':
dllname = "python%s%s.dll" % sys.version_info[:2]
# two location to try
system32path = os.path.join("C:\\", "Windows", "System32")
syswow64path = os.path.join("C:\\", "Windows", "SysWOW64")
files.append(os.path.join(system32path, dllname))
if "64" in platform.machine() and "64" in platform.architecture()[0]:
files.append(os.path.join(syswow64path, dllname))
elif sys.platform == 'linux':
libname = sysconfig.get_config_var("INSTSONAME")
libdir = sysconfig.get_config_var(
'LIBDIR') + (sysconfig.get_config_var("multiarchsubdir") or "")
files.append(os.path.join(libdir, libname))
else:
# osx
pass
dest_folder = os.path.abspath(dest)
for path in files:
if os.path.exists(path):
fil = os.path.basename(path)
root, ext = os.path.splitext(fil)
to = os.path.join(dest_folder, fil)
copy_file(path, to)
示例3: sysconfig2
def sysconfig2():
# import sysconfig module - Provide access to Python’s configuration information
import sysconfig
# returns an installation path corresponding to the path name
print("Path Name : ", sysconfig.get_path("stdlib"))
print()
# returns a string that identifies the current platform.
print("Current Platform : ", sysconfig.get_platform())
print()
# returns the MAJOR.MINOR Python version number as a string
print("Python Version Number : ", sysconfig.get_python_version())
print()
# returns a tuple containing all path names
print("Path Names : ", sysconfig.get_path_names())
print()
# returns a tuple containing all schemes
print("Scheme Names : ", sysconfig.get_scheme_names())
print()
# returns the value of a single variable name.
print("Variable name LIBDIR : ", sysconfig.get_config_var('LIBDIR'))
# returns the value of a single variable name.
print("Variable name LIBDEST : ", sysconfig.get_config_var('LIBDEST'))
示例4: main
def main():
"""Command line utility to retrieve compilation options for python modules'
"""
parser = argparse.ArgumentParser(
description='Retrieves compilation options for python modules.')
parser.add_argument('--libraries', help='Returns libraries',
action='store_true')
parser.add_argument('--includes', help='Returns includes',
action='store_true')
parser.add_argument('--library_dirs', help='Returns library_dirs',
action='store_true')
opts = parser.parse_args()
result = []
if opts.libraries:
python_lib = sysconfig.get_config_var('LDLIBRARY')
if python_lib.endswith(".so"):
python_lib = python_lib[:-3]
if python_lib.startswith("lib"):
python_lib = python_lib[3:]
result.append(python_lib)
if opts.includes:
result.append(sysconfig.get_config_var('INCLUDEPY'))
if opts.library_dirs:
result.append(sysconfig.get_config_var('BINLIBDEST'))
for x in result:
print x
示例5: fixup_build_ext
def fixup_build_ext(cmd):
"""Function needed to make build_ext tests pass.
When Python was build with --enable-shared on Unix, -L. is not good
enough to find the libpython<blah>.so. This is because regrtest runs
it under a tempdir, not in the top level where the .so lives. By the
time we've gotten here, Python's already been chdir'd to the tempdir.
When Python was built with in debug mode on Windows, build_ext commands
need their debug attribute set, and it is not done automatically for
some reason.
This function handles both of these things. Example use:
cmd = build_ext(dist)
support.fixup_build_ext(cmd)
cmd.ensure_finalized()
Unlike most other Unix platforms, Mac OS X embeds absolute paths
to shared libraries into executables, so the fixup is not needed there.
"""
if os.name == 'nt':
cmd.debug = sys.executable.endswith('_d.exe')
elif sysconfig.get_config_var('Py_ENABLE_SHARED'):
runshared = sysconfig.get_config_var('RUNSHARED')
if runshared is None:
cmd.library_dirs = ['.']
elif sys.platform == 'darwin':
cmd.library_dirs = []
else:
name, equals, value = runshared.partition('=')
cmd.library_dirs = [ d for d in value.split(os.pathsep) if d ]
return
示例6: get_enable_shared
def get_enable_shared():
if WIN32:
return True
from sysconfig import get_config_var
if LINUX:
return get_config_var('Py_ENABLE_SHARED')
if which('pkg-config') is None:
exit(f'pkg-config is required and not found in path. Link to install: {LINK}')
lib = '/Library/Frameworks/Mono.framework/Versions/Current/lib'
# Create a symlink of framework lib/mono to python lib/mono
dst = os.path.join(os.path.dirname(sys.executable)[:-3] + 'lib', 'mono')
if os.path.exists(dst): os.remove(dst)
os.symlink(os.path.join(lib, 'mono'), dst)
paths = [path for path, dirs, files in os.walk(lib) if 'mono-2.pc' in files]
os.environ['PKG_CONFIG_PATH'] = ':'.join(paths)
if len(paths) == 0:
exit(f'Could not find "mono-2.pc" in "{lib}" tree.')
return get_config_var('Py_ENABLE_SHARED')
示例7: test_srcdir_independent_of_cwd
def test_srcdir_independent_of_cwd(self):
# srcdir should be independent of the current working directory
# See Issues #15322, #15364.
srcdir = sysconfig.get_config_var('srcdir')
with change_cwd(os.pardir):
srcdir2 = sysconfig.get_config_var('srcdir')
self.assertEqual(srcdir, srcdir2)
示例8: copy_embeddable_python_dylib
def copy_embeddable_python_dylib(dst):
runtime = op.join(sysconfig.get_config_var('PYTHONFRAMEWORKPREFIX'), sysconfig.get_config_var('LDLIBRARY'))
filedest = op.join(dst, 'Python')
shutil.copy(runtime, filedest)
os.chmod(filedest, 0o774) # We need write permission to use install_name_tool
cmd = 'install_name_tool -id @rpath/Python %s' % filedest
print_and_do(cmd)
示例9: candidate_names
def candidate_names(suffix=SHLIB_SUFFIX):
"""
Iterate over candidate file names of libpython.
Yields
------
name : str
Candidate name libpython.
"""
LDLIBRARY = sysconfig.get_config_var("LDLIBRARY")
if LDLIBRARY:
yield LDLIBRARY
LIBRARY = sysconfig.get_config_var("LIBRARY")
if LIBRARY:
yield os.path.splitext(LIBRARY)[0] + suffix
dlprefix = "" if is_windows else "lib"
sysdata = dict(
v=sys.version_info,
# VERSION is X.Y in Linux/macOS and XY in Windows:
VERSION=(sysconfig.get_config_var("VERSION") or
"{v.major}.{v.minor}".format(v=sys.version_info)),
ABIFLAGS=(sysconfig.get_config_var("ABIFLAGS") or
sysconfig.get_config_var("abiflags") or ""),
)
for stem in [
"python{VERSION}{ABIFLAGS}".format(**sysdata),
"python{VERSION}".format(**sysdata),
"python{v.major}".format(**sysdata),
"python",
]:
yield dlprefix + stem + suffix
示例10: so_path
def so_path(dir, filename):
'''http://www.python.org/dev/peps/pep-3149/'''
suffix = sysconfig.get_config_var('SO')
if not suffix:
soabi = sysconfig.get_config_var('SOABI')
suffix = ".{}.so".format(soabi)
return os.path.join(dir, filename + suffix)
示例11: test_cpython_abi_py2
def test_cpython_abi_py2(debug, pymalloc, unicode_width, monkeypatch):
has_soabi = sysconfig.get_config_var("SOABI")
if platform.python_implementation() != "CPython" or has_soabi:
diff_debug = debug != sysconfig.get_config_var("Py_DEBUG")
diff_malloc = pymalloc != sysconfig.get_config_var("WITH_PYMALLOC")
unicode_size = sysconfig.get_config_var("Py_UNICODE_SIZE")
diff_unicode_size = unicode_size != unicode_width
if diff_debug or diff_malloc or diff_unicode_size:
config_vars = {
"SOABI": None,
"Py_DEBUG": int(debug),
"WITH_PYMALLOC": int(pymalloc),
"Py_UNICODE_SIZE": unicode_width,
}
monkeypatch.setattr(sysconfig, "get_config_var", config_vars.__getitem__)
else:
config_vars = {
"SOABI": None,
"Py_DEBUG": int(debug),
"WITH_PYMALLOC": int(pymalloc),
"Py_UNICODE_SIZE": unicode_width,
}
monkeypatch.setattr(sysconfig, "get_config_var", config_vars.__getitem__)
options = ""
if debug:
options += "d"
if pymalloc:
options += "m"
if unicode_width == 4:
options += "u"
assert "cp33{}".format(options) == tags._cpython_abi((3, 3))
示例12: _find_libpy3_windows
def _find_libpy3_windows(self, env):
'''
Find python3 libraries on Windows and also verify that the arch matches
what we are building for.
'''
pyarch = sysconfig.get_platform()
arch = detect_cpu_family(env.coredata.compilers)
if arch == 'x86':
arch = '32'
elif arch == 'x86_64':
arch = '64'
else:
# We can't cross-compile Python 3 dependencies on Windows yet
mlog.log('Unknown architecture {!r} for'.format(arch),
mlog.bold(self.name))
self.is_found = False
return
# Pyarch ends in '32' or '64'
if arch != pyarch[-2:]:
mlog.log('Need', mlog.bold(self.name),
'for {}-bit, but found {}-bit'.format(arch, pyarch[-2:]))
self.is_found = False
return
inc = sysconfig.get_path('include')
platinc = sysconfig.get_path('platinclude')
self.compile_args = ['-I' + inc]
if inc != platinc:
self.compile_args.append('-I' + platinc)
# Nothing exposes this directly that I coulf find
basedir = sysconfig.get_config_var('base')
vernum = sysconfig.get_config_var('py_version_nodot')
self.link_args = ['-L{}/libs'.format(basedir),
'-lpython{}'.format(vernum)]
self.version = sysconfig.get_config_var('py_version_short')
self.is_found = True
示例13: load_lib
def load_lib():
"""Find and load libspacepy
Normally this will be in the directory where spacepy is installed,
under libspacepy.
@return: the open library
@rtype: ctypes.CDLL or ctypes.WinDLL
"""
libdir = os.path.dirname(os.path.abspath(__file__))
if sys.platform == 'win32':
libnames = ['spacepy.dll']
elif sys.platform == 'darwin':
libnames = ['libspacepy.dylib', 'libspacepy.so',
'spacepy.dylib', 'spacepy.so']
else:
libnames = ['libspacepy.so']
if sysconfig:
ext = sysconfig.get_config_var('EXT_SUFFIX')
if ext is None:
ext = sysconfig.get_config_var('SO')
if ext:
libnames.append('libspacepy' + ext)
libnames.append('spacepy' + ext)
libpath = None
for n in libnames:
libpath = os.path.join(libdir, n)
if os.path.exists(libpath):
break
if libpath and os.path.exists(libpath):
return ctypes.CDLL(libpath)
else:
return None
示例14: fixup_build_ext
def fixup_build_ext(cmd):
"""Function needed to make build_ext tests pass.
When Python was build with --enable-shared on Unix, -L. is not good
enough to find the libpython<blah>.so. This is because regrtest runs
it under a tempdir, not in the top level where the .so lives. By the
time we've gotten here, Python's already been chdir'd to the tempdir.
When Python was built with in debug mode on Windows, build_ext commands
need their debug attribute set, and it is not done automatically for
some reason.
This function handles both of these things. Example use:
cmd = build_ext(dist)
support.fixup_build_ext(cmd)
cmd.ensure_finalized()
"""
if os.name == 'nt':
cmd.debug = sys.executable.endswith('_d.exe')
elif sysconfig.get_config_var('Py_ENABLE_SHARED'):
# To further add to the shared builds fun on Unix, we can't just add
# library_dirs to the Extension() instance because that doesn't get
# plumbed through to the final compiler command.
runshared = sysconfig.get_config_var('RUNSHARED')
if runshared is None:
cmd.library_dirs = ['.']
else:
name, equals, value = runshared.partition('=')
cmd.library_dirs = value.split(os.pathsep)
示例15: get_build_cflags
def get_build_cflags():
"""Synthesize a CFLAGS env var from the current python env for building of C modules."""
return '{} {} -I{}'.format(
sysconfig.get_config_var('BASECFLAGS'),
sysconfig.get_config_var('OPT'),
sysconfig.get_path('include')
)