当前位置: 首页>>代码示例>>Python>>正文


Python site.addsitedir方法代码示例

本文整理汇总了Python中site.addsitedir方法的典型用法代码示例。如果您正苦于以下问题:Python site.addsitedir方法的具体用法?Python site.addsitedir怎么用?Python site.addsitedir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在site的用法示例。


在下文中一共展示了site.addsitedir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUpModule

# 需要导入模块: import site [as 别名]
# 或者: from site import addsitedir [as 别名]
def setUpModule():
    global OLD_SYS_PATH
    OLD_SYS_PATH = sys.path[:]

    if site.ENABLE_USER_SITE and not os.path.isdir(site.USER_SITE):
        # need to add user site directory for tests
        try:
            os.makedirs(site.USER_SITE)
            # modify sys.path: will be restored by tearDownModule()
            site.addsitedir(site.USER_SITE)
        except OSError as exc:
            if exc.errno in (errno.EACCES, errno.EPERM):
                raise unittest.SkipTest('unable to create user site directory (%r): %s'
                                        % (site.USER_SITE, exc))
            else:
                raise 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_site.py

示例2: import_spydercustomize

# 需要导入模块: import site [as 别名]
# 或者: from site import addsitedir [as 别名]
def import_spydercustomize():
    """Import our customizations into the kernel."""
    here = osp.dirname(__file__)
    parent = osp.dirname(here)
    customize_dir = osp.join(parent, 'customize')

    # Remove current directory from sys.path to prevent kernel
    # crashes when people name Python files or modules with
    # the same name as standard library modules.
    # See spyder-ide/spyder#8007
    while '' in sys.path:
        sys.path.remove('')

    # Import our customizations
    site.addsitedir(customize_dir)
    import spydercustomize

    # Remove our customize path from sys.path
    try:
        sys.path.remove(customize_dir)
    except ValueError:
        pass 
开发者ID:spyder-ide,项目名称:spyder-kernels,代码行数:24,代码来源:start.py

示例3: _patch_path

# 需要导入模块: import site [as 别名]
# 或者: from site import addsitedir [as 别名]
def _patch_path(pipenv_site=None):
    import site
    pipenv_libdir = os.path.dirname(os.path.abspath(__file__))
    pipenv_site_dir = os.path.dirname(pipenv_libdir)
    pipenv_dist = None
    if pipenv_site is not None:
        pipenv_dist, pipenv_path = find_site_path("pipenv", site_dir=pipenv_site)
    else:
        pipenv_dist, pipenv_path = find_site_path("pipenv", site_dir=pipenv_site_dir)
    if pipenv_dist is not None:
        pipenv_dist.activate()
    else:
        site.addsitedir(next(iter(
            sitedir for sitedir in (pipenv_site, pipenv_site_dir)
            if sitedir is not None
        ), None))
    if pipenv_path is not None:
        pipenv_libdir = pipenv_path
    for _dir in ("vendor", "patched", pipenv_libdir):
        sys.path.insert(0, os.path.join(pipenv_libdir, _dir)) 
开发者ID:pypa,项目名称:pipenv,代码行数:22,代码来源:resolver.py

示例4: add

# 需要导入模块: import site [as 别名]
# 或者: from site import addsitedir [as 别名]
def add(path, index=1):
  """Insert site dir or virtualenv at a given index in sys.path.

  Args:
    path: relative path to a site dir or virtualenv.
    index: sys.path position to insert the site dir.

  Raises:
    ValueError: path doesn't exist.
  """
  venv_path = os.path.join(path, 'lib', PYTHON_VERSION, 'site-packages')
  if os.path.isdir(venv_path):
    site_dir = venv_path
  elif os.path.isdir(path):
    site_dir = path
  else:
    raise ValueError('virtualenv: cannot access %s: '
                     'No such virtualenv or site directory' % path)



  sys_path = sys.path[:]
  del sys.path[index:]
  site.addsitedir(site_dir)
  sys.path.extend(sys_path[index:]) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:27,代码来源:__init__.py

示例5: _inject_sitecustomize

# 需要导入模块: import site [as 别名]
# 或者: from site import addsitedir [as 别名]
def _inject_sitecustomize(target):
    """
    Create a sitecustomize file in the target that will install
    the target as a sitedir.
    """
    hook = (
        textwrap.dedent(
            """
        import site
        site.addsitedir({target!r})
        """
        )
        .lstrip()
        .format(**locals())
    )
    sc_fn = os.path.join(target, 'sitecustomize.py')
    with open(sc_fn, 'w') as strm:
        strm.write(hook) 
开发者ID:jaraco,项目名称:pip-run,代码行数:20,代码来源:launch.py

示例6: test_import_string

# 需要导入模块: import site [as 别名]
# 或者: from site import addsitedir [as 别名]
def test_import_string(self):
        assert import_string("site.addsitedir") == addsitedir
        assert import_string("site:addsitedir") == addsitedir
        assert import_string("code.interact") == interact
        assert import_string("code:interact") == interact

        # test things not already imported
        func = import_string("os.path:join")
        from os.path import join

        assert func == join

        # test something already imported
        import shiv

        assert import_string("shiv") == shiv == sys.modules["shiv"]

        # test bogus imports raise properly
        with pytest.raises(ImportError):
            import_string("this is bogus!") 
