Python软件包名称重复

huangapple go评论102阅读模式
英文:

Python package name duplication

问题

假设在PyPI中有一个名为pkg_1的包。那么名称为pkg__1pkg.1pkg-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 /&lt;project&gt;/
> where the &lt;project&gt; 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 = [
    &#39;pkg-1&#39;,
    &#39;pkg__1&#39;,
    &#39;pkg.1&#39;,
    &#39;Pkg_-.1&#39;,
]

for name in names:
     print(f&quot;{name=}: {canonicalize_name(name)}&quot;)
name=&#39;pkg-1&#39;: pkg-1
name=&#39;pkg__1&#39;: pkg-1
name=&#39;pkg.1&#39;: pkg-1
name=&#39;Pkg_-.1&#39;: pkg-1

huangapple
  • 本文由 发表于 2023年6月12日 16:57:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76455027.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定