- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我写了一些我想打包成鸡蛋的代码。这是我的目录结构:
src/src/testssrc/tests/test.py # this has several tests for the movie name parsersrc/torrentsrc/torrent/__init__.pysrc/torrent/movienameparsersrc/torrent/movienameparser/__init__.py # this contains the code
我想把这个目录结构打包成一个egg,并包含测试文件。我应该在 setup.py
文件中包含什么,以便我可以拥有任意数量的命名空间和任意数量的测试?
这是我要分享的第一个开源代码。尽管可能只有我会发现这个模块有用,但我还是想将它上传到 pypi
。我可以使用什么许可证来允许用户对代码做他们想做的事情,对再分发、修改没有限制?
即使我计划更新这个蛋,我也不想对任何事情负责(比如为用户提供支持)。我知道这听起来可能很自私,但这是我的第一个开源代码,所以请多多包涵。我需要提供许可证副本吗?我在哪里可以找到副本?
感谢阅读所有这些。
最佳答案
我不会在这里讨论许可问题,但通常在包源代码的根目录中包含 LICENSE 文件,以及其他常见的东西,如 README 等。
我通常按照在目标系统上安装包的方式来组织包。解释了标准包布局约定 here.
例如,如果我的包是“torrent”并且它有几个子包,例如“tests”和“util”,源代码树如下所示:
workspace/torrent/setup.pyworkspace/torrent/torrent/__init__.pyworkspace/torrent/torrent/foo.pyworkspace/torrent/torrent/bar.pyworkspace/torrent/torrent/...workspace/torrent/torrent/tests/__init__.pyworkspace/torrent/torrent/tests/test.pyworkspace/torrent/torrent/tests/...workspace/torrent/torrent/util/__init__.pyworkspace/torrent/torrent/util/helper1.pyworkspace/torrent/torrent/util/...
This 'torrent/torrent' bit seems redundant, but this is the side-effect of this standard convention and of how Python imports work.
Here's the very minimalist setup.py
(more info on how to write the setup script):
#!/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']
)
要获得源发行版,我会这样做:
$ cd workspace/torrent$ ./setup.py sdist
This distro (dist/torrent-0.1.tar.gz
) will be usable on its own, simply by unpacking it and running setup.py install
or by using easy_install
from setuptools
toolkit. And you won't have to make several "eggs" for each supported version of Python.
If you really need an egg, you will need to add a dependency on setuptools
to your setup.py
, which will introduce an additional subcommand bdist_egg
that generates eggs.
But there's another advantage of setuptools
besides its egg-producing-qualities, it removes the need to enumerate packages in your setup.py
with a nice helper function 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()
)
那么,为了得到一个“蛋”,我会做:
$ cd workspace$ ./setup.py bdist_egg
... 它会给我 egg 文件:dist/torrent-0.1-py2.6.egg
注意 py2.6
后缀,这是因为我的机器上有 Python 2.6。如果你想取悦很多人,你需要为每个主要的 Python 版本发布一个 egg。您不希望成群结队的 Python 2.5 人员拿着斧头和长矛出现在您家门口,对吗?
但你不必构建一个 egg,你仍然可以使用 sdist
子命令。
更新:这里是 another useful page在从用户的角度介绍 Distutils
的 Python 文档中。
关于python - 我想要一些关于将其打包为鸡蛋并将其上传到 pypi 的建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1301689/
我是一名优秀的程序员,十分优秀!