如何制作 pip 安装包数据(配置文件)? [英] How can I make pip install package data (a config file)?

查看:69
本文介绍了如何制作 pip 安装包数据(配置文件)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 clana 的包(Github, Github, Github="https://pypi.org/project/clana/" rel="nofollow noreferrer">PyPI) 具有以下结构:

<预><代码>.├── 部落│ ├── cli.py│ ├── config.yaml│ ├── __init__.py│ ├── utils.py│ └──visualize_predictions.py├── 文档/├── setup.cfg├── setup.py├──测试/└── tox.ini

setup.py 看起来像这样:

from setuptools import find_packages从 setuptools 导入设置requires_tests = [...]install_requires = [...]配置 = {"name": "部落",版本":0.3.6","author": "Martin Thoma","author_email": "info@martin-thoma.de","maintainer": "Martin Thoma","maintainer_email": "info@martin-thoma.de",包":find_packages(),entry_points":{console_scripts":[clana=clana.cli:entry_point"]},安装要求":安装要求,tests_require":requires_tests,package_data":{clana":[clana/config.yaml"]},include_package_data":真,zip_safe":错误,}设置(**配置)

如何检查它是否不起作用

快速

python3 setup.py sdistopen dist/clana-0.3.8.tar.gz # config.yaml 不在这个文件中

真正的检查

我认为这将确保安装包时 config.yamlcli.py 位于同一目录中.但是当我尝试这个时:

virtualenv venv源 venv/bin/激活pip 安装 clanacd venv/lib/python3.6/site-packages/clanals

我明白了:

cli.py __init__.py __pycache__ utils.pyvisualize_predictions.py

我上传到 PyPI 的方式:

python3 setup.py sdist bdist_wheel &&麻线上传dist/*

所以 config.yaml 丢失了.我如何确定它在那里?

解决方案

您可以在 setup.py 旁边添加一个文件名 MANIFEST.in,其中包含要添加的文件,允许通配符(例如:include *.yamlinclude clana/config.yaml)然后选项 include_package_data=True 将激活清单文件

I have a package called clana (Github, PyPI) with the following structure:

.
├── clana
│   ├── cli.py
│   ├── config.yaml
│   ├── __init__.py
│   ├── utils.py
│   └── visualize_predictions.py
├── docs/
├── setup.cfg
├── setup.py
├── tests/
└── tox.ini

The setup.py looks like this:

from setuptools import find_packages
from setuptools import setup

requires_tests = [...]

install_requires = [...]


config = {
    "name": "clana",
    "version": "0.3.6",
    "author": "Martin Thoma",
    "author_email": "info@martin-thoma.de",
    "maintainer": "Martin Thoma",
    "maintainer_email": "info@martin-thoma.de",
    "packages": find_packages(),
    "entry_points": {"console_scripts": ["clana=clana.cli:entry_point"]},
    "install_requires": install_requires,
    "tests_require": requires_tests,
    "package_data": {"clana": ["clana/config.yaml"]},
    "include_package_data": True,
    "zip_safe": False,
}

setup(**config)

How to check that it didn't work

Quick

python3 setup.py sdist
open dist/clana-0.3.8.tar.gz  # config.yaml is not in this file

The real check

I thought this would make sure that the config.yaml is in the same directory as the cli.py when the package is installed. But when I try this:

virtualenv venv
source venv/bin/activate
pip install clana
cd venv/lib/python3.6/site-packages/clana
ls

I get:

cli.py  __init__.py  __pycache__  utils.py  visualize_predictions.py

The way I upload it to PyPI:

python3 setup.py sdist bdist_wheel && twine upload dist/*

So the config.yaml is missing. How can I make sure it is there?

解决方案

You can add a file name MANIFEST.in next to setup.py with a list of the file you want to add, wildcard allowed (ex: include *.yaml or include clana/config.yaml) then the option include_package_data=True will activate the manifest file

这篇关于如何制作 pip 安装包数据(配置文件)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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