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


Python ModuleType.__path__方法代码示例

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


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

示例1: InitPathesAndBuiltins

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __path__ [as 别名]
def InitPathesAndBuiltins():
    sys.path.insert(0, eg.mainDir.encode('mbcs'))
    sys.path.insert(1, eg.sitePackagesDir.encode('mbcs'))

    import cFunctions
    sys.modules["eg.cFunctions"] = cFunctions
    eg.cFunctions = cFunctions

    # add 'wx' to the builtin name space of every module
    import __builtin__
    __builtin__.wx = wx

    # we create a package 'PluginModule' and set its path to the plugin-dir
    # so we can simply use __import__ to load a plugin file
    corePluginPackage = ModuleType("eg.CorePluginModule")
    corePluginPackage.__path__ = [eg.corePluginDir]
    sys.modules["eg.CorePluginModule"] = corePluginPackage
    eg.CorePluginModule = corePluginPackage
    # we create a package 'PluginModule' and set its path to the plugin-dir
    # so we can simply use __import__ to load a plugin file
    if not os.path.exists(eg.localPluginDir):
        os.makedirs(eg.localPluginDir)
    userPluginPackage = ModuleType("eg.UserPluginModule")
    userPluginPackage.__path__ = [eg.localPluginDir]
    sys.modules["eg.UserPluginModule"] = userPluginPackage
    eg.UserPluginModule = userPluginPackage
开发者ID:AssetsInc,项目名称:EventGhost,代码行数:28,代码来源:Init.py

示例2: test_minimum_sys_modules

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __path__ [as 别名]
def test_minimum_sys_modules():
  # builtins stay
  builtin_module = ModuleType('my_builtin')
  modules = {'my_builtin': builtin_module}
  new_modules = PEX.minimum_sys_modules([], modules)
  assert new_modules == modules
  new_modules = PEX.minimum_sys_modules(['bad_path'], modules)
  assert new_modules == modules

  # tainted evict
  tainted_module = ModuleType('tainted_module')
  tainted_module.__path__ = ['bad_path']
  modules = {'tainted_module': tainted_module}
  new_modules = PEX.minimum_sys_modules([], modules)
  assert new_modules == modules
  new_modules = PEX.minimum_sys_modules(['bad_path'], modules)
  assert new_modules == {}
  assert tainted_module.__path__ == []

  # tainted cleaned
  tainted_module = ModuleType('tainted_module')
  tainted_module.__path__ = ['bad_path', 'good_path']
  modules = {'tainted_module': tainted_module}
  new_modules = PEX.minimum_sys_modules([], modules)
  assert new_modules == modules
  new_modules = PEX.minimum_sys_modules(['bad_path'], modules)
  assert new_modules == modules
  assert tainted_module.__path__ == ['good_path']
开发者ID:clam-gpsw,项目名称:pex,代码行数:30,代码来源:test_pex.py

示例3: setUp

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __path__ [as 别名]
    def setUp(self):
        # `dummyns.submod` emulates a package that also provide the
        # `dummyns` namespace package that got installed after the
        # other package `dummyns`.
        ds_egg_root = join(mkdtemp(self), 'dummyns.submod')
        dummyns_path = join(ds_egg_root, 'dummyns')
        dummyns = ModuleType('dummyns')
        dummyns.__file__ = join(dummyns_path, '__init__.py')
        dummyns.__path__ = [dummyns_path]
        self.addCleanup(sys.modules.pop, 'dummyns')
        sys.modules['dummyns'] = dummyns

        dummyns_submod_path = join(ds_egg_root, 'dummyns', 'submod')
        dummyns_submod = ModuleType('dummyns.submod')
        dummyns_submod.__file__ = join(dummyns_submod_path, '__init__.py')
        dummyns_submod.__path__ = [dummyns_submod_path]
        self.addCleanup(sys.modules.pop, 'dummyns.submod')
        sys.modules['dummyns.submod'] = dummyns_submod

        os.makedirs(dummyns_submod_path)

        with open(join(dummyns_path, '__init__.py'), 'w') as fd:
            fd.write('')

        with open(join(dummyns_submod_path, '__init__.py'), 'w') as fd:
            fd.write('')

        self.nested_res = join(dummyns_submod_path, 'data.txt')
        self.nested_data = 'data'
        with open(self.nested_res, 'w') as fd:
            fd.write(self.nested_data)

        # create the package proper
        self.dummyns_submod_dist = make_dummy_dist(self, ((
            'namespace_packages.txt',
            'dummyns\n'
            'dummyns.submod\n',
        ), (
            'entry_points.txt',
            '[dummyns.submod]\n'
            'dummyns.submod = dummyns.submod:attr\n',
        ),), 'dummyns.submod', '1.0', working_dir=ds_egg_root)

        self.ds_egg_root = ds_egg_root
        self.dummyns_path = dummyns_path

        self.mod_dummyns = dummyns
        self.mod_dummyns_submod = dummyns_submod
