示例#1
0
def find_queries_path():
    possible_paths = []
    # Try all possible schemes where python expects data to stay.
    for scheme in sysconfig.get_scheme_names():
        default_path = sysconfig.get_path(name='data', scheme=scheme)
        possible_paths.append(os.path.join(default_path, 'tract_querier', 'queries'))

    # Try to manage Virtual Environments on some OSes,
    # where data is not put the 'local' subdirectory,
    # but at the root of the virtual environment.
    if default_path.endswith('local'):
        possible_paths.append(os.path.join(default_path.rsplit('local', 1)[0],
                                           'tract_querier', 'queries'))

    # Case where the Tract_querier is cloned from git and simply
    # added to the python path, without installation.
    possible_paths.append(os.path.abspath(os.path.join(
                                          os.path.dirname(__file__), 'data')))

    paths_found = [path for path in possible_paths if os.path.exists(path)]

    if not paths_found:
        raise Exception('Default path for queries not found')

    return paths_found[0]
 def test_get_scheme_names(self):
     wanted = ['nt', 'nt_user', 'osx_framework_user',
               'posix_home', 'posix_prefix', 'posix_user']
     if sys.platform == 'uwp':
         wanted.extend(['uwp_os', 'uwp_os_user'])
     wanted = tuple(wanted)
     self.assertEqual(get_scheme_names(), wanted)
示例#3
0
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
0
def get_soabi():
    soabi = None
    try:
        soabi = sysconfig.get_config_var('SOABI')
        arch = sysconfig.get_config_var('MULTIARCH')
    except IOError:
        pass
    if soabi and arch and 'pypy' in sysconfig.get_scheme_names():
        soabi = '%s-%s' % (soabi, arch)
    if soabi is None and 'pypy' in sysconfig.get_scheme_names():
        # NOTE(sigmavirus24): PyPy only added support for the SOABI config var
        # to sysconfig in 2015. That was well after 2.2.1 was published in the
        # Ubuntu 14.04 archive.
        for suffix, _, _ in imp.get_suffixes():
            if suffix.startswith('.pypy') and suffix.endswith('.so'):
                soabi = suffix.split('.')[1]
                break
    return soabi
示例#5
0
文件: setup.py 项目: GNOME/pygobject
 def get_sys_path(location, name):
     # Returns the sysconfig path for a distribution, or None
     for scheme in sysconfig.get_scheme_names():
         for path_type in ["platlib", "purelib"]:
             path = sysconfig.get_path(path_type, scheme)
             try:
                 if samefile(path, location):
                     return sysconfig.get_path(name, scheme)
             except EnvironmentError:
                 pass
    def test_user_site(self):
        # test install with --user
        # preparing the environment for the test
        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')
        _CONFIG_VARS['userbase'] = self.user_base
        scheme = '%s_user' % os.name
        _SCHEMES.set(scheme, 'purelib', self.user_site)

        def _expanduser(path):
            if path[0] == '~':
                path = os.path.normpath(self.tmpdir) + path[1:]
            return path

        self.old_expand = os.path.expanduser
        os.path.expanduser = _expanduser

        def cleanup():
            _CONFIG_VARS['userbase'] = self.old_user_base
            _SCHEMES.set(scheme, 'purelib', self.old_user_site)
            os.path.expanduser = self.old_expand

        self.addCleanup(cleanup)

        schemes = get_scheme_names()
        for key in ('nt_user', 'posix_user', 'os2_home'):
            self.assertIn(key, schemes)

        dist = Distribution({'name': 'xx'})
        cmd = install_dist(dist)

        # making sure the user option is there
        options = [name for name, short, lable in
                   cmd.user_options]
        self.assertIn('user', options)

        # setting a value
        cmd.user = True

        # user base and site shouldn't be created yet
        self.assertFalse(os.path.exists(self.user_base))
        self.assertFalse(os.path.exists(self.user_site))

        # let's run finalize
        cmd.ensure_finalized()

        # now they should
        self.assertTrue(os.path.exists(self.user_base))
        self.assertTrue(os.path.exists(self.user_site))

        self.assertIn('userbase', cmd.config_vars)
        self.assertIn('usersite', cmd.config_vars)
