本文整理匯總了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)
示例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
示例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
示例4: normalize
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import safe_name [as 別名]
def normalize(self, key):
return safe_name(key)
示例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')])
示例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)
示例7: safer_name
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import safe_name [as 別名]
def safer_name(name):
return safe_name(name).replace("-", "_")
示例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
示例9: safer_name
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import safe_name [as 別名]
def safer_name(name):
return safe_name(name).replace('-', '_')
示例10: project_name
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import safe_name [as 別名]
def project_name(self) -> str:
return safe_name(self.name)
示例11: normalize_package
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import safe_name [as 別名]
def normalize_package(name):
return safe_name(name).lower()