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


Python pkg_resources.working_set方法代码示例

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


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

示例1: __init__

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import working_set [as 别名]
def __init__(self, registry_name, *a, **kw):
        # TODO whenever there is time to move the BaseRegistry to a
        # bootstrap module of some sort (that will break tests that
        # override calmjs.base.working_set if done naively), and have
        # the calmjs.registry.Registry inherit from that (and this
        # module also to maintain the BaseRegistry import location,
        # this import should be moved to the top
        from calmjs.registry import get
        # resolve parent before the parent class, as the construction
        # should be able to reference this parent.
        parent_name = self.resolve_parent_registry_name(registry_name)
        _parent = kw.pop('_parent', NotImplemented)
        if _parent is NotImplemented:
            self.parent = get(parent_name)
        else:
            self.parent = _parent

        if not self.parent:
            raise ValueError(
                "could not construct child module registry '%s' as its "
                "parent registry '%s' could not be found" % (
                    registry_name, parent_name)
            )
        super(BaseChildModuleRegistry, self).__init__(registry_name, *a, **kw) 
开发者ID:calmjs,项目名称:calmjs,代码行数:26,代码来源:base.py

示例2: setup_class_integration_environment

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import working_set [as 别名]
def setup_class_integration_environment(cls, **kw):
    import calmjs.registry
    from calmjs import dist as calmjs_dist
    from calmjs import base
    from calmjs.loaderplugin import MODULE_LOADER_SUFFIX
    cls.dist_dir = mkdtemp_realpath()
    working_set, inst = generate_root_integration_environment(
        cls.dist_dir, **kw)

    cls.root_registry = inst
    cls.registry_name = kw.get('registry_id', 'calmjs.module.simulated')
    cls.test_registry_name = cls.registry_name + tests_suffix
    cls.loader_registry_name = cls.registry_name + MODULE_LOADER_SUFFIX
    cls.working_set = working_set

    # stubs
    cls._old_root_registry, calmjs.registry._inst = calmjs.registry._inst, inst
    cls.root_working_set, calmjs_dist.default_working_set = (
        calmjs_dist.default_working_set, working_set)
    base.working_set = working_set 
开发者ID:calmjs,项目名称:calmjs,代码行数:22,代码来源:utils.py

示例3: get_packages

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import working_set [as 别名]
def get_packages():
    """
    Get list of installed packages and their versions.

    :return: installed packages and versions, keyed by package name
    :rtype: dict of str or unicode => str or unicode
    """
    packages = pkg_resources.working_set
    packages_dict = {}
    for package in packages:
        # Some packages are imported using their `package.key` (keys do not
        # contain capitals), e.g., gdal. Others are imported using their
        # `package.project_name`, e.g., netCDF4. So, both the `key` and
        # `project_name` are added to the `packages_dict`.
        modules_from_package = package._get_metadata('top_level.txt')
        for mod in modules_from_package:
            packages_dict[mod] = package.version

        packages_dict[package.key] = package.version
        packages_dict[package.project_name] = package.version
    return packages_dict 
开发者ID:recipy,项目名称:recipy,代码行数:23,代码来源:environment.py

示例4: check_package_exists

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import working_set [as 别名]
def check_package_exists(package, lib_dir):
    """Check if a package is installed globally or in lib_dir.

    Returns True when the requirement is met.
    Returns False when the package is not installed or doesn't meet req.
    """
    try:
        req = pkg_resources.Requirement.parse(package)
    except ValueError:
        # This is a zip file
        req = pkg_resources.Requirement.parse(urlparse(package).fragment)

    # Check packages from lib dir
    if lib_dir is not None:
        if any(dist in req for dist in
               pkg_resources.find_distributions(lib_dir)):
            return True

    # Check packages from global + virtual environment
    # pylint: disable=not-an-iterable
    return any(dist in req for dist in pkg_resources.working_set) 
开发者ID:django-leonardo,项目名称:django-leonardo,代码行数:23,代码来源:package.py

示例5: __init__

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import working_set [as 别名]
def __init__(
            self, registry_name,
            package_name=PACKAGE_NAME, reserved=CALMJS_RESERVED, *a, **kw):
        """
        The root registry will also track the undocumented working set
        specification
        """

        working_set_ = kw.get('_working_set') or working_set
        self.reserved = {}
        if reserved:
            dist = working_set_.find(Requirement.parse(package_name))
            if dist is None:
                logger.error(
                    "failed to set up registry_name reservations for "
                    "registry '%s', as the specified package '%s' could "
                    "not found in the current working_set; maybe it is not "
                    "correctly installed?", registry_name, package_name,
                )
            else:
                # module_name is the package_name in our context.
                self.reserved = {
                    k: v.module_name for k, v in dist.get_entry_map(
                        reserved).items()
                }
        super(Registry, self).__init__(registry_name, *a, **kw) 
开发者ID:calmjs,项目名称:calmjs,代码行数:28,代码来源:registry.py

示例6: stub_mod_working_set

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import working_set [as 别名]
def stub_mod_working_set(testcase_inst, modules, working_set):
    """
    Replace the working_set for the target modules
    """

    def restore(module, working_set):
        module.working_set = working_set

    for module in modules:
        testcase_inst.addCleanup(restore, module, module.working_set)
        module.working_set = working_set 
开发者ID:calmjs,项目名称:calmjs,代码行数:13,代码来源:utils.py