开发者ID:calmjs,项目名称:calmjs,代码行数:50,代码来源:test_indexer.py

示例4: test_get_modpath_all_multi

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __path__ [as 别名]
 def test_get_modpath_all_multi(self):
     module = ModuleType('nothing')
     module.__path__ = ['/path/to/here', '/path/to/there']
     self.assertEqual(
         indexer.modpath_all(module, None),
         ['/path/to/here', '/path/to/there'],
     )
开发者ID:calmjs,项目名称:calmjs,代码行数:9,代码来源:test_indexer.py

示例5: create_module

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __path__ [as 别名]
 def create_module(self, spec):
     """
     Alter __path__ to equal spec.name (i.e qualname) 
     so we can catch consequent imports.
     """
     m = ModuleType(spec.name)
     m.__path__ = [m.__name__.lower()]
     return m
开发者ID:DimitrisJim,项目名称:pipimporter,代码行数:10,代码来源:__init__.py

示例6: InitPathsAndBuiltins

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __path__ [as 别名]
def InitPathsAndBuiltins():
    import cFunctions
    import __builtin__

    eg.folderPath = eg.FolderPath()
    eg.mainDir = eg.folderPath.mainDir
    eg.configDir = eg.folderPath.configDir
    eg.corePluginDir = eg.folderPath.corePluginDir
    eg.localPluginDir = eg.folderPath.localPluginDir
    eg.imagesDir = eg.folderPath.imagesDir
    eg.languagesDir = eg.folderPath.languagesDir
    eg.sitePackagesDir = eg.folderPath.sitePackagesDir

    if not exists(eg.configDir):
        try:
            makedirs(eg.configDir)
        except:
            pass

    if not exists(eg.localPluginDir):
        try:
            makedirs(eg.localPluginDir)
        except:
            eg.localPluginDir = eg.corePluginDir

    if eg.Cli.args.isMain:
        if exists(eg.configDir):
            chdir(eg.configDir)
        else:
            chdir(eg.mainDir)

    __builtin__.wx = wx

    corePluginPackage = ModuleType("eg.CorePluginModule")
    corePluginPackage.__path__ = [eg.corePluginDir]
    userPluginPackage = ModuleType("eg.UserPluginModule")
    userPluginPackage.__path__ = [eg.localPluginDir]

    sys.modules["eg.CorePluginModule"] = corePluginPackage
    sys.modules["eg.UserPluginModule"] = userPluginPackage
    sys.modules['eg.cFunctions'] = cFunctions

    eg.pluginDirs = [eg.corePluginDir, eg.localPluginDir]
    eg.cFunctions = cFunctions
    eg.CorePluginModule = corePluginPackage
    eg.UserPluginModule = userPluginPackage
开发者ID:EventGhost,项目名称:EventGhost,代码行数:48,代码来源:Init.py

