python类addsitedir()的实例源码

vendor.py 文件源码 项目:arithmancer 作者: google 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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:])
__init__.py 文件源码 项目:Deploy_XXNET_Server 作者: jzp820927 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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:])
launch.py 文件源码 项目:rwt 作者: jaraco 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _inject_sitecustomize(target):
    """
    Create a sitecustomize file in the target that will install
    the target as a sitedir.

    Only needed on Python 3.2 and earlier to workaround #1.
    """
    if sys.version_info > (3, 3):
        return

    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)
__boot__.py 文件源码 项目:Mosaic-for-Lego-Digital-Designer 作者: JosephSamela 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _site_packages():
    import site, sys, os
    paths = []
    prefixes = [sys.prefix]
    if sys.exec_prefix != sys.prefix:
        prefixes.append(sys.exec_prefix)
    for prefix in prefixes:
        paths.append(os.path.join(prefix, 'lib', 'python' + sys.version[:3],
            'site-packages'))
    if os.path.join('.framework', '') in os.path.join(sys.prefix, ''):
        home = os.environ.get('HOME')
        if home:
            paths.append(os.path.join(home, 'Library', 'Python',
                sys.version[:3], 'site-packages'))

    # Work around for a misfeature in setuptools: easy_install.pth places
    # site-packages way to early on sys.path and that breaks py2app bundles.
    # NOTE: this is hacks into an undocumented feature of setuptools and
    # might stop to work without warning.
    sys.__egginsert = len(sys.path)

    for path in paths:
        site.addsitedir(path)
admin.py 文件源码 项目:touch-pay-client 作者: HackPucBemobi 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def add_path_first(path):
    sys.path = [path] + [p for p in sys.path if (
        not p == path and not p == (path + '/'))]
    if not global_settings.web2py_runtime_gae:
        site.addsitedir(path)
root.py 文件源码 项目:hoplite 作者: ni 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def reload_site_packages():
    # TODO: Can probably be replaced with reload(pkg_resources)
    opsys = platform.system().lower()
    python_exe_path = sys.executable
    bin_path = os.path.split(python_exe_path)[0]
    venv_path = os.path.split(bin_path)[0]
    site_path = ""
    if opsys == 'windows':
        # If running in virtual environment, we must account for different
        # folder structure
        if hasattr(sys, 'real_prefix'):
            site_path = os.path.join(venv_path, "..", "Lib", "site-packages")
        else:
            site_path = os.path.join(venv_path, "Lib", "site-packages")
    elif opsys == 'linux' or opsys == 'darwin':
        # If running in virtual environment, we must account for different
        # folder structure
        if hasattr(sys, 'real_prefix'):
            site_path = os.path.join(
                venv_path, "..", "lib", "python{0}.{1}".format(
                    sys.version_info[0], sys.version_info[1]), "site-packages")
        else:
            site_path = os.path.join(
                venv_path, "lib", "python{0}.{1}".format(
                    sys.version_info[0], sys.version_info[1]), "site-packages")
    site.addsitedir(site_path)
    for path in sys.path:
        pkg_resources.working_set.add_entry(path)
test_rosmsg_importlib_import.py 文件源码 项目:rosimport 作者: pyros-dev 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def setUpClass(cls):
        # This is used for message definitions, not for python code
        site.addsitedir(cls.rosdeps_path)
        rosimport.activate()
test_rosmsg_importlib_import.py 文件源码 项目:rosimport 作者: pyros-dev 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def setUpClass(cls):
        # This is used for message definitions, not for python code
        site.addsitedir(cls.rosdeps_path)
        site.addsitedir(cls.ros_comm_msgs_path)
        rosimport.activate()
test_rosmsg_importlib_importmodule.py 文件源码 项目:rosimport 作者: pyros-dev 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def setUpClass(cls):
        # This is used for message definitions, not for python code
        site.addsitedir(cls.rosdeps_path)
        rosimport.activate()
test_rosmsg_importlib_importmodule.py 文件源码 项目:rosimport 作者: pyros-dev 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def setUpClass(cls):
        # This is used for message definitions, not for python code
        site.addsitedir(cls.rosdeps_path)
        site.addsitedir(cls.ros_comm_msgs_path)
        rosimport.activate()
test_rosmsg_importlib.py 文件源码 项目:rosimport 作者: pyros-dev 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def setUpClass(cls):
        # This is used for message definitions, not for python code
        site.addsitedir(cls.rosdeps_path)
        activate()
test_rosmsg_import.py 文件源码 项目:rosimport 作者: pyros-dev 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def setUpClass(cls):
        # This is used for message definitions, not for python code
        site.addsitedir(cls.rosdeps_path)
        activate()
test_rosmsg_import.py 文件源码 项目:rosimport 作者: pyros-dev 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def setUpClass(cls):
        # This is used for message definitions, not for python code
        site.addsitedir(cls.rosdeps_path)
        site.addsitedir(cls.ros_comm_msgs_path)
        activate()