示例#7
0
 def test_get_scheme_names(self):
     wanted = (
         "nt",
         "nt_user",
         "os2",
         "os2_home",
         "osx_framework_user",
         "posix_home",
         "posix_prefix",
         "posix_user",
         "pypy",
     )
     self.assertEqual(get_scheme_names(), wanted)
def get_soabi():
    try:
        return sysconfig.get_config_var('SOABI')
    except IOError:
        pass

    if 'pypy' in sysconfig.get_scheme_names():
        # NOTE(sigmavirus24): PyPy only added support for the SOABI config var
        # to sysconfig in 2015. That was well after 2.2.1 was published in the
        # Ubuntu 14.04 archive.
        for suffix, _, _ in imp.get_suffixes():
            if suffix.startswith('.pypy') and suffix.endswith('.so'):
                return suffix.split('.')[1]
    return None
示例#9
0
def get_soabi():
    soabi = None
    try:
        soabi = sysconfig.get_config_var("SOABI")
    except IOError:
        pass
    if soabi is None and "pypy" in sysconfig.get_scheme_names():
        # NOTE(sigmavirus24): PyPy only added support for the SOABI config var
        # to sysconfig in 2015. That was well after 2.2.1 was published in the
        # Ubuntu 14.04 archive.
        for suffix, _, _ in imp.get_suffixes():
            if suffix.startswith(".pypy") and suffix.endswith(".so"):
                soabi = suffix.split(".")[1]
                break
    return soabi
示例#10
0
def setup_data_path():
    global data_path
    share = os.path.join('share', 'pcbdraw')
    entries = len(data_path)
    scheme_names = sysconfig.get_scheme_names()
    if os.name == 'posix':
        if 'posix_user' in scheme_names:
            data_path.append(
                os.path.join(sysconfig.get_path('data', 'posix_user'), share))
        if 'posix_prefix' in scheme_names:
            data_path.append(
                os.path.join(sysconfig.get_path('data', 'posix_prefix'),
                             share))
    elif os.name == 'nt':
        if 'nt_user' in scheme_names:
            data_path.append(
                os.path.join(sysconfig.get_path('data', 'nt_user'), share))
        if 'nt' in scheme_names:
            data_path.append(
                os.path.join(sysconfig.get_path('data', 'nt'), share))
    if len(data_path) == entries:
        data_path.append(os.path.join(sysconfig.get_path('data'), share))
示例#11
0
def _find_executable_and_scripts(path: str) -> Tuple[str, str, str]:
    """
    Detect the Python executable and script folder of a virtual environment.

    :param path: The location of the virtual environment
    :return: The Python executable, script folder, and purelib folder
    """
    config_vars = sysconfig.get_config_vars().copy(
    )  # globally cached, copy before altering it
    config_vars['base'] = path
    scheme_names = sysconfig.get_scheme_names()
    if 'venv' in scheme_names:
        # Python distributors with custom default installation scheme can set a
        # scheme that can't be used to expand the paths in a venv.
        # This can happen if build itself is not installed in a venv.
        # The distributors are encouraged to set a "venv" scheme to be used for this.
        # See https://bugs.python.org/issue45413
        # and https://github.com/pypa/virtualenv/issues/2208
        paths = sysconfig.get_paths(scheme='venv', vars=config_vars)
    elif 'osx_framework_library' in scheme_names:
        # The Python that ships with the macOS developer tools varies the
        # default scheme depending on whether the ``sys.prefix`` is part of a framework.
        # But it does not (yet) set the "venv" scheme.
        # If the Apple-custom "osx_framework_library" scheme is available but "venv"
        # is not, we use "posix_prefix" instead which is venv-compatible there.
        paths = sysconfig.get_paths(scheme='posix_prefix', vars=config_vars)
    else:
        paths = sysconfig.get_paths(vars=config_vars)
    executable = os.path.join(
        paths['scripts'],
        'python.exe' if sys.platform.startswith('win') else 'python')
    if not os.path.exists(executable):
        raise RuntimeError(
            f'Virtual environment creation failed, executable {executable} missing'
        )

    return executable, paths['scripts'], paths['purelib']
 def test_get_scheme_names(self):
     wanted = {'nt', 'nt_user', 'os2', 'os2_home', 'osx_framework_user',
               'posix_home', 'posix_prefix', 'posix_user', 'java',
               'java_user'}
     self.assertEqual({name for name in get_scheme_names()}, wanted)