开发者ID:linkedin,项目名称:shiv,代码行数:22,代码来源:test_bootstrap.py

示例7: add

# 需要导入模块: import site [as 别名]
# 或者: from site import addsitedir [as 别名]
def add(path, index=1):
  """Insert site dir or virtualenv at a given index in sys.path.
  Args:
    path: relative path to a site dir or virtualenv.
    index: sys.path position to insert the site dir.
  Raises:
    ValueError: path doesn't exist.
  """
  venv_path = os.path.join(path, 'lib', PYTHON_VERSION, 'site-packages')
  if os.path.isdir(venv_path):
    site_dir = venv_path
  elif os.path.isdir(path):
    site_dir = path
  else:
    raise ValueError('virtualenv: cannot access %s: '
                     'No such virtualenv or site directory' % path)



  sys_path = sys.path[:]
  del sys.path[index:]
  site.addsitedir(site_dir)
  sys.path.extend(sys_path[index:]) 
开发者ID:google,项目名称:arithmancer,代码行数:25,代码来源:vendor.py

示例8: init_virtualenv

# 需要导入模块: import site [as 别名]
# 或者: from site import addsitedir [as 别名]
def init_virtualenv():
    venv = os.environ.get("VIRTUAL_ENV", None)
    if not venv:
        return

    p = os.path.normcase(sys.executable)
    paths = [p]
    while os.path.islink(p):
        p = os.path.normcase(os.path.join(os.path.dirname(p), os.readlink(p)))
        paths.append(p)
    venv_path = os.path.normcase(venv)
    if any(p.startswith(venv_path) for p in paths):
        return

    print(venv_warning, file=sys.stderr)
    if sys.platform == "win32":
        path = os.path.join(venv, 'Lib', 'site-packages')
    else:
        python = "python{}.{}".format(*sys.version_info[:2])
        path = os.path.join(venv, 'lib', python, 'site-packages')
    sys.path.insert(0, path)
    site.addsitedir(path) 
开发者ID:numberly,项目名称:flask2postman,代码行数:24,代码来源:flask2postman.py

示例9: test_addsitedir

# 需要导入模块: import site [as 别名]
# 或者: from site import addsitedir [as 别名]
def test_addsitedir(self):
        # Same tests for test_addpackage since addsitedir() essentially just
        # calls addpackage() for every .pth file in the directory
        pth_file = PthFile()
        pth_file.cleanup(prep=True) # Make sure that nothing is pre-existing
                                    # that is tested for
        try:
            pth_file.create()
            site.addsitedir(pth_file.base_dir, set())
            self.pth_file_tests(pth_file)
        finally:
            pth_file.cleanup() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:test_site.py

示例10: test_no_home_directory

# 需要导入模块: import site [as 别名]
# 或者: from site import addsitedir [as 别名]
def test_no_home_directory(self):
        # bpo-10496: getuserbase() and getusersitepackages() must not fail if
        # the current user has no home directory (if expanduser() returns the
        # path unchanged).
        site.USER_SITE = None
        site.USER_BASE = None
        sysconfig._CONFIG_VARS = None

        with EnvironmentVarGuard() as environ, \
             support.swap_attr(os.path, 'expanduser', lambda path: path):

            del environ['PYTHONUSERBASE']
            del environ['APPDATA']

            user_base = site.getuserbase()
            self.assertTrue(user_base.startswith('~' + os.sep),
                            user_base)

            user_site = site.getusersitepackages()
            self.assertTrue(user_site.startswith(user_base), user_site)

        def fake_isdir(path):
            fake_isdir.arg = path
            return False
        fake_isdir.arg = None

        def must_not_be_called(*args):
            raise AssertionError

        with support.swap_attr(os.path, 'isdir', fake_isdir), \
             support.swap_attr(site, 'addsitedir', must_not_be_called), \
             support.swap_attr(site, 'ENABLE_USER_SITE', True):

            # addusersitepackages() must not add user_site to sys.path
            # if it is not an existing directory
            known_paths = set()
            site.addusersitepackages(known_paths)

            self.assertEqual(fake_isdir.arg, user_site)
            self.assertFalse(known_paths) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:42,代码来源:test_site.py

示例11: fix_module_search_paths