test_rosmsg_import.py 文件源码 项目:rosimport 作者: pyros-dev 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def setUpClass(cls):
        # This is used for message definitions, not for python code
        site.addsitedir(cls.rosdeps_path)
        rosimport.activate()
test_rosmsg_import.py 文件源码 项目:rosimport 作者: pyros-dev 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def setUpClass(cls):
        # This is used for message definitions, not for python code
        site.addsitedir(cls.rosdeps_path)
        site.addsitedir(cls.ros_comm_msgs_path)
        rosimport.activate()
rosmsg_metafinder.py 文件源码 项目:rosimport 作者: pyros-dev 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self, *workspaces):
            """
            :param workspaces: can be a devel or install workspace (including a distro install directory), but also a directory containing packages (like a source workspace)
            These should all work, without catkin build necessary.
            """
            super(ROSDistroMetaFinder, self).__init__()
            # TODO : prevent that when we are in virtualenv and we have not allowed system site packages

            self.src_rospkgs = []

            broken_workspaces = []
            for w in workspaces:
                # Adding the share path (where we can find all packages and their messages)
                share_path = os.path.join(w, 'share')
                if os.path.exists(share_path):
                    self.share_path = share_path
                else:  # this is not a workspace, maybe we are expected to get the package directly from source ?
                    found_one = False
                    for root, dirs, files in os.walk(w, topdown=False):
                        if 'package.xml' in files:  # we have found a ros package
                            self.src_rospkgs.append(root)
                            found_one = True
                    if not found_one:
                        broken_workspaces.append(w)

                    raise ImportError

                python_libpath = os.path.join(w, 'lib', 'python' + sys.version_info.major + '.' + sys.version_info.minor)
                if os.path.exists(python_libpath):
                    # adding python site directories for the ROS distro (to find python modules as usual with ROS)
                    if os.path.exists(os.path.join(python_libpath, 'dist-packages')):
                        site.addsitedir(os.path.join(python_libpath, 'dist-packages'))
                    if os.path.exists(os.path.join(python_libpath, 'site-packages')):
                        site.addsitedir(os.path.join(python_libpath, 'site-packages'))
                else:  # this is not a workspace, maybe we are expected to get the package directly from source ?

                    for root, dirs, files in os.walk(w, topdown=False):
                        if 'package.xml' in files:  # we have found a ros package
                            self.src_rospkgs.append(root)

                    raise ImportError
admin.py 文件源码 项目:true_review_web2py 作者: lucadealfaro 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def add_path_first(path):
    sys.path = [path] + [p for p in sys.path if (
        not p == path and not p == (path + '/'))]
    if not global_settings.web2py_runtime_gae:
        site.addsitedir(path)
test_site.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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()
vtr_plugin.py 文件源码 项目:Vector-Tiles-Reader-QGIS-Plugin 作者: geometalab 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _add_path_to_dependencies_to_syspath():
        """
         * Adds the path to the external libraries to the sys.path if not already added
        """
        ext_libs_path = os.path.join(get_plugin_directory(), 'ext-libs')
        if ext_libs_path not in sys.path:
            site.addsitedir(ext_libs_path)
general_utils.py 文件源码 项目:trex-http-proxy 作者: alwye 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def import_module_list_by_path (modules_list):
    assert(isinstance(modules_list, list))
    for full_path in modules_list:
        site.addsitedir(full_path)
admin.py 文件源码 项目:Problematica-public 作者: TechMaz 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def add_path_first(path):
    sys.path = [path] + [p for p in sys.path if (
        not p == path and not p == (path + '/'))]
    if not global_settings.web2py_runtime_gae:
        site.addsitedir(path)
test_site.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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()
test_site.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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()
test_site.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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()
admin.py 文件源码 项目:rekall-agent-server 作者: rekall-innovations 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def add_path_first(path):
    sys.path = [path] + [p for p in sys.path if (
        not p == path and not p == (path + '/'))]
    if not global_settings.web2py_runtime_gae:
        site.addsitedir(path)
test_mu.py 文件源码 项目:cloud-custodian 作者: capitalone 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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())
admin.py 文件源码 项目:web3py 作者: web2py 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def add_path_first(path):
    sys.path = [path] + [p for p in sys.path if (
        not p == path and not p == (path + '/'))]
    if not global_settings.web2py_runtime_gae:
        site.addsitedir(path)
test_site.py 文件源码 项目:pefile.pypy 作者: cloudtracer 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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()
test_site.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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()
admin.py 文件源码 项目:slugiot-client 作者: slugiot 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def add_path_first(path):
    sys.path = [path] + [p for p in sys.path if (
        not p == path and not p == (path + '/'))]
    if not global_settings.web2py_runtime_gae:
        site.addsitedir(path)


问题


面经


文章

微信
公众号

扫码关注公众号