从任意 VCS 存储库安装 python 模块的最佳实践

发布于 2024-09-04 06:44:46 字数 416 浏览 4 评论 0 原文

我对 python 生态系统很陌生,并且有一个关于模块编辑的问题。

我使用了一堆分布在 PyPi 上的第三方模块。我有 C 和 Java 背景,喜欢 easy_install 的易用性。这是一个新的、美妙的世界,但是当我想编辑新安装的模块时,模型崩溃了,原因有两个:

  1. egg 文件可能存储在文件系统上某个疯狂的文件夹或存档中。
  2. 使用egg 似乎会妨碍使用原始项目的版本控制系统,就像使用 debian 包会妨碍从原始 VCS 存储库进行开发一样。

从任意 VCS 存储库安装模块的最佳实践是什么?我希望能够继续在其他脚本中导入 foomodule 。如果我修改模块的源代码,我是否需要执行任何其他命令?

I'm newish to the python ecosystem, and have a question about module editing.

I use a bunch of third-party modules, distributed on PyPi. Coming from a C and Java background, I love the ease of easy_install <whatever>. This is a new, wonderful world, but the model breaks down when I want to edit the newly installed module for two reasons:

  1. The egg files may be stored in a folder or archive somewhere crazy on the file system.
  2. Using an egg seems to preclude using the version control system of the originating project, just as using a debian package precludes development from an originating VCS repository.

What is the best practice for installing modules from an arbitrary VCS repository? I want to be able to continue to import foomodule in other scripts. And if I modify the module's source code, will I need to perform any additional commands?

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

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

发布评论

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

评论(4

╭⌒浅淡时光〆 2024-09-11 06:44:46

Pip 允许您安装文件,提供 Subversion、git、Mercurial 或 bzr 存储库的 URL。

pip install -e svn+http://path_to_some_svn/repo#egg=package_name

例子:
pip install -e hg+https://[电子邮件受保护]/ianb/cmdutils#egg=cmdutils

如果我想下载最新版本的 cmdutils。 (我决定拉随机包)。

我将其安装到 virtualenv 中(使用 -E 参数),并将 cmdutls pip 安装到 virtualenv 文件夹顶层的 src 文件夹中。

pip install -E thisIsATest -e hg+https://[email protected]/ianb/cmdutils#egg=cmdutils

$  ls thisIsATest/src
cmdutils

Pip lets you install files gives a URL to the Subversion, git, Mercurial or bzr repository.

pip install -e svn+http://path_to_some_svn/repo#egg=package_name

Example:
pip install -e hg+https://[email protected]/ianb/cmdutils#egg=cmdutils

If I wanted to download the latest version of cmdutils. (Random package I decided to pull).

I installed this into a virtualenv (using the -E parameter), and pip installed cmdutls into a src folder at the top level of my virtualenv folder.

pip install -E thisIsATest -e hg+https://[email protected]/ianb/cmdutils#egg=cmdutils

$  ls thisIsATest/src
cmdutils
少女情怀诗 2024-09-11 06:44:46

您是否想要进行开发,但让系统将开发的版本作为鸡蛋处理(例如获取入口点)?如果是这样,那么您应该检查源代码并使用开发模式,方法是:

python setup.py develop

如果项目碰巧不是基于 setuptools 的项目(这是上述所需的),则可以使用以下命令快速解决此问题:

python -c "import setuptools; execfile('setup.py')" develop

几乎所有您想了解的有关 setuptools(easy_install 的基础)的信息都可以从 setuptools 文档。另外还有easy_install 文档

开发模式以与 easy_install 相同的方式将项目添加到导入路径。您所做的更改将在您的应用程序下次导入模块时可用。

正如其他人提到的,如果您只想获取最新版本,但无法编辑,您也可以直接使用版本控制 URL,但这只会拍摄快照,并且确实会创建一个普通的 Egg 作为该过程的一部分。我确信它可以支持 Subversion,并且我认为它也可以支持其他版本,但我找不到相关文档。

Are you wanting to do development but have the developed version be handled as an egg by the system (for instance to get entry-points)? If so then you should check out the source and use Development Mode by doing:

python setup.py develop

If the project happens to not be a setuptools based project, which is required for the above, a quick work-around is this command:

python -c "import setuptools; execfile('setup.py')" develop

Almost everything you ever wanted to know about setuptools (the basis of easy_install) is available from the the setuptools docs. Also there are docs for easy_install.

Development mode adds the project to your import path in the same way that easy_install does. An changes you make will be available to your apps the next time they import the module.

As others mentioned, you can also directly use version control URLs if you just want to get the latest version as it is now without the ability to edit, but that will only take a snapshot, and indeed creates a normal egg as part of the process. I know for sure it does Subversion and I thought it did others but I can't find the docs on that.

情愿 2024-09-11 06:44:46

您可以使用 PYTHONPATH 环境变量或者将您的代码符号链接到站点包中的某个位置。

You can use the PYTHONPATH environment variable or symlink your code to somewhere in site-packages.

红尘作伴 2024-09-11 06:44:46

easy_install 安装的包往往来自开发者版本控制的快照,通常是在开发者发布正式版本时制作的。因此,您必须在通过 easy_install 方便的自动下载和通过版本控制的最新代码更新之间进行选择。如果您选择后者,则可以通过运行 python setup.py install 直接从版本控制检查中构建和安装在 python 包索引中看到的大多数包。

如果您不喜欢默认安装目录,可以安装到自定义位置,并导出一个 PYTHONPATH 环境变量,其值为已安装包的父文件夹的路径。

Packages installed by easy_install tend to come from snapshots of the developer's version control, generally made when the developer releases an official version. You're therefore going to have to choose between convenient automatic downloads via easy_install and up-to-the-minute code updates via version control. If you pick the latter, you can build and install most packages seen in the python package index directly from a version control checkout by running python setup.py install.

If you don't like the default installation directory, you can install to a custom location instead, and export a PYTHONPATH environment variable whose value is the path of the installed package's parent folder.

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