示例7: InitPathsAndBuiltins

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __path__ [as 别名]
def InitPathsAndBuiltins():
    sys.path.insert(0, eg.mainDir.encode('mbcs'))
    sys.path.insert(1, eg.sitePackagesDir.encode('mbcs'))

    try:
        if "PYTHONPATH" in os.environ:
            for path in os.environ.get("PYTHONPATH").split(os.pathsep):
                site.addsitedir(path)

        key = winreg.HKEY_LOCAL_MACHINE
        version = sys.version_info[:2]
        subkey = r"SOFTWARE\Python\PythonCore\%d.%d\InstallPath" % version
        with winreg.OpenKey(key, subkey) as hand:
            site.addsitedir(
                os.path.join(
                    winreg.QueryValue(hand, None),
                    "Lib",
                    "site-packages",
                )
            )
    except:
        pass

    import cFunctions
    sys.modules["eg.cFunctions"] = cFunctions
    eg.cFunctions = cFunctions

    # add 'wx' to the builtin name space of every module
    import __builtin__
    __builtin__.wx = wx

    # we create a package 'PluginModule' and set its path to the plugin-dir
    # so we can simply use __import__ to load a plugin file
    corePluginPackage = ModuleType("eg.CorePluginModule")
    corePluginPackage.__path__ = [eg.corePluginDir]
    sys.modules["eg.CorePluginModule"] = corePluginPackage
    eg.CorePluginModule = corePluginPackage
    # we create a package 'PluginModule' and set its path to the plugin-dir
    # so we can simply use __import__ to load a plugin file
    if not os.path.exists(eg.localPluginDir):
        os.makedirs(eg.localPluginDir)
    userPluginPackage = ModuleType("eg.UserPluginModule")
    userPluginPackage.__path__ = [eg.localPluginDir]
    sys.modules["eg.UserPluginModule"] = userPluginPackage
    eg.UserPluginModule = userPluginPackage
开发者ID:WoLpH,项目名称:EventGhost,代码行数:47,代码来源:Init.py

示例8: load_module

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __path__ [as 别名]
 def load_module(self, fullname):
     print "load", fullname
     if fullname.endswith("test"):
         return 1
     else:
         r = ModuleType(fullname)
         r.__package__ = fullname
         r.__path__ = []
         return r
开发者ID:ChinaQuants,项目名称:pyston,代码行数:11,代码来源:sys_meta_path.py

示例9: test_minimum_sys_modules

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __path__ [as 别名]
def test_minimum_sys_modules():
  # builtins stay
  builtin_module = ModuleType('my_builtin')
  modules = {'my_builtin': builtin_module}
  new_modules = PEX.minimum_sys_modules([], modules)
  assert new_modules == modules
  new_modules = PEX.minimum_sys_modules(['bad_path'], modules)
  assert new_modules == modules

  # tainted evict
  tainted_module = ModuleType('tainted_module')
  tainted_module.__path__ = ['bad_path']
  modules = {'tainted_module': tainted_module}
  new_modules = PEX.minimum_sys_modules([], modules)
  assert new_modules == modules
  new_modules = PEX.minimum_sys_modules(['bad_path'], modules)
  assert new_modules == {}
  assert tainted_module.__path__ == []

  # tainted cleaned
  tainted_module = ModuleType('tainted_module')
  tainted_module.__path__ = ['bad_path', 'good_path']
  modules = {'tainted_module': tainted_module}
  new_modules = PEX.minimum_sys_modules([], modules)
  assert new_modules == modules
  new_modules = PEX.minimum_sys_modules(['bad_path'], modules)
  assert new_modules == modules
  assert tainted_module.__path__ == ['good_path']

  # If __path__ is not a list the module is removed; typically this implies
  # it's a namespace package (https://www.python.org/dev/peps/pep-0420/) where
  # __path__ is a _NamespacePath.
  try:
    from importlib._bootstrap_external import _NamespacePath
    bad_path = _NamespacePath("hello", "world", None)
  except ImportError:
    bad_path = {"hello": "world"}
  class FakeModule(object):
    pass
  tainted_module = FakeModule()
  tainted_module.__path__ = bad_path   # Not a list as expected
  modules = {'tainted_module': tainted_module}
  new_modules = PEX.minimum_sys_modules(['bad_path'], modules)
  assert new_modules == {}
开发者ID:pfmoore,项目名称:pex,代码行数:46,代码来源:test_pex.py

示例10: test_get_modpath_pkg_resources_missing

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __path__ [as 别名]
 def test_get_modpath_pkg_resources_missing(self):
     # fake just the entry point, but provide a valid module.
     nothing = ModuleType('nothing')
     nothing.__path__ = []
     self.addCleanup(sys.modules.pop, 'nothing')
     sys.modules['nothing'] = nothing
     ep = pkg_resources.EntryPoint.parse('nothing = nothing')
     with pretty_logging(stream=StringIO()) as fd:
         self.assertEqual([], indexer.modpath_pkg_resources(nothing, ep))
     self.assertIn(
         "resource path cannot be found for module 'nothing' and "
         "entry_point 'nothing = nothing'", fd.getvalue())