# 需要导入模块: import site [as 别名]
# 或者: from site import addsitedir [as 别名]
def fix_module_search_paths():
  """Add directories that we must be able to import from to path."""
  root_directory = os.environ['ROOT_DIR']
  source_directory = os.path.join(root_directory, 'src')

  python_path = os.getenv('PYTHONPATH', '').split(os.pathsep)

  third_party_libraries_directory = os.path.join(source_directory,
                                                 'third_party')
  config_modules_directory = _config_modules_directory(root_directory)

  if (os.path.exists(config_modules_directory) and
      config_modules_directory not in sys.path):
    sys.path.insert(0, config_modules_directory)
    python_path.insert(0, config_modules_directory)

  if third_party_libraries_directory not in sys.path:
    sys.path.insert(0, third_party_libraries_directory)
    python_path.insert(0, third_party_libraries_directory)

  python_source_directory = os.path.join(source_directory, 'python')
  if python_source_directory not in sys.path:
    sys.path.insert(0, python_source_directory)
    python_path.insert(0, python_source_directory)

  if source_directory not in sys.path:
    sys.path.insert(0, source_directory)
    python_path.insert(0, source_directory)

  os.environ['PYTHONPATH'] = os.pathsep.join(python_path)

  # Add site directory to make from imports work in google namespace.
  site.addsitedir(third_party_libraries_directory)

  # TODO(ochang): Remove this once SDK is removed from images.
  _patch_appengine_modules_for_bots() 
开发者ID:google,项目名称:clusterfuzz,代码行数:38,代码来源:modules.py

示例12: init_virtualenv

# 需要导入模块: import site [as 别名]
# 或者: from site import addsitedir [as 别名]
def init_virtualenv(self):
        """Add a virtualenv to sys.path so the user can import modules from it.
        This isn't perfect: it doesn't use the Python interpreter with which the
        virtualenv was built, and it ignores the --no-site-packages option. A
        warning will appear suggesting the user installs IPython in the
        virtualenv, but for many cases, it probably works well enough.
        
        Adapted from code snippets online.
        
        http://blog.ufsoft.org/2009/1/29/ipython-and-virtualenv
        """
        if 'VIRTUAL_ENV' not in os.environ:
            # Not in a virtualenv
            return
        
        if sys.executable.startswith(os.environ['VIRTUAL_ENV']):
            # Running properly in the virtualenv, don't need to do anything
            return
        
        warn("Attempting to work in a virtualenv. If you encounter problems, please "
             "install IPython inside the virtualenv.")
        if sys.platform == "win32":
            virtual_env = os.path.join(os.environ['VIRTUAL_ENV'], 'Lib', 'site-packages') 
        else:
            virtual_env = os.path.join(os.environ['VIRTUAL_ENV'], 'lib',
                       'python%d.%d' % sys.version_info[:2], 'site-packages')
        
        import site
        sys.path.insert(0, virtual_env)
        site.addsitedir(virtual_env)

    #-------------------------------------------------------------------------
    # Things related to injections into the sys module
    #------------------------------------------------------------------------- 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:36,代码来源:interactiveshell.py

示例13: get_module

# 需要导入模块: import site [as 别名]
# 或者: from site import addsitedir [as 别名]
def get_module (self):
    site.addsitedir(self.fields.get('path'))
    return importlib.import_module(self.name) 
开发者ID:openaps,项目名称:openaps,代码行数:5,代码来源:vendor.py

示例14: FromImport

# 需要导入模块: import site [as 别名]
# 或者: from site import addsitedir [as 别名]
def FromImport (klass, candidate, config=None):
    name = candidate.get('name')
    fields = candidate.get(name)
    # site.addsitedir(fields.get('path'))
    # fields['vendor'] = importlib.import_module(fields['vendor'])
    from openaps import vendors
    vendor = vendors.lookup_dotted(fields['vendor'], config)
    inst = klass(name, vendor)
    inst.fields = fields
    inst.extra.fields = candidate['extra']
    return inst 
开发者ID:openaps,项目名称:openaps,代码行数:13,代码来源:device.py

示例15: main

# 需要导入模块: import site [as 别名]
# 或者: from site import addsitedir [as 别名]
def main(step_run_ref_filepath, pipeline_zip):
    # Extract any zip files to a temporary directory and add that temporary directory
    # to the site path so the contained files can be imported.
    #
    # We can't rely on pip or other packaging tools because the zipped files might not
    # even be Python packages.
    with tempfile.TemporaryDirectory() as tmp:

        print('Extracting {}'.format(pipeline_zip))
        with zipfile.ZipFile(pipeline_zip) as zf:
            zf.extractall(tmp)
        site.addsitedir(tmp)

        print('Loading step run ref')
        # We can use regular local filesystem APIs to access DBFS inside the Databricks runtime.
        with open(step_run_ref_filepath, 'rb') as handle:
            step_run_ref = pickle.load(handle)

        print('Step run ref:')
        print(step_run_ref)

        print('Setting up storage credentials')
        setup_storage(step_run_ref)

        print('Running pipeline')
        events = list(run_step_from_ref(step_run_ref))

    print('Saving events to DBFS')
    events_filepath = os.path.dirname(step_run_ref_filepath) + '/' + PICKLED_EVENTS_FILE_NAME
    with open(events_filepath, 'wb') as handle:
        pickle.dump(serialize_value(events), handle) 
开发者ID:dagster-io,项目名称:dagster,代码行数:33,代码来源:databricks_step_main.py


注:本文中的site.addsitedir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。