示例7: __init__

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import working_set [as 别名]
def __init__(
            self, logger='calmjs', action_key=DEST_RUNTIME,
            working_set=default_working_set, package_name=None,
            description=None, *a, **kw):
        """
        Keyword Arguments:

        logger
            The logger to enable for pretty logging.

            Default: the calmjs root logger

        action_key
            The destination key where the command will be stored.  Under
            this key the target driver runtime will be stored, and it
            will be popped off first before passing rest of kwargs to
            it.

        working_set
            The working_set to use for this instance.

            Default: pkg_resources.working_set

        package_name
            The package name that this instance of runtime is for.  Used
            for the version flag.

        description
            The description for this runtime.
        """

        self.logger = logger
        self.action_key = action_key
        self.working_set = working_set
        self.description = description or self.__doc__
        self.package_name = package_name
        super(BaseRuntime, self).__init__(*a, **kw) 
开发者ID:calmjs,项目名称:calmjs,代码行数:39,代码来源:runtime.py

示例8: update_available

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import working_set [as 别名]
def update_available(package_name):
    packages = [dist.project_name for dist in pkg_resources.working_set]
    if package_name not in packages:
        dprint(f"The package: [{package_name}] is not a dependency of this software.", origin=L_DEPENDENCIES)
        return None
    vers = check_pypi_version(package_name)
    if vers is not None:
        dprint(f"{package_name} available: {vers}", origin=L_DEPENDENCIES)
        dprint(f"{package_name} current: {pkg_resources.get_distribution(package_name).version}", origin=L_DEPENDENCIES)
        if vers != pkg_resources.get_distribution(package_name).version:
            dprint(f"There is a newer version of: [{package_name}({vers})] available.", origin=L_DEPENDENCIES)
            return True
    return False 
开发者ID:DuckBoss,项目名称:JJMumbleBot,代码行数:15,代码来源:auto_updater_helper.py

示例9: get_versions

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import working_set [as 别名]
def get_versions(working_set=True):
  versions = [get_module_version(name) for name in MODULES]
  if working_set:
    for pkg in pkg_resources.working_set:
      name, version = str(pkg).split(' ', 1)
      versions.append(('{} *'.format(name), version))
  versions.sort()
  return versions 
开发者ID:lipis,项目名称:github-stats,代码行数:10,代码来源:versions.py

示例10: collect_installed_distributions

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import working_set [as 别名]
def collect_installed_distributions():
    """Yield the normalized spec and the names of top_level modules of all installed packages."""
    for distribution in pkg_resources.working_set:
        distribution_spec = str(distribution.as_requirement())
        distribution_top_level = guess_top_level(distribution)
        yield distribution_spec, distribution_top_level 
开发者ID:nodev-io,项目名称:pytest-nodev,代码行数:8,代码来源:collect.py

示例11: _get_pkg_resource

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import working_set [as 别名]
def _get_pkg_resource(filename, package, prefix):
    """Query pkg_resources for the location of the filename."""
    requirement = pkg_resources.Requirement.parse(package)
    target = os.path.join(prefix, filename)
    try:
        return pkg_resources.resource_filename(requirement, target)
    except pkg_resources.DistributionNotFound:
        # It may be that the working set is not in sync (e.g. if sys.path was
        # manipulated). Try to reload it just in case.
        pkg_resources.working_set = pkg_resources.WorkingSet()
        try:
            return pkg_resources.resource_filename(requirement, target)
        except pkg_resources.DistributionNotFound:
            return None 
开发者ID:google,项目名称:rekall,代码行数:16,代码来源:resources.py

示例12: fill_missing_version

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import working_set [as 别名]
def fill_missing_version(self):
        if self.version is not None:
            return
        dist = pkg_resources.working_set.by_key.get(self.name)
        self.version = dist.version if dist else None 
开发者ID:IDSIA,项目名称:sacred,代码行数:7,代码来源:dependencies.py

示例13: create

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import working_set [as 别名]
def create(cls, mod):
        if not cls.modname_to_dist:
            # some packagenames don't match the module names (e.g. PyYAML)
            # so we set up a dict to map from module name to package name
            for dist in pkg_resources.working_set:
                try:
                    toplevel_names = dist._get_metadata("top_level.txt")
                    for tln in toplevel_names:
                        cls.modname_to_dist[tln] = dist.project_name, dist.version
                except Exception:
                    pass

        name, version = cls.modname_to_dist.get(mod.__name__, (mod.__name__, None))

        return PackageDependency(name, version) 
开发者ID:IDSIA,项目名称:sacred,代码行数:17,代码来源:dependencies.py

示例14: get_dependencies_from_pkg

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import working_set [as 别名]
def get_dependencies_from_pkg(globs, base_path):
    dependencies = set()
    for dist in pkg_resources.working_set:
        if dist.version == "0.0.0":
            continue  # ugly hack to deal with pkg-resource version bug
        dependencies.add(PackageDependency(dist.project_name, dist.version))
    return dependencies 
开发者ID:IDSIA,项目名称:sacred,代码行数:9,代码来源:dependencies.py

示例15: _generate_installed_modules

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import working_set [as 别名]
def _generate_installed_modules():
    # type: () -> Iterator[Tuple[str, str]]
    try:
        import pkg_resources
    except ImportError:
        return

    for info in pkg_resources.working_set:
        yield info.key, info.version 
开发者ID:getsentry,项目名称:sentry-python,代码行数:11,代码来源:modules.py


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