Python“ setup.py开发”:是否可以创建“ .egg-info”?文件夹不在源代码文件夹中? [英] Python "setup.py develop": is it possible to create ".egg-info" folder not in source code folder?

查看:154
本文介绍了Python“ setup.py开发”:是否可以创建“ .egg-info”?文件夹不在源代码文件夹中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python可以通过运行 setup.py 脚本并使用 develop 而不是安装。这会修改python环境,因此可以从当前位置导入包(不会将其复制到 site-package 目录中)。这样就可以开发供其他软件包使用的软件包:通过简单的 import 修改源代码,并在其余python代码中进行更改。



除了 setup.py development 命令创建 .egg-info 文件夹,其元数据与 setup.py 处于同一级别。混合源代码和临时文件不是一个好主意-需要将该文件夹添加到从vcs到结束备份系统的多个工具的忽略列表中。



是可以使用 setup.py开发,但可以在其他位置创建 .egg-info 目录,因此原始源代码是不是被临时目录和文件污染了?

解决方案

setup.py开发就地创建一个python鸡蛋;它确实 [修改] python环境,以便可以从其当前位置导入包。您仍然必须将其位置添加到python搜索路径中,或将其位置用作当前目录。



这是<$ c的工作$ c> develop 命令创建一个就地鸡蛋,其中可能包括编译C扩展,运行2to3 python转换过程以创建Python3兼容代码以及提供元数据 other 可能依赖python代码。当您将软件包作为鸡蛋安装在 site-packages 目录中时,相同的元数据也将包含在其中。数据当然不是临时的(从 setup.py 文件中提取出来,以便于其他工具轻松解析)。



<目的是,当您在更广泛的系统中使用软件包时,可以依靠该元数据,而该系统依赖于存在的元数据,同时仍在开发软件包。例如,在 buildout 开发部署中,我们经常使用 mr.developer 可以使我们在获取给定包的源代码时自动化需要进行处理,将其作为开发工具构建并在我们处理代码时将其绑定到部署中。



请注意, .egg-info 目录用于特定目的:向setuptools生态系统中的其他工具发送信号,表明您的软件包已安装且可用。如果您的程序包是安装程序中另一个egg的依赖项,则可以满足该依赖项。 pip easy_install 和附加内容不会尝试从其他位置获取鸡蛋。



除创建 .egg-info 目录外,该命令唯一执行的 other 任务是构建扩展, 到位。因此,您要查找的命令是:

  setup.py build_ext --inplace 

这将与 setup.py开发完全相同,但是省略了 .egg-info 目录。它也不会生成 .pth 文件。



无法仅生成 .pth 文件,而忽略 .egg-info 目录生成。



从技术上讲, setup.py开发还将检查您是否具有设置工具 site.py 已安装文件以支持命名空间包,但这与此处无关。


Python has ability to "pseudoinstall" a package by running it's setup.py script with develop instead of install. This modifies python environment so package can be imported from it's current location (it's not copied into site-package directory). This allows to develop packages that are used by other packages: source code is modified in place and changes are available to rest of python code via simple import.

All works fine except that setup.py develop command creates an .egg-info folder with metadata at same level as setup.py. Mixing source code and temporary files is not very good idea - this folder need to be added into "ignore" lists of multiple tools starting from vcs and ending backup systems.

Is it possible to use setup.py develop but create .egg-info directory in some other place, so original source code is not polluted by temporary directory and files?

解决方案

setup.py develop creates a python egg, in-place; it does not [modify the] python environment so package can be imported from it's current location. You still have to either add it's location to the python search path or use the directory it is placed in as the current directory.

It is the job of the develop command to create an in-place egg, which may include compiling C extensions, running the 2to3 python conversion process to create Python3 compatible code, and to provide metadata other python code may be relying on. When you install the package as an egg in your site-packages directory, the same metadata is included there as well. The data is certainly not temporary (it is extracted from your setup.py file for easy parsing by other tools).

The intent is that you can then rely on that metadata when using your package in a wider system that relies on the metadata being present, while still developing the package. For example, in a buildout development deployment, we often use mr.developer to automate the process of fetching the source code for a given package when we need to work on it, which builds it as a develop egg and ties it into the deployment while we work on the code.

Note that the .egg-info directory serves a specific purpose: to signal to other tools in the setuptools eco-system that your package is installed and available. If your package is a dependency of another egg in your setup, then that dependency is satisfied. pip and easy_install and buildout will not try and fetch the egg from somewhere else instead.

Apart from creating the .egg-info directory, the only other thing the command does, is to build extensions, in-place. So the command you are looking for instead is:

setup.py build_ext --inplace

This will do the exact same thing as setup.py develop but leave out the .egg-info directory. It also won't generate the .pth file.

There is no way of generating only the .pth file and leave out the .egg-info directory generation.

Technically speaking, setup.py develop will also check if you have the setuptools site.py file installed to support namespaced packages, but that's not relevant here.

这篇关于Python“ setup.py开发”:是否可以创建“ .egg-info”?文件夹不在源代码文件夹中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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