make install仅当requirements.txt发生更改时,如何才能运行目标?
我不想每次升级包时都升级make install
我通过创建假文件找到了一些解决方法,_requirements.txt.pyc但又丑又脏。它将拒绝第二次安装piprequirements,因为requirements.txt没有变化
$ make install-pip-requirements \nmake: Nothing to be done for 'install-pip-requirements'.\nRun Code Online (Sandbox Code Playgroud)\n\n但我的目标是:
\n\n# first time,\n$ make install # create virtual environment, install requirements\n\n# second time\n$ make install # detected and skipping creating virtual env,\n # detect that requirements.txt have no changes \n # and skipping installing again all python packages\nmake: Nothing to be done for 'install'.\nRun Code Online (Sandbox Code Playgroud)\n\nPython 包看起来像:
\n\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Makefile\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 README.rst\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 lambda_handler.py\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 requirements.txt\nRun Code Online (Sandbox Code Playgroud)\n\n我正在使用文件Makefile来实现 python 中的一些自动化:
/opt/virtual_env:\n # create virtual env if folder not exists\n python -m venv /opt/virtual_env\n\nvirtual: /opt/virtual_env\n\n# if requirements.txt is modified than execute pip install\n_requirements.txt.pyc: requirements.txt\n /opt/virtual_env/bin/pip install -r --upgrade requirements.txt\n echo > _requirements.txt.pyc\n\nrequirements: SOME MAGIG OR SOME make flags \n pip install -r requirements.txt\n\ninstall-pip-requirements: _requirements.txt.pyc\n\ninstall: virtual requirements\nRun Code Online (Sandbox Code Playgroud)\n\n我确定
\n\n\n\n\n一定是更好的方法
\n
去做这个;)
\n目前不确定它会回答您的问题。更好的方法是使用成熟的 Python PIP 项目模板。
我们使用cookiecutter来通过这个cookiecutter 模板创建一个特定的 pip 包。
它有一个 Makefile,它不会不断地重新安装所有依赖项,并且它利用了Python 毒素,它允许自动在不同的 python 环境中运行项目测试。您仍然可以在 dev virtualenv 中进行开发,但我们仅在添加新包时更新它,其他一切都由 tox 处理。
但是,到目前为止,您所展示的是尝试从头开始编写 Python 构建,这是通过大量项目模板完成的。如果你真的想了解那里发生了什么,你可以分析这些模板。
如下:因为您希望它与 makefile 一起使用,所以我建议--upgrade从 pip 命令中删除该标志。我怀疑您的要求不包括项目运行所需的版本。我们有一个经验,不把版本放在那里可能会严重破坏事情。因此我们的requirements.txt看起来像:
configure==0.5
falcon==0.3.0
futures==3.0.5
gevent==1.1.1
greenlet==0.4.9
gunicorn==19.4.5
hiredis==0.2.0
python-mimeparse==1.5.2
PyYAML==3.11
redis==2.10.5
six==1.10.0
eventlet==0.18.4
Run Code Online (Sandbox Code Playgroud)
使用无原因的要求--upgradepip 只需验证 virtualenv 中的内容和不包含的内容。所有满足所需版本的内容都将被跳过(不下载)。您还可以在需求中引用 git 版本,如下所示:
-e git+http://some-url-here/path-to/repository.git@branch-name-OR-commit-id#egg=package-name-how-to-appear-in-pip-freeze
Run Code Online (Sandbox Code Playgroud)