我想要一些关于将其打包为 Egg 并将其上传到 pypi 的建议

发布于 2024-08-01 21:45:21 字数 617 浏览 9 评论 0原文

我写了一些代码,我想将其打包为鸡蛋。 这是我的目录结构:

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 上。 我可以使用什么许可证来允许用户对代码执行他们想要的操作,并且对重新分发和修改没有限制?

尽管我计划更新这个egg,但我不想承担任何责任(例如向用户提供支持)。 我知道这听起来可能很自私,但这是我的第一个开源代码,所以请耐心等待。 我需要提供许可证副本吗? 我在哪里可以找到副本?

感谢您阅读所有这些。

I wrote some code that I'd like to package as an egg. This is my directory structure:

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

I'd like to package this directory structure as an egg, and include the test file too. What should I include in the setup.py file so that I can have any number of namespaces, and any number of tests?

This is the first open source code I'd like to share. Even though, probably, I will be the only one who will find this module useful, I'd like to upload it on pypi. What license can I use that will allow users to do what they want with the code,no limitations upon redistribution,modifications?

Even though I plan on updating this egg, I'd like not to be responsible of anything ( such as providing support to users ). I know this may sound selfish, but this is my first open source code, so please bear with me. Will I need to provide a copy of the license? Where could I find a copy?

Thanks for reading all of this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空心空情空意 2024-08-08 21:45:22

包含来自 setuptools 网站 的 ez_setup 文件,并在 setup.py 顶部包含:

from ez_setup import use_setuptools
use_setuptools()

该脚本对于没有安装工具的人来说是一个帮助者。 它会在未安装 setuptools 的系统上下载并安装最新版本的 setuptools。

Include ez_setup file from setuptools website and include, at the top of your setup.py:

from ez_setup import use_setuptools
use_setuptools()

This script is an helper for people who doesn't have setuptools. It download and install latest version of setuptools on system that do not have setuptools installed.

殤城〤 2024-08-08 21:45:22

最好将其作为 tarball (.tar.gz) 分发,而不是作为 Egg 分发。 Eggs 主要用于二进制分发,例如使用编译的 C 扩展时。 在纯源发行版中,它们只是不必要的复杂性。

如果您只是想将代码发布到世界各地,那么 MIT 或 3 条款 BSD 许可证是最受欢迎的选择。 两者均包含免责声明。 您所要做的就是将主许可证包含在 tarball 中; 通常为“License.txt”或类似名称。 或者,您可以为每个源文件添加一个小的版权通知; 我鼓励这样做,因此即使没有整个存档,每个文件的状态也是显而易见的,但有些人认为这太冗长了。 这是个人喜好的问题。

BSD 许可证可在 Wikipdia 上获取,复制如下:

Copyright (c) <year>, <copyright holder>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the <organization> nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY <copyright holder> ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

It would be better to distribute it as a tarball (.tar.gz), not as an egg. Eggs are primarily for binary distribution, such as when using compiled C extensions. In source-only distributions, they are just unnecessary complexity.

If you just want to throw your code out into the world, the MIT or 3-clause BSD licenses are the most popular choice. Both include disclaimers of liability. All you have to do is include the main license in the tarball; typically as "License.txt", or similar. Optionally, you can add a small copyright notification to each source file; I encourage this, so the status of each file is obvious even without the entire archive, but some people think that's too verbose. It's a matter of personal preference.

The BSD license is available on Wikipdia, copied below:

Copyright (c) <year>, <copyright holder>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the <organization> nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY <copyright holder> ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
倒数 2024-08-08 21:45:21

我不会在这里讨论许可问题,但通常会在包源代码的根目录中包含 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/...

这个“torrent/torrent”位似乎是多余的,但这是副作用这个标准约定以及 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']
)

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

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

该发行版(dist/torrent-0.1.tar.gz)将是可以单独使用,只需解压并运行 setup.py install 或使用 setuptools 工具包中的 easy_install 即可。 而且您不必为每个受支持的 Python 版本制作多个“鸡蛋”。

如果您确实需要一个 Egg,则需要将对 setuptools 的依赖项添加到 setup.py 中,这将引入一个额外的子命令 <​​code>bdist_egg产生鸡蛋。

但是,除了它的鸡蛋生成质量之外,setuptools 还有另一个优点,它消除了使用一个很好的辅助函数 find_packages< 枚举 setup.py 中的包的需要。 /code>:

#!/usr/bin/env python

from setuptools import setup, find_packages

setup(name='torrent',
      version='0.1',
      description='would be nice',
      packages=find_packages()
)

然后,为了获得一个“egg”,我会这样做:

$ cd workspace
$ ./setup.py bdist_egg

... 它会给我 Egg 文件: dist/torrent-0.1-py2.6.egg

注意 < code>py2.6 后缀,这是因为我的机器上有Python 2.6。 如果你想取悦很多人,你需要为每个主要的 Python 版本发布一个 Egg。 您不希望成群结队的拿着斧头和长矛的 Python 2.5 人员出现在您家门口,对吗?

但您不必构建鸡蛋,您仍然可以使用 sdist 子命令。

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

I won't get into licensing discussion here, but it's typical to include LICENSE file at the root of your package source code, along with other customary things like README, etc.

I usually organize packages the same way they will be installed on the target system. The standard package layout convention is explained here.

For example if my package is 'torrent' and it has a couple sub-packages such as 'tests' and 'util', here's the source tree would look like:

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/...

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']
)

To obtain a source distro, I'd then do:

$ 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()
)

Then, to obtain an "egg", I will do:

$ cd workspace
$ ./setup.py bdist_egg

... and it will give me the egg file: dist/torrent-0.1-py2.6.egg

Notice the py2.6 suffix, this is because on my machine I have Python 2.6. If you want to please lots of people, you'd need to publish an egg for each major Python release. You don't want hordes of Python 2.5 folks with axes and spears at your doorstep, do you?

But you don't have to build an egg, you can still use sdist subcommand.

Updated: here's another useful page in Python documentation that introduces Distutils from user's perspective.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文