英文:
Python package name duplication
问题
假设在PyPI中有一个名为pkg_1
的包。那么名称为pkg__1
、pkg.1
或pkg-1
的包可以上传到PyPI吗?
这里提到:
名称是您的包的分发名称。只要它只包含字母、数字、
.
、_
和-
,它可以是任何名称。
但是这里提到:
在根URL下面,每个单独的项目都有另一个URL。此URL的格式是
/<project>/
,其中<project>
由该项目的规范化名称替代,因此名为“HolyGrail”的项目将具有类似/holygrail/
的URL。
而通过规范化名称,它的意思是:
名称应全部小写,所有字符
.
、-
或_
的运行都应替换为单个-
字符。
所以我猜一个名为a_.-b
的包被视为与a-b
相同。我对吗?
英文:
Suppose there is a package named pkg_1
in PyPI. Can packages with names pkg__1
, pkg.1
or pkg-1
be uploaded to PyPI?
Here mentioned:
> name is the distribution name of your package. This can be any name as
> long as it only contains letters, numbers, .
, _
, and -
.
But Here mentioned:
> Below the root URL is another URL for each individual project
> contained within a repository. The format of this URL is /<project>/
> where the <project>
is replaced by the normalized name for that
> project, so a project named “HolyGrail” would have a URL like
> /holygrail/
.
And by the normalized name, it means:
> The name should be lowercased with all runs of the characters .
, -
, or _
replaced with a single -
character.
So I guess a package named a_.-b
is considered the same as a-b
. Am I right?
答案1
得分: 1
我建议使用packaging.utils.canonicalize_name()
实用函数,这是第三方 packaging 库中的函数,该库是 pip 本身用于此类工作的库。
from packaging.utils import canonicalize_name
names = [
'pkg-1',
'pkg__1',
'pkg.1',
'Pkg_-.1',
]
for name in names:
print(f"{name=}: {canonicalize_name(name)}")
name='pkg-1': pkg-1
name='pkg__1': pkg-1
name='pkg.1': pkg-1
name='Pkg_-.1': pkg-1
英文:
I recommend using the packaging.utils.canonicalize_name()
utility function from the 3rd party packaging library which is the library used by pip itself for this kind of work.
from packaging.utils import canonicalize_name
names = [
'pkg-1',
'pkg__1',
'pkg.1',
'Pkg_-.1',
]
for name in names:
print(f"{name=}: {canonicalize_name(name)}")
name='pkg-1': pkg-1
name='pkg__1': pkg-1
name='pkg.1': pkg-1
name='Pkg_-.1': pkg-1
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论