How to use virtualenv in makefile

后端 未结 8 1071
-上瘾入骨i
-上瘾入骨i 2020-12-24 04:55

I want to perform several operations while working on a specified virtualenv.

For example command

make install

would be equivalent

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-24 05:35

    Normally make runs every command in a recipe in a different subshell. However, setting .ONESHELL: will run all the commands in a recipe in the same subshell, allowing you to activate a virtualenv and then run commands inside it.

    Note that .ONESHELL: applies to the whole Makefile, not just a single recipe. It may change behaviour of existing commands, details of possible errors in the full documentation. This will not let you activate a virtualenv for use outside the Makefile, since the commands are still run inside a subshell.

    Reference documentation: https://www.gnu.org/software/make/manual/html_node/One-Shell.html

    Example:

    .ONESHELL:
    
    .PHONY: install
    install:
        source path/to/virtualenv/bin/activate
        pip install -r requirements.txt
    

提交回复
热议问题