Setuptools “development” Requirements

会有一股神秘感。 提交于 2019-12-02 17:16:10
Sean

For more info on using setup.py vs requirements.txt, I found this article helpful.

Update: September 2016

I no longer use requirements.txt (see original answer below) for installing development only packages. The prevailing wisdom seems to be that requirements.txt should be used to pin deployments to specific version numbers, typically using pip freeze > requirements.txt. This ensures that the exact same versions of your project's dependencies and also your project's dependencies' dependencies are installed on all of your servers.

I instead use the extras_require option to setup.

requirements = [
    'click',
    'ansible',
    'fabric',
    'gitpython',
    'pyyaml',
    'jinja2',
    'yapsy'
]

setup({
    install_requires=requirements,
    extras_require={
        'dev': [
            'pytest',
            'pytest-pep8',
            'pytest-cov'
        ]
    }
})

Now, to install your package for development, you run pip install -e .[dev]. This installs all the regular required packages and those listed in the dev section of extras_require.

Production installs can still be done with python setup.py install or pip install . (or with a requirements.txt file).

Original Answer

Here is a way to do it that seems to be in keeping with the recommendations I've run into regarding setup.py vs requirements.txt. Specify all your production dependencies in the install_requires parameter of setup.py.

requirements = [
    'click',
    'ansible',
    'fabric',
    'gitpython',
    'pyyaml',
    'jinja2',
    'yapsy'
]

setup({
    # ...
    install_requires=requirements
    # ...
})

Then create a requirements.txt file that instructs pip to install your production dependencies from setup.py as well as your testing dependencies.

-e .

pytest
pytest-pep8
pytest-cov

Now you can install your package for development with pip install -r requirements.txt. The -e . line will install your package and its dependencies from setup.py in development mode. To install on production, you could use python setup.py install or pip install .. This will only install the dependencies listed in setup.py.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!