如何打包在python轮perl的文件

问题描述 投票:1回答:1

我们已经创建了具有Python和Perl脚本的集合包装画中画轮文件。因为Python包装将只蟒蛇文件添加到文件轮是什么来包装perl的文件,以及最好的方式。

这是我的项目结构

.
|____myproject
| |____logging.ini
| |____utils.py
| |____myperlscript.pl
| |____config.py
| |____version.py
| |____scripta.py
| |____scriptb.py
| |____scriptc.py
| |______init__.py
|____test
| |____test_scripts.py
|______init__.py
|____MANIFEST.in
|____README.md
|____setup.py
|____.gitignore
|____Jenkinsfile
python perl setuptools distutils python-wheel
1个回答
0
投票

如果您正在使用setuptoolssetup.py为您的项目,并利用python setup.py bdist_wheel,生成.whl文件的方法中,添加以下行到MANIFEST.in文件,该文件已经存在于你的项目的根目录。

recursive-include myproject *

当然,对于实际的顶级目录,其中将包括目标myproject脚本(或任何其他文件)替换.pl

作为演示,如果你的setup.py大约是写像这样:

from setuptools import setup
from setuptools import find_packages

setup(
    name='myproject',
    version='0.0.0',
    description='demo package',
    long_description=open('README.md').read(),
    classifiers=[
        'Programming Language :: Python',
    ],
    packages=find_packages(),
    include_package_data=True,
    zip_safe=False,
)

运行python setup.py bdist_wheel会显示如下所示的输出:

...
adding 'myproject/__init__.py'
adding 'myproject/config.py'
adding 'myproject/logging.ini'
adding 'myproject/myperlscript.pl'
adding 'myproject/scripta.py'
adding 'myproject/utils.py'
adding 'myproject/version.py'
adding 'test/__init__.py'
...

该文件被打包在里面.whl

$ unzip -t dist/myproject-0.0.0-py3-none-any.whl 
Archive:  dist/myproject-0.0.0-py3-none-any.whl
    testing: myproject/__init__.py    OK
    testing: myproject/config.py      OK
    testing: myproject/logging.ini    OK
    testing: myproject/myperlscript.pl   OK
...

在新的环境中安装所产生的.whl文件:

$ pip install -U myproject-0.0.0-py3-none-any.whl 
Processing myproject-0.0.0-py3-none-any.whl
Installing collected packages: myproject
Successfully installed myproject-0.0.0
$ ls env/lib/python3.6/site-packages/myproject/
config.py    logging.ini      __pycache__  utils.py
__init__.py  myperlscript.pl  scripta.py   version.py

还要注意的是,如果MANIFEST.in方法是不需要的,包括对package_data={'': ['*']},呼叫setup说法也应使其与最新版本setuptools的工作。

进一步增编:setuptools包实际上有一个MANIFEST.in包括此特定的语法,但仅限于特定的文件扩展名,因为他们要包含的文件。这显然是尽管一些导游/文档,否则可能会暗示支持的选项。事实上,这是默认附带的Python功能provided by the core distutils module。相关的问题:

© www.soinside.com 2019 - 2024. All rights reserved.