• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python site.addpackage函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中site.addpackage函数的典型用法代码示例。如果您正苦于以下问题:Python addpackage函数的具体用法?Python addpackage怎么用?Python addpackage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: addpackage

def addpackage(sitedir, pthfile, known_dirs=None):
    """
    Wrapper for site.addpackage

    Try and work out which directories are added by
    the .pth and add them to the known_dirs set
    """
    known_dirs = set(known_dirs or [])
    with open(join(sitedir, pthfile)) as f:
        for n, line in enumerate(f):
            if line.startswith("#"):
                continue
            line = line.rstrip()
            if line:
                if line.startswith(("import ", "import\t")):
                    exec (line, globals(), locals())
                    continue
                else:
                    p_rel = join(sitedir, line)
                    p_abs = abspath(line)
                    if isdir(p_rel):
                        os.environ['PATH'] += env_t(os.pathsep + p_rel)
                        sys.path.append(p_rel)
                        added_dirs.add(p_rel)
                    elif isdir(p_abs):
                        os.environ['PATH'] += env_t(os.pathsep + p_abs)
                        sys.path.append(p_abs)
                        added_dirs.add(p_abs)

    if isfile(pthfile):
        site.addpackage(sitedir, pthfile, known_dirs)
    else:
        logging.debug("pth file '%s' not found")
开发者ID:andreubotella,项目名称:vext,代码行数:33,代码来源:__init__.py


示例2: test_nested_namespace_import

 def test_nested_namespace_import(self):
     pth = 'foogle_fax-0.12.5-py2.7-nspkg.pth'
     site.addpackage(resources.RESOURCE_PATH, pth, [])
     pkg_resources._namespace_packages['foogle'] = ['foogle.crank']
     pkg_resources._namespace_packages['foogle.crank'] = []
     try:
         self.manager.ast_from_module_name('foogle.crank')
     finally:
         del pkg_resources._namespace_packages['foogle']
         sys.modules.pop('foogle')
开发者ID:eriksf,项目名称:dotfiles,代码行数:10,代码来源:unittest_manager.py


示例3: test_namespace_and_file_mismatch

 def test_namespace_and_file_mismatch(self):
     filepath = unittest.__file__
     ast = self.manager.ast_from_file(filepath)
     self.assertEqual(ast.name, 'unittest')
     pth = 'foogle_fax-0.12.5-py2.7-nspkg.pth'
     site.addpackage(resources.RESOURCE_PATH, pth, [])
     pkg_resources._namespace_packages['foogle'] = []
     try:
         with self.assertRaises(exceptions.AstroidImportError):
             self.manager.ast_from_module_name('unittest.foogle.fax')
     finally:
         del pkg_resources._namespace_packages['foogle']
         sys.modules.pop('foogle')
开发者ID:eriksf,项目名称:dotfiles,代码行数:13,代码来源:unittest_manager.py


示例4: test_addpackage

 def test_addpackage(self):
     # Make sure addpackage() imports if the line starts with 'import',
     # adds directories to sys.path for any line in the file that is not a
     # comment or import that is a valid directory name for where the .pth
     # file resides; invalid directories are not added
     pth_file = PthFile()
     pth_file.cleanup(prep=True)  # to make sure that nothing is
                                   # pre-existing that shouldn't be
     try:
         pth_file.create()
         site.addpackage(pth_file.base_dir, pth_file.filename, set())
         self.pth_file_tests(pth_file)
     finally:
         pth_file.cleanup()
开发者ID:pogigroo,项目名称:py3k-__format__,代码行数:14,代码来源:test_site.py


示例5: test_namespace_package_pth_support

    def test_namespace_package_pth_support(self):
        pth = 'foogle_fax-0.12.5-py2.7-nspkg.pth'
        site.addpackage(resources.RESOURCE_PATH, pth, [])
        pkg_resources._namespace_packages['foogle'] = []

        try:
            module = self.manager.ast_from_module_name('foogle.fax')
            submodule = next(module.igetattr('a'))
            value = next(submodule.igetattr('x'))
            self.assertIsInstance(value, astroid.Const)
            with self.assertRaises(exceptions.AstroidImportError):
                self.manager.ast_from_module_name('foogle.moogle')
        finally:
            del pkg_resources._namespace_packages['foogle']
            sys.modules.pop('foogle')
开发者ID:eriksf,项目名称:dotfiles,代码行数:15,代码来源:unittest_manager.py


示例6: test_namespace_package_pth_support

 def test_namespace_package_pth_support(self):
     directory = os.path.join(resources.DATA_DIR, "data")
     pth = "foogle_fax-0.12.5-py2.7-nspkg.pth"
     site.addpackage(directory, pth, [])
     # pylint: disable=no-member; can't infer _namespace_packages, created at runtime.
     pkg_resources._namespace_packages["foogle"] = []
     try:
         module = self.manager.ast_from_module_name("foogle.fax")
         submodule = next(module.igetattr("a"))
         value = next(submodule.igetattr("x"))
         self.assertIsInstance(value, astroid.Const)
         with self.assertRaises(exceptions.AstroidImportError):
             self.manager.ast_from_module_name("foogle.moogle")
     finally:
         del pkg_resources._namespace_packages["foogle"]
         sys.modules.pop("foogle")
开发者ID:PyCQA,项目名称:astroid,代码行数:16,代码来源:unittest_manager.py


示例7: test_addpackage_import_bad_pth_file

 def test_addpackage_import_bad_pth_file(self):
     # Issue 5258
     pth_dir, pth_fn = self.make_pth("abc\x00def\n")
     with captured_stderr() as err_out:
         self.assertFalse(site.addpackage(pth_dir, pth_fn, set()))
     self.assertEqual(err_out.getvalue(), "")
     for path in sys.path:
         if isinstance(path, str):
             self.assertNotIn("abc\x00def", path)
开发者ID:funkyHat,项目名称:cpython,代码行数:9,代码来源:test_site.py


示例8: rel

from __future__ import absolute_import, division, print_function, unicode_literals

import site
import os

def rel(*path):
    """
    Converts path relative to the project root into an absolute path

    :rtype: str
    """
    return os.path.abspath(
        os.path.join(
            os.path.dirname(__file__),
            *path
        )
    ).replace("\\", "/")

site.addpackage(rel(), "apps.pth", known_paths=set())
开发者ID:GoelAnuj2020,项目名称:weather,代码行数:19,代码来源:__init__.py


示例9: rel

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

from .utils import rel
import os, site

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
ROOT_DIR = rel('..')
BASE_DIR = rel('')

# site.addpackage is actually responsible for *.pth file processing
site.addpackage(os.path.join(ROOT_DIR), 'modules.pth', known_paths=set())

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '2([email protected]@pf!j$a#[email protected]$x2z#q-=(+ono)dt!uu!niol'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = bool(os.environ.get('DEBUG', False))
TEMPLATE_DEBUG = DEBUG
ALLOWED_HOSTS = []

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Application definition
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
开发者ID:adriancmiranda,项目名称:django-template,代码行数:31,代码来源:base.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python site.addsitedir函数代码示例发布时间:2022-05-27
下一篇:
Python site._init_pathinfo函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap