當前位置: 首頁>>代碼示例>>Python>>正文


Python site.__file__方法代碼示例

本文整理匯總了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) 
開發者ID:edmundmok,項目名稱:mealpy,代碼行數:21,代碼來源:venv_update.py

示例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 
開發者ID:edmundmok,項目名稱:mealpy,代碼行數:33,代碼來源:venv_update.py

示例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}) 
開發者ID:edmundmok,項目名稱:mealpy,代碼行數:6,代碼來源:venv_update.py

示例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 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:locations.py

示例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 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:11,代碼來源:locations.py

示例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 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:15,代碼來源:locations.py

示例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) 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:14,代碼來源:virtualenv.py


注:本文中的site.__file__方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。