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


Python pkg_resources.safe_name方法代码示例

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


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

示例1: find_site_path

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_name [as 别名]
def find_site_path(pkg, site_dir=None):
    import pkg_resources
    if site_dir is not None:
        site_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    working_set = pkg_resources.WorkingSet([site_dir] + sys.path[:])
    for dist in working_set:
        root = dist.location
        base_name = dist.project_name if dist.project_name else dist.key
        name = None
        if "top_level.txt" in dist.metadata_listdir(""):
            name = next(iter([l.strip() for l in dist.get_metadata_lines("top_level.txt") if l is not None]), None)
        if name is None:
            name = pkg_resources.safe_name(base_name).replace("-", "_")
        if not any(pkg == _ for _ in [base_name, name]):
            continue
        path_options = [name, "{0}.py".format(name)]
        path_options = [os.path.join(root, p) for p in path_options if p is not None]
        path = next(iter(p for p in path_options if os.path.exists(p)), None)
        if path is not None:
            return (dist, path)
    return (None, None) 
开发者ID:pypa,项目名称:pipenv,代码行数:23,代码来源:resolver.py

示例2: get_name_variants

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_name [as 别名]
def get_name_variants(pkg):
    # type: (STRING_TYPE) -> Set[STRING_TYPE]
    """
    Given a packager name, get the variants of its name for both the canonicalized
    and "safe" forms.

    :param AnyStr pkg: The package to lookup
    :returns: A list of names.
    :rtype: Set
    """

    if not isinstance(pkg, six.string_types):
        raise TypeError("must provide a string to derive package names")
    from pkg_resources import safe_name
    from packaging.utils import canonicalize_name

    pkg = pkg.lower()
    names = {safe_name(pkg), canonicalize_name(pkg), pkg.replace("-", "_")}
    return names 
开发者ID:pypa,项目名称:pipenv,代码行数:21,代码来源:utils.py

示例3: _init_project_name

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_name [as 别名]
def _init_project_name(guildfile):
        """Returns a project name for a guildfile distribution.

        Guildfile distribution project names are of the format:

            '.guildfile.' + ESCAPED_GUILDFILE_PATH

        ESCAPED_GUILDFILE_PATH is a 'safe' project name (i.e. will not be
        modified in a call to `pkg_resources.safe_name`) that, when
        unescaped using `unescape_project_name`, is the relative path of
        the directory containing the guildfile. The modefile name itself
        (e.g. 'guild.yml') is not contained in the path.

        Guildfile paths are relative to the current working directory
        (i.e. the value of os.getcwd() at the time they are generated) and
        always start with '.'.
        """
        pkg_path = os.path.relpath(guildfile.dir, config.cwd())
        if pkg_path[0] != ".":
            pkg_path = os.path.join(".", pkg_path)
        safe_path = escape_project_name(pkg_path)
        return ".guildfile.%s" % safe_path 
开发者ID:guildai,项目名称:guildai,代码行数:24,代码来源:model.py

示例4: normalize

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_name [as 别名]
def normalize(self, key):
        return safe_name(key) 
开发者ID:calmjs,项目名称:calmjs,代码行数:4,代码来源:base.py

示例5: test_distribution_as_key

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_name [as 别名]
def test_distribution_as_key(self):
        mapping = base.PackageKeyMapping()
        mapping[Distribution(project_name='not_normalized')] = 1
        self.assertEqual(1, mapping['not_normalized'])
        self.assertEqual(1, mapping[safe_name('not_normalized')]) 
开发者ID:calmjs,项目名称:calmjs,代码行数:7,代码来源:test_base.py

示例6: test_membership_normalized

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_name [as 别名]
def test_membership_normalized(self):
        mapping = base.PackageKeyMapping(not_normalized=1)
        self.assertIn(safe_name('not_normalized'), mapping)
        self.assertIn('not_normalized', mapping) 
开发者ID:calmjs,项目名称:calmjs,代码行数:6,代码来源:test_base.py

示例7: safer_name

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_name [as 别名]
def safer_name(name):
    return safe_name(name).replace("-", "_") 
开发者ID:microsoft,项目名称:botbuilder-python,代码行数:4,代码来源:azure_bdist_wheel.py

示例8: patch_missing_pkg_info

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_name [as 别名]
def patch_missing_pkg_info(self, attrs):
        # Fake up a replacement for the data that would normally come from
        # PKG-INFO, but which might not yet be built if this is a fresh
        # checkout.
        #
        if not attrs or 'name' not in attrs or 'version' not in attrs:
            return
        key = pkg_resources.safe_name(str(attrs['name'])).lower()
        dist = pkg_resources.working_set.by_key.get(key)
        if dist is not None and not dist.has_metadata('PKG-INFO'):
            dist._version = pkg_resources.safe_version(str(attrs['version']))
            self._patched_dist = dist 
开发者ID:jpush,项目名称:jbox,代码行数:14,代码来源:dist.py

示例9: safer_name

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_name [as 别名]
def safer_name(name):
    return safe_name(name).replace('-', '_') 
开发者ID:jpush,项目名称:jbox,代码行数:4,代码来源:bdist_wheel.py

示例10: project_name

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_name [as 别名]
def project_name(self) -> str:
        return safe_name(self.name) 
开发者ID:frostming,项目名称:pdm,代码行数:4,代码来源:meta.py

示例11: normalize_package

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import safe_name [as 别名]
def normalize_package(name):
    return safe_name(name).lower() 
开发者ID:frostming,项目名称:pdm,代码行数:4,代码来源:show.py


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