fades icon indicating copy to clipboard operation
fades copied to clipboard

Support running fades inside a virtualenv

Open judy2k opened this issue 5 years ago • 6 comments

I decided to install fades using the pipx tool, which is a great way of managing various Python executables. Obviously it's not supported - the first time I tried to run a fades script, it told me so - great error reporting!

I've worked around this by following the correct installation instructions, and installed the deb package. But I'd really like to use pipx to install fades instead.

judy2k avatar Oct 07 '20 08:10 judy2k

I'd be happy to do the work on this myself if you'll accept the feature.

If you let me know what's probably going to cause me problems in the implementation, that will help.

judy2k avatar Oct 07 '20 08:10 judy2k

Hello @judy2k, thanks for your time and reporting your experience with fades!

Is it supported to run a virtualenv inside another virtualenv? ("nested", I mean). AFAIK we don't let fades run inside a virtualenv because of that.

facundobatista avatar Oct 07 '20 16:10 facundobatista

It sounds super interesting. I think the challenge is that you are going to be running from a virtualenv.

I think it's not super-hard to get it working but I'm not sure if we want to do it (because it will be kind of a hack)

To give you an idea you can check here https://github.com/PyAr/fades/blob/master/fades/main.py#L201
and here https://github.com/PyAr/fades/blob/master/fades/main.py#L467

Just playing for some time it will probably work but I'm afraid of any other lib making assumptions and it will start crashing.

Other challenge will be the venv creation (fades/envbuilder.py). No idea here, but it's matter of testing.

But thinking in your problem maybe it's a super good idea to use pipx as a lib and ask it to install the python version that you want to use?

in fades you can tell it to use a particular python --python. Following what we did in the past it seems a good idea. I'm thinking in something like

fades --pipx python3.6 -r requirements.txt my_project.py

Do you think it's possible? I don't have experience with pipx, my usual workflow is to install the python version using my distro solution (archlinux) and then ask fades to create the venv using it

Update: I'm reading pipx docs. Thay are also using cowsay as an example XD

gilgamezh avatar Oct 07 '20 18:10 gilgamezh

Thanks for your responses!

The only backing I have right now is that tox also manages virtualenvs, and can also be run from a virtualenv.

I think it's definitely possible that nesting virtualenvs might cause problems. I'm not sure if venv supports it, but IIRC, pew does. That obviously doesn't mean it's a good idea, and when I used pew regularly, I used to avoid nesting a virtualenv inside another.

A better approach would probably be for fades to traverse the tree of virtualenvs that fades is installed within (hopefully not actually nested, but you get the idea) until it finds the original python install, and then to spin off a virtualenv from that. I'm not entirely certain how you do that, but I'm optimistic that it's possible without too much hackery.

I also really like the idea of specifying the version of Python that's required, and having fades identify that and ensure the virtualenv is created from an appropriate Python version.

judy2k avatar Oct 08 '20 19:10 judy2k

It's worth noting that pipx doesn't install python at all, it just creates a virtualenv for each library/utility you've asked it to install, and then ensures that the executables are "linked" to that virtualenv so when you run them they run within their own personal virtualenv automatically.

judy2k avatar Oct 08 '20 19:10 judy2k

Related: instead of "pipx installing" foo, and then having foo (running from a virtualenv) in my PATH, I got used to put in my bashrc something like alias foo=fades -d foo -x foo. The good thing in my solution is that when I install a new machine and I bring my bashrc, the moment I call "foo" it will make fades to create the virtualenv and it just will work (no need to install it previously!).

facundobatista avatar Oct 10 '20 16:10 facundobatista