在python存储库名称和包名称中使用连字符/破折号 [英] Using hyphen/dash in python repository name and package name

查看:147
本文介绍了在python存储库名称和包名称中使用连字符/破折号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使我的git存储库可点安装.为此,我正在对存储库进行重组,以遵循正确的约定.通过查看其他存储库,我的理解是,我应该将所有源代码放在与存储库名称同名的程序包中.例如.如果我的存储库称为myrepo,则源代码将全部放入一个也称为myrepo的程序包中.

I am trying to make my git repository pip-installable. In preparation for that I am restructuring the repo to follow the right conventions. My understanding from looking at other repositories is that I should put all my source code in a package that has the same name as the repository name. E.g. if my repository is called myrepo, then the source code would all go into a package also called myrepo.

我的存储库中带有连字符以提高可读性:例如my-repo.因此,如果我想为其包装一个具有相同名称的包装,则包装中也应带有连字符. 在本教程中它对python软件包说不要使用连字符"名称.但是,我已经看到了完善的软件包,例如scikit-learn,其名称中带有连字符.我注意到的一件事是,在scikit-learn存储库中,程序包名称与存储库名称不同,而是称为sklearn.

My repository has a hyphen in it for readability: e.g. my-repo. So if I wanted to make a package for it with the same name, it would have a hyphen in it as well. In this tutorial it says "don't use hyphens" for python package names. However I've seen well-established packages such as scikit-learn that have hyphens in their name. One thing that I have noticed though is that in the scikit-learn repo, the package name is not the same as the repo name and is instead called sklearn.

我认为以上讨论归结为以下问题:

I think my discussion above boils down to the following questions:

  1. 打包存储库时,存储库名称和软件包名称之间是什么关系?名称不匹配时要注意什么?
  2. 软件包名称中可以使用连字符吗?存储库名称如何?
  3. 如果scikit-learn的软件包名称是sklearn,那么在安装它时为什么会使用pip install scikit-learn而不是pip install sklearn?
  1. When packaging a repo, what is the relationship between the repository's name and the package's name? Is there anything to beware of when having names that don't match?
  2. Is it okay to have hyphens in package names? What about in repository names?
  3. If the package name for scikit-learn is sklearn, then how come when I install it I do pip install scikit-learn instead of pip install sklearn?

推荐答案

回答我的第一点,让我改写我的回答转到另一个问题.

To answer your 1st point let me rephrase my answer to a different question.

造成误解的最大原因是包裹"一词的重载程度很高.游戏中有4种不同的名称-存储库名称,用于开发的目录名称(包含setup.py的目录),包含__init__.py和其他可导入模块的目录的名称,名称在PyPI发行.通常这4个都是相同或相似的,但这不是必需的.

The biggest source of misunderstanding is that the word "package" is heavily overloaded. There are 4 different names in the game — the name of the repository, the name of the directory being used for development (the one that contains setup.py), the name of the directory contained __init__.py and other importable modules, the name of distribution at PyPI. Quite often these 4 are the same or similar but that's not required.

存储库和开发目录的名称可以是任何名称,它们的名称不起作用.当然,正确命名它们很方便,但这只是方便.

The names of the repository and development directory can be any, their names don't play any role. Of course it's convenient to name them properly but that's only convenience.

带有Python文件的目录名称为要导入的包命名.将包命名为要导入后,该名称通常会卡住并且无法更改.

The name of the directory with Python files name the package to be imported. Once the package is named for import the name usually stuck and cannot be changed.

分发的名称在PyPI上显示一页,并且分发文件的名称(源分发,鸡蛋,转盘).这是人们在setup(name='distribution')通话中添加的名称.

The name of the distribution gives one a page at PyPI and the name of distribution files (source distribution, eggs, wheels). It's the name one puts in setup(name='distribution') call.

让我展示详细的真实示例.我一直在维护一个名为 CheetahTemplate 的模板库.我在名为cheetah3/的开发目录中进行开发. PyPI上的发行版称为 Cheetah3 ;这是我在 setup(name='Cheetah3') 中输入的名称.顶层模块是 Cheetah ,因此可以使用import Cheetah.Templatefrom Cheetah import Template;这意味着我有一个目录cheetah3/Cheetah/.

Let me show detailed real example. I've been maintaining a templating library called CheetahTemplate. I develop it in the development directory called cheetah3/. The distribution at PyPI is called Cheetah3; this is the name I put into setup(name='Cheetah3'). The top-level module is Cheetah hence one does import Cheetah.Template or from Cheetah import Template; that means that I have a directory cheetah3/Cheetah/.

2的答案是:您可以在存储库名称和PyPI发行名称中使用破折号,但在包(具有__init__.py文件的目录),模块(.py文件)名称中不能包含破折号,因为您不能用Python ,将其减去并SyntaxError.

The answer to 2 is: you can have dashes in repository names and PyPI distribution names but not in package (directories with __init__.py files) names and module (.py files) names because you cannot write in Python import xy-zzy, that would be subtraction and SyntaxError.

第3点:站点和存储库名称为scikit-learn,以及

Point 3: The site and the repository names are scikit-learn, as well as the distribution name, but the importable package (the top-level directory with __init__.py) is sklearn.

PEP 8与该问题无关,因为它不是在讨论分发,而只是在讨论可导入的程序包和模块.

PEP 8 has nothing to do with the question as it doesn't talk about distribution, only about importable packages and modules.

这篇关于在python存储库名称和包名称中使用连字符/破折号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