本文整理汇总了Python中site.__file__方法的典型用法代码示例。如果您正苦于以下问题:Python site.__file__方法的具体用法?Python site.__file__怎么用?Python site.__file__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类site
的用法示例。
在下文中一共展示了site.__file__方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: has_system_site_packages
# 需要导入模块: import site [as 别名]
# 或者: from site import __file__ [as 别名]
def has_system_site_packages(interpreter):
# TODO: unit-test
system_site_packages = check_output((
interpreter,
'-c',
# stolen directly from virtualenv's site.py
"""\
import site, os.path
print(
0
if os.path.exists(
os.path.join(os.path.dirname(site.__file__), 'no-global-site-packages.txt')
) else
1
)"""
))
system_site_packages = int(system_site_packages)
assert system_site_packages in (0, 1)
return bool(system_site_packages)
示例2: exec_scratch_virtualenv
# 需要导入模块: import site [as 别名]
# 或者: from site import __file__ [as 别名]
def exec_scratch_virtualenv(args):
"""
goals:
- get any random site-packages off of the pythonpath
- ensure we can import virtualenv
- ensure that we're not using the interpreter that we may need to delete
- idempotency: do nothing if the above goals are already met
"""
scratch = Scratch()
if not exists(scratch.python):
run(('virtualenv', scratch.venv))
if not exists(join(scratch.src, 'virtualenv.py')):
scratch_python = venv_python(scratch.venv)
# TODO: do we allow user-defined override of which version of virtualenv to install?
tmp = scratch.src + '.tmp'
run((scratch_python, '-m', 'pip.__main__', 'install', 'virtualenv', '--target', tmp))
from os import rename
rename(tmp, scratch.src)
import sys
from os.path import realpath
# We want to compare the paths themselves as sometimes sys.path is the same
# as scratch.venv, but with a suffix of bin/..
if realpath(sys.prefix) != realpath(scratch.venv):
# TODO-TEST: sometimes we would get a stale version of venv-update
exec_((scratch.python, dotpy(__file__)) + args) # never returns
# TODO-TEST: the original venv-update's directory was on sys.path (when using symlinking)
sys.path[0] = scratch.src
示例3: execfile_
# 需要导入模块: import site [as 别名]
# 或者: from site import __file__ [as 别名]
def execfile_(filename):
with open(filename) as code:
code = compile(code.read(), filename, 'exec')
exec(code, {'__file__': filename})
示例4: virtualenv_no_global
# 需要导入模块: import site [as 别名]
# 或者: from site import __file__ [as 别名]
def virtualenv_no_global():
"""
Return True if in a venv and no system site packages.
"""
# this mirrors the logic in virtualenv.py for locating the
# no-global-site-packages.txt file
site_mod_dir = os.path.dirname(os.path.abspath(site.__file__))
no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt')
if running_under_virtualenv() and os.path.isfile(no_global_file):
return True
示例5: virtualenv_no_global
# 需要导入模块: import site [as 别名]
# 或者: from site import __file__ [as 别名]
def virtualenv_no_global():
"""
Return True if in a venv and no system site packages.
"""
#this mirrors the logic in virtualenv.py for locating the no-global-site-packages.txt file
site_mod_dir = os.path.dirname(os.path.abspath(site.__file__))
no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt')
if running_under_virtualenv() and os.path.isfile(no_global_file):
return True
示例6: virtualenv_no_global
# 需要导入模块: import site [as 别名]
# 或者: from site import __file__ [as 别名]
def virtualenv_no_global():
# type: () -> bool
"""
Return True if in a venv and no system site packages.
"""
# this mirrors the logic in virtualenv.py for locating the
# no-global-site-packages.txt file
site_mod_dir = os.path.dirname(os.path.abspath(site.__file__))
no_global_file = os.path.join(site_mod_dir, 'no-global-site-packages.txt')
if running_under_virtualenv() and os.path.isfile(no_global_file):
return True
else:
return False
示例7: _no_global_under_regular_virtualenv
# 需要导入模块: import site [as 别名]
# 或者: from site import __file__ [as 别名]
def _no_global_under_regular_virtualenv():
# type: () -> bool
"""Check if "no-global-site-packages.txt" exists beside site.py
This mirrors logic in pypa/virtualenv for determining whether system
site-packages are visible in the virtual environment.
"""
site_mod_dir = os.path.dirname(os.path.abspath(site.__file__))
no_global_site_packages_file = os.path.join(
site_mod_dir, 'no-global-site-packages.txt',
)
return os.path.exists(no_global_site_packages_file)