示例#13
0
 def test_get_scheme_names(self):
     wanted = {
         'nt', 'nt_user', 'os2', 'os2_home', 'osx_framework_user',
         'posix_home', 'posix_prefix', 'posix_user', 'java', 'java_user'
     }
     self.assertEqual({name for name in get_scheme_names()}, wanted)
示例#14
0
import sys

import sysconfig

print('path names')
for path in sys.path:
    print(path)

print('Printing sysconfig scheme names line by line here')

for path in sysconfig.get_scheme_names():
    print(path)
# sysconfig.get_platform()
示例#15
0
def _load_sysconfig_schemes():
    with contextlib.suppress(AttributeError):
        return {
            scheme: sysconfig.get_paths(scheme, expand=False)
            for scheme in sysconfig.get_scheme_names()
        }
# coding=utf-8
# 使用sysconfig

import sysconfig

print sysconfig.get_config_var('Py_ENABLE_SHARED')
print sysconfig.get_config_var('LIBDIR')
print sysconfig.get_config_vars('AR', "CXX")


print sysconfig.get_scheme_names()
print sysconfig.get_path_names()

print sysconfig.get_python_version()
print sysconfig.get_platform()

# return true if current python installation was built from source
print sysconfig.is_python_build()

print sysconfig.get_config_h_filename()
print sysconfig._get_makefile_filename()
示例#17
0
from pip._internal.models.scheme import SCHEME_KEYS, Scheme
from pip._internal.utils.virtualenv import running_under_virtualenv

from .base import get_major_minor_version, is_osx_framework

logger = logging.getLogger(__name__)

# Notes on _infer_* functions.
# Unfortunately ``_get_default_scheme()`` is private, so there's no way to
# ask things like "what is the '_prefix' scheme on this platform". These
# functions try to answer that with some heuristics while accounting for ad-hoc
# platforms not covered by CPython's default sysconfig implementation. If the
# ad-hoc implementation does not fully implement sysconfig, we'll fall back to
# a POSIX scheme.

_AVAILABLE_SCHEMES = set(sysconfig.get_scheme_names())

_HAS_PREFERRED_SCHEME_API = sys.version_info >= (3, 10)


