本文整理汇总了Python中site._init_pathinfo函数的典型用法代码示例。如果您正苦于以下问题:Python _init_pathinfo函数的具体用法?Python _init_pathinfo怎么用?Python _init_pathinfo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_init_pathinfo函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_init_pathinfo
def test_init_pathinfo(self):
dir_set = site._init_pathinfo()
for entry in [site.makepath(path)[1] for path in sys.path
if path and os.path.isdir(path)]:
self.assertIn(entry, dir_set,
"%s from sys.path not found in set returned "
"by _init_pathinfo(): %s" % (entry, dir_set))
示例2: _install_namespace_package
def _install_namespace_package(self, tmp_sitedir):
# Install our test namespace package in such a way that both py27 and
# py36 can find it.
from setuptools import namespaces
installer = namespaces.Installer()
class Distribution: namespace_packages = ['namespace_package']
installer.distribution = Distribution()
installer.target = os.path.join(tmp_sitedir, 'namespace_package.pth')
installer.outputs = []
installer.dry_run = False
installer.install_namespaces()
site.addsitedir(tmp_sitedir, known_paths=site._init_pathinfo())
示例3: addpackage
def addpackage(sitedir, name, known_paths, prepend_mode = False):
effective_known_paths = \
known_paths if known_paths is not None else _site._init_pathinfo()
fullname = os.path.join(sitedir, name)
# Figure out if we're dealing with a zip file.
archive_path, pth_file = split_zip_path(fullname)
archive = None
if not archive_path:
f = open(pth_file, mode)
else:
archive = zipfile.ZipFile(archive_path)
f = archive.open(pth_file, "r")
# Parse through the .pth file
for n, line in enumerate(f):
# Ignore comments
if line.startswith(b"#"):
continue
try:
# Execute any lines starting with import
if line.startswith((b"import ", b"import\t")):
exec(line)
else:
line = line.rstrip()
dir, dircase = makepath(sitedir, line.decode('utf-8'))
if not dircase in known_paths and exists(dir):
#Handy debug statement: print "added", dir
if prepend_mode:
sys.path.insert(0, dir)
else:
sys.path.append(dir)
effective_known_paths.add(dircase)
except Exception:
print("Error processing line {:d} of {}:\n".format(n + 1, fullname), file=sys.stderr)
# Pretty print the exception info
for record in traceback.format_exception(*sys.exc_info()):
for line in record.splitlines():
print(" " + line, file=sys.stderr)
print("\nRemainder of file ignored", file=sys.stderr)
break
f.close()
if archive is not None:
archive.close()
return known_paths
示例4: swig_import_helper
def swig_import_helper():
from os.path import dirname, join
import imp
import site
try:
fp, pathname, description = imp.find_module('_graphviz', list(site._init_pathinfo()) +
[dirname(__file__), join(dirname(__file__),'pyvizgraph')])
except ImportError:
import _graphviz
return _graphviz
if fp:
try:
_mod = imp.load_module('_graphviz', fp, pathname, description)
finally:
fp.close()
return _mod
示例5: section
def section(self):
stdlib_path = [sysconfig.get_path('stdlib')]
site_path = sysconfig.get_path('purelib')
# some stdlib modules have different paths inside a virtualenv
if hasattr(sys, 'real_prefix'):
import site
stdlib_path.extend([p for p in site._init_pathinfo() if
re.match(sys.real_prefix, p)])
try:
fpath = self.module.__file__
except AttributeError:
# builtin, thus stdlib
section = ModuleImporter.STDLIB
else:
if re.match(site_path, fpath):
section = ModuleImporter.SITE
elif [p for p in stdlib_path if re.match(p, fpath)]:
section = ModuleImporter.STDLIB
else:
section = ModuleImporter.USER
return section
示例6: addsitedir
def addsitedir(sitedir, known_paths = None, prepend_mode = False):
# We need to return exactly what they gave as known_paths, so don't touch
# it.
effective_known_paths = \
known_paths if known_paths is not None else _site._init_pathinfo()
# Figure out what (if any) part of the path is a zip archive.
archive_path, site_path = split_zip_path(sitedir)
if not site_path.endswith("/"):
site_path = site_path + "/"
# If the user is not trying to add a directory in a zip file, just use
# the standard function.
if not archive_path:
return old_addsitedir(sitedir, effective_known_paths)
# Add the site directory itself
if prepend_mode:
sys.path.insert(0, sitedir)
else:
sys.path.append(sitedir)
with closing(zipfile.ZipFile(archive_path, mode = "r")) as archive:
# Go trhough everything in the archive...
for i in archive.infolist():
# and grab all the .pth files.
if os.path.dirname(i.filename) == os.path.dirname(site_path) and \
i.filename.endswith(os.extsep + "pth"):
addpackage(
os.path.join(archive_path, site_path),
os.path.basename(i.filename),
effective_known_paths,
prepend_mode = prepend_mode
)
return known_paths
示例7: get_sys_path
def get_sys_path(self):
for path in [os.path.join(p, 'site-packages') for p in site._init_pathinfo()
if p.startswith(sys.real_prefix)]:
if os.path.isdir(path):
return path
示例8: SublimeCodeIntelConfig
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import site
PYTHON_PATH = sys.executable
PYTHON_EXTRAS_PATH = site._init_pathinfo()
CONFIG_TEMPLATE = """{
'Python': {
'python': '%s',
'pythonExtraPaths': %s
}
}
"""
class SublimeCodeIntelConfig(object):
"""SublimeCodeIntelConfig"""
config_path = '.codeintel'
config_file = '.codeintel/config'
config_text = ''
def __init__(self):
super(SublimeCodeIntelConfig, self).__init__()
def format_config(self):
self.config_text = CONFIG_TEMPLATE % (PYTHON_PATH,
str(list(PYTHON_EXTRAS_PATH)))