我想要一些关于将它打包成鸡蛋并将其上传到pypi的建议

Geo*_*Geo 2 python distutils egg setuptools pypi

我写了一些代码,我想打包成鸡蛋.这是我的目录结构:

src/
src/tests
src/tests/test.py # this has several tests for the movie name parser
src/torrent
src/torrent/__init__.py
src/torrent/movienameparser
src/torrent/movienameparser/__init__.py # this contains the code

我想将这个目录结构打包为一个egg,并包含测试文件.我应该在setup.py文件中包含什么内容,以便我可以拥有任意数量的命名空间和任意数量的测试?

这是我想分享的第一个开源代码.即使可能,我将是唯一一个会发现这个模块有用的人,我想上传它pypi.我可以使用哪种许可证,允许用户使用代码执行他们想要的操作,对重新分发,修改没有限制?

即使我计划更新这个鸡蛋,我也不想对任何事情负责(例如为用户提供支持).我知道这可能听起来很自私,但这是我的第一个开源代码,所以请耐心等待.我是否需要提供许可证副本?我在哪里可以找到副本?

感谢阅读所有这些.

Pav*_*pin 6

我不会在这里讨论许可讨论,但通常会在您的软件包源代码的根目录中包含LICENSE文件,以及其他常见的东西,如README等.

我通常以与在目标系统上安装相同的方式组织包.这里解释标准包布局约定.

例如,如果我的包是'torrent'并且它有几个子包,例如'tests'和'util',那么源代码树将如下所示:

workspace/torrent/setup.py
workspace/torrent/torrent/__init__.py
workspace/torrent/torrent/foo.py
workspace/torrent/torrent/bar.py
workspace/torrent/torrent/...
workspace/torrent/torrent/tests/__init__.py
workspace/torrent/torrent/tests/test.py
workspace/torrent/torrent/tests/...
workspace/torrent/torrent/util/__init__.py
workspace/torrent/torrent/util/helper1.py
workspace/torrent/torrent/util/...

这个'洪流/洪流'位似乎是多余的,但这是这个标准惯例的副作用以及Python导入的工作方式.

这是极简主义setup.py(有关如何编写安装脚本的更多信息):

#!/usr/bin/env python

from distutils.core import setup

setup(name='torrent',
      version='0.1',
      description='would be nice',
      packages=['torrent', 'torrent.tests', 'torrent.util']
)
Run Code Online (Sandbox Code Playgroud)

要获得源发行版,我会这样做:

$ cd workspace/torrent
$ ./setup.py sdist

此发行版(dist/torrent-0.1.tar.gz)将使用它自己的,只需拆开包装并运行setup.py install或使用easy_installsetuptools工具箱.而且你不必为每个支持的Python版本制作几个"蛋".

如果你真的需要一个鸡蛋,你需要添加一个依赖setuptools你的setup.py,这将引入一个bdist_egg生成鸡蛋的额外子命令.

但是setuptools除了它的产蛋品质之外还有另一个优点,它消除了setup.py使用一个很好的辅助函数枚举包中的需要find_packages:

#!/usr/bin/env python

from setuptools import setup, find_packages

setup(name='torrent',
      version='0.1',
      description='would be nice',
      packages=find_packages()
)
Run Code Online (Sandbox Code Playgroud)

然后,为了获得"鸡蛋",我会做:

$ cd workspace
$ ./setup.py bdist_egg

...它会给我一个鸡蛋文件: dist/torrent-0.1-py2.6.egg

注意py2.6后缀,这是因为在我的机器上我有Python 2.6.如果你想取悦很多人,你需要为每个主要的Python版本发布一个鸡蛋.你不希望成群的Python 2.5人员在你家门口就有斧头和长矛,对吗?

但是你不必建立一个鸡蛋,你仍然可以使用sdist子命令.

更新:这是Python文档中另一个有用的页面,Distutils从用户的角度介绍.