pyinvoke / invoke

Pythonic task management & command execution.
http://pyinvoke.org
BSD 2-Clause "Simplified" License
4.38k stars 367 forks source link

Dealing with virtual environments #838

Closed g0di closed 2 years ago

g0di commented 2 years ago

Hello folks,

lately I wanted to give a try at invoke to replace GNU Make. However, I’m unsure to understand the way I’m supposed to use it when developing a project in a virtual environment

Should invoke be installed globally or within the virtual environment?

I tried the later but the issue is that I must install invoke in the virtual env, and activate it in order to be able to use it from command line. This is particularly problematic when I want to provide some « install » command allowing developers to quickly setup their development environment.

I also tried the former which sounds bit better but I just encountered a drawback. I can’t use Python dependencies from the virtual environment inside the tasks.py file. This is problematic if I want for example to provide a task using Python requests and it is not installed next to invoke itself.

If someone could bring some light, it could be awesome!

Happy new year everyone

kuwv commented 2 years ago

@g0di

Typically development dependencies are stored within a dev-requirements.txt for tools like invoke. Virtual environments are also the preferred approach. This can be supplemented with a CONTRIBUTING guide to document the project setup procedures.

But, if you want to streamline the process I find both Pipenv and Poetry very useful for this purpose. The former is more so for deployments whereas the latter for libraries.

Both allow you to run commands from outside of the virtual environment:

pipenv run invoke build

or

poetry run invoke build

Hope this helps...

g0di commented 2 years ago

Thank you for your answer. Indeed after some researches I found out that tools like poetry pipenv and pdm should be used for dependencies management so there is no real need of some « install » tasks using invoke. This way, invoke can be just installed as a development dependency using mentioned tools and provide some more powerful task management tool compared to poetry and others which allo to create just simple tasks.

hope this may help other readers if any