def _infer_prefix() -> str:
    """Try to find a prefix scheme for the current platform.

    This tries:

    * A special ``osx_framework_library`` for Python distributed by Apple's
      Command Line Tools, when not running in a virtual environment.
    * Implementation + OS, used by PyPy on Windows (``pypy_nt``).
    * Implementation without OS, used by PyPy on POSIX (``pypy``).
    * OS + "prefix", used by CPython on POSIX (``posix_prefix``).
    * Just the OS name, used by CPython on Windows (``nt``).
示例#18
0
 def test_get_scheme_names(self):
     wanted = ['nt', 'posix_home', 'posix_prefix']
     if HAS_USER_BASE:
         wanted.extend(['nt_user', 'osx_framework_user', 'posix_user'])
     self.assertEqual(get_scheme_names(), tuple(sorted(wanted)))
示例#19
0
文件: nodes.py 项目: xxoolm/Ryven
 def update_event(self, inp=-1):
     self.set_output_val(0, sysconfig.get_scheme_names())
示例#20
0
import collections
import os
import site
import stat
import sys
import sysconfig

SITE_PACKAGES_PATHS = set()
for scheme in sysconfig.get_scheme_names():
    if scheme == 'posix_home':
        # it would appear this scheme is not for site-packages
        continue
    for name in ['platlib', 'purelib']:
        try:
            SITE_PACKAGES_PATHS.add(sysconfig.get_path(name, scheme))
        except KeyError:
            pass
if hasattr(site, 'getusersitepackages'):
    SITE_PACKAGES_PATHS.add(site.getusersitepackages())
if sys.version_info < (3, 10):
    from distutils.sysconfig import get_python_lib

    SITE_PACKAGES_PATHS.add(get_python_lib())
SITE_PACKAGES_PATHS.add(os.path.dirname(os.path.dirname(__file__)))
SITE_PACKAGES_PATHS = tuple(SITE_PACKAGES_PATHS)

SYS_PREFIX_PATHS = {
    '<frozen zipimport>',
    '<frozen importlib._bootstrap>',
    '<frozen importlib._bootstrap_external>',
    sys.prefix,
示例#21
0
import sysconfig

# python -m sysconfig

print(sysconfig.get_config_var('Py_ENABLE_SHARED'))

print(sysconfig.get_config_var('LIBDIR'))

print(sysconfig.get_config_vars('posix_home', 'prefix'))

print(sysconfig.get_config_vars())

print(sysconfig.get_scheme_names())
"""
stdlib: directory containing the standard Python library files that are not platform-specific.
platstdlib: directory containing the standard Python library files that are platform-specific.
platlib: directory for site-specific, platform-specific files.
purelib: directory for site-specific, non-platform-specific files.
include: directory for non-platform-specific header files.
platinclude: directory for platform-specific header files.
scripts: directory for script files.
data: directory for data files.
"""
print(sysconfig.get_path_names())

print(sysconfig.get_path("data"))

print(sysconfig.get_paths("nt"))

print(sysconfig.get_python_version())
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann.  All rights reserved.
#
"""Installation schemes.
"""
# end_pymotw_header

import sysconfig

for name in sysconfig.get_scheme_names():
    print name
示例#23
0
 def _get_lib_dirs():
     schemes = sysconfig.get_scheme_names()
     names = ["stdlib", "platstdlib", "platlib", "purelib"]
     paths = {sysconfig.get_path(name, scheme) for scheme in schemes for name in names}
     return [os.path.abspath(path).lower() + os.sep for path in paths if path in sys.path]
示例#24
0
 def test_get_scheme_names(self):
     # XXX Graalpython change: add our scheme
     wanted = ('graalpy', 'nt', 'nt_user', 'osx_framework_user',
               'posix_home', 'posix_prefix', 'posix_user')
     self.assertEqual(get_scheme_names(), wanted)
示例#25
0
    def __init__(self):
        def u(v):
            return v.decode("utf-8") if isinstance(v, bytes) else v

        def abs_path(v):
            return None if v is None else os.path.abspath(
                v)  # unroll relative elements from path (e.g. ..)

        # qualifies the python
        self.platform = u(sys.platform)
        self.implementation = u(platform.python_implementation())
        if self.implementation == "PyPy":
            self.pypy_version_info = tuple(u(i) for i in sys.pypy_version_info)

        # this is a tuple in earlier, struct later, unify to our own named tuple
        self.version_info = VersionInfo(*list(u(i) for i in sys.version_info))
        self.architecture = 64 if sys.maxsize > 2**32 else 32

        # Used to determine some file names.
        # See `CPython3Windows.python_zip()`.
        self.version_nodot = sysconfig.get_config_var("py_version_nodot")

        self.version = u(sys.version)
        self.os = u(os.name)

        # information about the prefix - determines python home
        self.prefix = u(abs_path(getattr(sys, "prefix",
                                         None)))  # prefix we think
        self.base_prefix = u(abs_path(getattr(sys, "base_prefix",
                                              None)))  # venv
        self.real_prefix = u(abs_path(getattr(sys, "real_prefix",
                                              None)))  # old virtualenv

        # information about the exec prefix - dynamic stdlib modules
        self.base_exec_prefix = u(
            abs_path(getattr(sys, "base_exec_prefix", None)))
        self.exec_prefix = u(abs_path(getattr(sys, "exec_prefix", None)))

        self.executable = u(abs_path(
            sys.executable))  # the executable we were invoked via
        self.original_executable = u(abs_path(
            self.executable))  # the executable as known by the interpreter
        self.system_executable = self._fast_get_system_executable(
        )  # the executable we are based of (if available)

        try:
            __import__("venv")
            has = True
        except ImportError:
            has = False
        self.has_venv = has
        self.path = [u(i) for i in sys.path]
        self.file_system_encoding = u(sys.getfilesystemencoding())
        self.stdout_encoding = u(getattr(sys.stdout, "encoding", None))

        if "venv" in sysconfig.get_scheme_names():
            self.sysconfig_scheme = "venv"
            self.sysconfig_paths = {
                u(i): u(sysconfig.get_path(i, expand=False, scheme="venv"))
                for i in sysconfig.get_path_names()
            }
            # we cannot use distutils at all if "venv" exists, distutils don't know it
            self.distutils_install = {}
        else:
            self.sysconfig_scheme = None
            self.sysconfig_paths = {
                u(i): u(sysconfig.get_path(i, expand=False))
                for i in sysconfig.get_path_names()
            }
            self.distutils_install = {
                u(k): u(v)
                for k, v in self._distutils_install().items()
            }

        # https://bugs.python.org/issue22199
        makefile = getattr(sysconfig, "get_makefile_filename",
                           getattr(sysconfig, "_get_makefile_filename", None))
        self.sysconfig = {
            u(k): u(v)
            for k, v in [
                # a list of content to store from sysconfig
                ("makefile_filename", makefile()),
            ] if k is not None
        }

        config_var_keys = set()
        for element in self.sysconfig_paths.values():
            for k in _CONF_VAR_RE.findall(element):
                config_var_keys.add(u(k[1:-1]))
        config_var_keys.add("PYTHONFRAMEWORK")

        self.sysconfig_vars = {
            u(i): u(sysconfig.get_config_var(i) or "")
            for i in config_var_keys
        }
        if self.implementation == "PyPy" and sys.version_info.major == 2:
            self.sysconfig_vars["implementation_lower"] = "python"

        confs = {
            k: (self.system_prefix if v.startswith(self.prefix) else v)
            for k, v in self.sysconfig_vars.items()
        }
        self.system_stdlib = self.sysconfig_path("stdlib", confs)
        self.system_stdlib_platform = self.sysconfig_path("platstdlib", confs)
        self.max_size = getattr(sys, "maxsize", getattr(sys, "maxint", None))
        self._creators = None
示例#26
0
# coding=utf-8
# 使用sysconfig

import sysconfig

print sysconfig.get_config_var('Py_ENABLE_SHARED')
print sysconfig.get_config_var('LIBDIR')
print sysconfig.get_config_vars('AR', "CXX")

print sysconfig.get_scheme_names()
print sysconfig.get_path_names()

print sysconfig.get_python_version()
print sysconfig.get_platform()

# return true if current python installation was built from source
print sysconfig.is_python_build()

print sysconfig.get_config_h_filename()
print sysconfig._get_makefile_filename()
示例#27
0
 def test_get_scheme_names(self):
     wanted = ('nt', 'nt_user', 'os2', 'os2_home', 'osx_framework_user',
               'posix_home', 'posix_prefix', 'posix_user', 'pypy')
     self.assertEqual(get_scheme_names(), wanted)
#!/usr/bin/python
# 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 schemes
print("Scheme Names : ", sysconfig.get_scheme_names())
print()


示例#29
0
 def test_get_scheme_names(self):
     wanted = ('nt', 'nt_user', 'osx_framework_user', 'posix_home',
               'posix_prefix', 'posix_user')
     self.assertEqual(get_scheme_names(), wanted)
#!/usr/bin/python
# 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 schemes
print("Scheme Names : ", sysconfig.get_scheme_names())
print()