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


Python ModuleType.__file__方法代码示例

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


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

示例1: setUp

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __file__ [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

示例2: from_config_status

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __file__ [as 别名]
    def from_config_status(cls, path):
        """Create an instance from a config.status file."""
        code_cache = cls._CODE_CACHE
        mtime = os.path.getmtime(path)

        # cache the compiled code as it can be reused
        # we cache it the first time, or if the file changed
        if not path in code_cache or code_cache[path][0] != mtime:
            # Add config.status manually to sys.modules so it gets picked up by
            # iter_modules_in_path() for automatic dependencies.
            mod = ModuleType('config.status')
            mod.__file__ = path
            sys.modules['config.status'] = mod

            with open(path, 'rt') as fh:
                source = fh.read()
                code_cache[path] = (
                    mtime,
                    compile(source, path, 'exec', dont_inherit=1)
                )

        g = {
            '__builtins__': __builtins__,
            '__file__': path,
        }
        l = {}
        exec(code_cache[path][1], g, l)

        config = BuildConfig()

        for name in l['__all__']:
            setattr(config, name, l[name])

        return config
开发者ID:MichaelKohler,项目名称:gecko-dev,代码行数:36,代码来源:configenvironment.py

示例3: refresh_model

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __file__ [as 别名]
    def refresh_model(self):
        """ Refresh the compiled model object.

        This method will (re)compile the model for the given model text
        and update the 'compiled_model' attribute. If a compiled view is
        available and has a member named 'model', the model will be
        applied to the view.

        """
        text = self.model_text
        filename = self.model_filename
        _fake_linecache(text, filename)
        try:
            if not text:
                self.compiled_model = None
                self._model_module = None
            else:
                code = compile(text, filename, 'exec')
                module = ModuleType(filename.rsplit('.', 1)[0])
                module.__file__ = filename
                namespace = module.__dict__
                exec_(code, namespace)
                model = namespace.get(self.model_item, lambda: None)()
                self.compiled_model = model
                self._model_module = module
            self.relink_view()
        except Exception:
            self.traceback = traceback.format_exc()
        else:
            self.traceback = ''
开发者ID:peterazmanov,项目名称:enaml,代码行数:32,代码来源:live_editor_model.py

示例4: update_from_file

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __file__ [as 别名]
    def update_from_file(self, filename, overwrite=False):
        """Updates configuration from Python file.
        For example, if there's :file:`dev.cfg`::

            debug = False
            database_uri = 'sqlite://'

        so you can load it using :meth:`update_from_file()` method::

            config.update_from_file('dev.cfg')

        Like :meth:`update_from_object()` method, it also ignores
        variables that start with underscore.

        :param filename: the path of Python file to load
        :type filename: :class:`basestring`
        :param overwrite: keys that already exist are ignored by default.
                          if ``True`` has given to this parameter,
                          these are not overwritten
        :type overwrite: :class:`bool`

        """
        module = ModuleType(filename)
        module.__file__ = abspath(filename)
        execfile(filename, module.__dict__)
        self.update_from_object(module, overwrite)
开发者ID:yoloseem,项目名称:plastic,代码行数:28,代码来源:config.py

示例5: new_module

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __file__ [as 别名]
def new_module(name, doc=None):
    import sys
    from types import ModuleType
    m = ModuleType(name, doc)
    m.__file__ = name + '.py'
    sys.modules[name] = m
    return m
开发者ID:RBINS,项目名称:mars,代码行数:9,代码来源:patches.py

示例6: main

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __file__ [as 别名]
def main(module=None):

    # Pygame won't run from a normal virtualenv copy of Python on a Mac
    if not _check_python_ok_for_pygame():
        _substitute_full_framework_python()

    if not module:
        parser = OptionParser()
        options, args = parser.parse_args()

        if len(args) != 1:
            parser.error("You must specify which module to run.")

        if __debug__:
            warnings.simplefilter('default', DeprecationWarning)

        path = args[0]
    else:
        path = module
    with open(path) as f:
        src = f.read()

    code = compile(src, os.path.basename(path), 'exec', dont_inherit=True)

    loaders.set_root(path)

    pygame.display.set_mode((100, 100), DISPLAY_FLAGS)
    name, _ = os.path.splitext(os.path.basename(path))
    mod = ModuleType(name)
    mod.__file__ = path
    mod.__name__ = name
    mod.__dict__.update(builtins.__dict__)
    sys.modules[name] = mod
    exec(code, mod.__dict__)
    Juego(mod).run()
开发者ID:yrobla,项目名称:pyjuegos,代码行数:37,代码来源:runner.py

示例7: __call__

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __file__ [as 别名]
    def __call__(self, cls):
        """
        Decorate `cls`
        """
        expose_internal = self.expose_internal

        if self.submodule:
            self.name += "." + cls.__name__

        if self.name not in sys.modules:
            orig = ModuleType(self.name)
            orig.__name__ = self.name
            orig.__file__ = getfile(cls)
        else:
            orig = sys.modules[self.name]

        if isinstance(orig, ModuleFacade):
            raise TypeError("Facade() used inside module which is already "
                              "wrapped - only once Facade() allowed per module."
                              " inside {0}".format(orig))

        class _wrapper_cls(cls, ModuleFacade, ModuleType, object):
            _facade_wrapped = orig
            _facade_cls = cls

            def __dir__(self):
                items = set()
                items.update(self.__dict__)
                items.update(self._facade_cls.__dict__)

                if hasattr(self._facade_cls, "__dir__"):
                    items.update(self._facade_cls.__dir__(self))

                if expose_internal:
                    items.update(orig.__dict__)

                return sorted(items)

            def __getattr__(self, key):
                if expose_internal and hasattr(orig, key):
                    return getattr(orig, key)
                sup = super(_wrapper_cls, self)
                if hasattr(sup, "__getattr__"):
                    result = sup.__getattr__(key)
                    if result is not None:
                        return result
                raise AttributeError("'{0}' object has no attribute '{1}'"
                    .format(self, key))

        _wrapper_cls.__name__ = "ModuleFacade({0})".format(cls.__name__)
        inst = _wrapper_cls(self.name)
        sys.modules[self.name] = inst

        for key in "__name__ __doc__ __file__ __path__".split():
            if hasattr(orig, key):
                setattr(inst, key, getattr(orig, key))

        return inst
开发者ID:S-Bahrasemani,项目名称:rootpy,代码行数:60,代码来源:module_facade.py

示例8: _loadSingle

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __file__ [as 别名]
def _loadSingle(mk, mf, m=None):
    trace("execfile", mk.name, m)
    if m is None:
        m = ModuleType(mk.name)
    contents = {}
    code = execfile(mk.filePath.path, contents)
    contents['__exocet_context__'] = mf
    m.__dict__.update(contents)
    m.__file__ = mk.filePath.path
    return m
开发者ID:EntityReborn,项目名称:bravo,代码行数:12,代码来源:_exocet.py

示例9: new_module

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __file__ [as 别名]
    def new_module(self, module_name, file_path):
        self.module_name = module_name

        module = ModuleType(module_name)

        module.__package__ = module_name.rpartition('.')[0]
        module.__file__ = file_path
        module.__loader__ = FileWithMacrosLoader(module_name, module)

        return module
开发者ID:ruza-net,项目名称:PyMac,代码行数:12,代码来源:import_hook.py

示例10: _pl_local_init

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __file__ [as 别名]
def _pl_local_init(initfile = "init.py", eval = __builtins__.eval):
	from types import ModuleType
	import os.path
	if os.path.exists(initfile):
		# XXX: Do permission check on init.py
		with open(initfile) as init_file:
			bc = compile(init_file.read(), initfile, 'exec')
			module = ModuleType('__pg_init__')
			module.__file__ = initfile
			module.__builtins__ = __builtins__
			eval(bc, module.__dict__, module.__dict__)
		sys.modules['__pg_init__'] = module
		LOG('loaded Python module "__pg_init__" (init.py)')
开发者ID:fdr,项目名称:pg-python,代码行数:15,代码来源:module.py

示例11: get_module

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __file__ [as 别名]
def get_module(mod_path, filepath):
    '''Compile a plugin module

    :param filepath: full filepath to python plugin module
    '''

    with open(filepath, 'r') as f:
        c = compile(f.read(), '', 'exec')

    module = ModuleType(mod_path)
    module.__file__ = filepath
    exec(c, module.__dict__)

    return module
开发者ID:danbradham,项目名称:mtoatools,代码行数:16,代码来源:plugins.py

示例12: _loadSingle

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __file__ [as 别名]
def _loadSingle(mk, mf, m=None):
    trace("execfile", mk.name, m)
    if m is None:
        m = ModuleType(mk.name)

    # Run the actual exec.
    contents = {}
    with mk.filePath.open("rb") as handle:
        exec handle in contents

    contents['__exocet_context__'] = mf
    m.__dict__.update(contents)
    m.__file__ = mk.filePath.path
    return m
开发者ID:JDShu,项目名称:bravo,代码行数:16,代码来源:_exocet.py

示例13: _exec

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __file__ [as 别名]
    def _exec(engine, data, width, height):
        _main = sys.modules["__main__"]
        try:
            mod = ModuleType("__main__")
            mod.__file__ = __file__

            mod._engine_ = weakref.ref(engine)
            mod._data_ = data
            mod._width_ = width
            mod._height_ = height
            mod._mmap_size_ = None
            mod._mmap_ = None

            sys.modules["__main__"] = mod
            exec(code, mod.__dict__)
        finally:
            sys.modules["__main__"] = _main
        return mod
开发者ID:mattheimlich,项目名称:barnold,代码行数:20,代码来源:ipr.py

示例14: refresh_view

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __file__ [as 别名]
    def refresh_view(self):
        """ Refresh the compiled view object.

        This method will (re)compile the view for the given view text
        and update the 'compiled_view' attribute. If a compiled model
        is available and the view has a member named 'model', the model
        will be applied to the view.

        """
        text = self.view_text
        filename = self.view_filename
        _fake_linecache(text, filename)
        try:
            if not text:
                self.compiled_view = None
                self._view_module = None
            else:
                ast = parse(text, filename=filename)
                code = EnamlCompiler.compile(ast, filename)
                module = ModuleType('__main__')
                module.__file__ = filename
                namespace = module.__dict__
                with enaml.imports():
                    exec_(code, namespace)
                view = namespace.get(self.view_item, lambda: None)()
                if isinstance(view, Object) and 'model' in view.members():
                    view.model = self.compiled_model
                # trap any initialization errors and roll back the view
                old = self.compiled_view
                try:
                    self.compiled_view = view
                except Exception:
                    self.compiled_view = old
                    if isinstance(old, Widget):
                        old.show()
                    raise
                self._view_module = module
                if old is not None and not old.is_destroyed:
                    old.destroy()
        except Exception:
            self.traceback = traceback.format_exc()
        else:
            self.traceback = ''
开发者ID:peterazmanov,项目名称:enaml,代码行数:45,代码来源:live_editor_model.py

示例15: import_file

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __file__ [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


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