當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。