ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

python-应用程序开发人员应如何使用setup.py和requirements.txt?

2019-11-20 23:55:32  阅读:282  来源: 互联网

标签:python-2-7 packaging distutils python


应用程序开发人员应在setup.py和requirements.txt中放置什么?应用程序甚至应该有setup.py吗?

docs似乎仅涵盖编写模块的情况.但是在应用程序中,应该如何对包和模块依赖项进行编码?同时使用setup.py和requirements.txt吗?

我已经得到了一个带有一些可疑代码的2.7.8项目,但是我不确定这个setup.py是否合理.我对大量样板代码感到惊讶:

#!/usr/bin/env python
from setuptools import setup, find_packages
import sys

if sys.argv[1] == 'test':
    import multiprocessing, logging
    from billiard import util

with open('requirements.txt') as f:
    required = f.read().splitlines()

if sys.version_info < (2, 7, 0):
    required.append('importlib')

setup(
    version='0.1',
    name='...',
    description='...',
    author='...',
    author_email='...',
    packages=find_packages(),
    package_data={},
    install_requires=required,
    include_package_data=True,
    tests_require=[
        'billiard',
        'nose==1.3'
    ],
    test_suite='nose.collector'
)

我是Python的新手,但我看到了一些潜在的问题:

>无关的版本号,需要手动更新.
>“测试”导入与项目无关(“多处理”).
>我们不会通过执行setup.py来运行测试;我们执行鼻子测试命令.
> install_requires取决于requirements.txt的内容.但是afaik应该是另一种方式:需要基于install_requires部分生成requirements.txt.
>似乎正在检查该应用未编码为支持的python版本.

解决方法:

An irrelevant version number which needs to be manually updated.

setup.py中的版本号仅在您的应用程序/部署需要时才重要.

The ‘test’ imports aren’t relevant to the project (“multiprocessing”).

在这种情况下,您可能需要删除它-它可能已过时.

We don’t run tests by executing setup.py; we execute the nosetests command.

我必须查找它,但是某些测试框架使用setup.py将项目安装在单独的环境中(例如,用于在各种Python解释器中测试项目的tox).

This depends on the contents of requirements.txt, but afaik it should be the other way around: requirements.txt needs to be generated based on an install_requires section in setup.py

在整个Python社区中,对requirements.txt和setup.py的使用有所不同.到目前为止,setup.py在安装项目时需要知道要求,但是在打算部署应用程序时,您可以不使用setup.py文件而仅使用requirements.txt文件.

There’s no install_requires.

这可能是个问题,具体取决于您是否实际使用setup.py来安装依赖项(如上所述,完全可以在没有setup.py文件的情况下开发和部署应用程序).

It seems to check for a python version which the app isn’t coded to support.

然后,您可能需要将其删除.

标签:python-2-7,packaging,distutils,python
来源: https://codeday.me/bug/20191120/2047952.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有