开发者ID:calmjs,项目名称:calmjs,代码行数:14,代码来源:test_indexer.py

示例11: test_find_app

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __path__ [as 别名]
    def test_find_app(self):
        cmd = MockCommand()
        with patch("celery.bin.base.symbol_by_name") as sbn:
            from types import ModuleType
            x = ModuleType("proj")
            def on_sbn(*args, **kwargs):

                def after(*args, **kwargs):
                    x.celery = "quick brown fox"
                    x.__path__ = None
                    return x
                sbn.side_effect = after
                return x
            sbn.side_effect = on_sbn
            x.__path__ = [True]
            self.assertEqual(cmd.find_app("proj"), "quick brown fox")
开发者ID:AdrianRibao,项目名称:celery,代码行数:18,代码来源:test_base.py

示例12: test_find_app

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __path__ [as 别名]
    def test_find_app(self):
        cmd = MockCommand(app=self.app)
        with patch('celery.bin.base.symbol_by_name') as sbn:
            from types import ModuleType
            x = ModuleType('proj')

            def on_sbn(*args, **kwargs):

                def after(*args, **kwargs):
                    x.app = 'quick brown fox'
                    x.__path__ = None
                    return x
                sbn.side_effect = after
                return x
            sbn.side_effect = on_sbn
            x.__path__ = [True]
            self.assertEqual(cmd.find_app('proj'), 'quick brown fox')
开发者ID:AlJohri,项目名称:celery,代码行数:19,代码来源:test_base.py

示例13: test_find_app

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __path__ [as 别名]
    def test_find_app(self, app):
        cmd = MockCommand(app=app)
        with patch('celery.utils.imports.symbol_by_name') as sbn:
            from types import ModuleType
            x = ModuleType(bytes_if_py2('proj'))

            def on_sbn(*args, **kwargs):

                def after(*args, **kwargs):
                    x.app = 'quick brown fox'
                    x.__path__ = None
                    return x
                sbn.side_effect = after
                return x
            sbn.side_effect = on_sbn
            x.__path__ = [True]
            assert cmd.find_app('proj') == 'quick brown fox'
开发者ID:pashinin,项目名称:celery,代码行数:19,代码来源:test_base.py

示例14: import_file

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __path__ [as 别名]
def import_file(filename, name = None, package = None, add_to_sys_modules = False):
    if os.path.isdir(filename):
        filename = os.path.join(filename, "__init__.py")
    if name is None:
        name = os.path.basename(filename).split(".")[0]
        dirname = os.path.basename(os.path.dirname(filename)).strip()
        if name == "__init__" and dirname:
            name = dirname
        elif package is not None:
            name = package + "." + name
    mod = ModuleType(name)
    mod.__file__ = os.path.abspath(filename)
    if package is not None:
        mod.__package__ = package
        mod.__path__ = [os.path.dirname(mod.__file__)]
    if add_to_sys_modules:
        sys.modules[name] = mod
    execfile(filename, mod.__dict__)
    return mod
开发者ID:GeekOffTheStreet,项目名称:agnos,代码行数:21,代码来源:util.py

示例15: InitPathesAndBuiltins

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __path__ [as 别名]
def InitPathesAndBuiltins():
    sys.path.insert(0, eg.MAIN_DIR)
    sys.path.insert(
        1,
        os.path.join(eg.MAIN_DIR, "lib%d%d" % sys.version_info[:2], "site-packages")
    )

    import cFunctions
    sys.modules["eg.cFunctions"] = cFunctions
    eg.cFunctions = cFunctions

    # add 'wx' to the builtin name space of every module
    import __builtin__
    __builtin__.wx = wx

    # we create a package 'PluginModule' and set its path to the plugin-dir
    # so we can simply use __import__ to load a plugin file
    pluginPackage = ModuleType("eg.PluginModule")
    pluginPackage.__path__ = [eg.PLUGIN_DIR]
    sys.modules["eg.PluginModule"] = pluginPackage
    eg.PluginModule = pluginPackage
开发者ID:garbear,项目名称:EventGhost,代码行数:23,代码来源:Init.py


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