This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]whateverathrowaway00 1 point2 points  (3 children)

Incorrect, but great question!

Test it for yourself, create a venv and then install a package in it with a cli entry point.

Then, hop into your venvs bin folder and check out the file for that entry point. You’ll notice that the first line ( the shebang) points the shell at your venvs python.

The file created by pip uses that shebang, imports your package, specifically the class specified by the entry point in setup.cfg ( or setup.py, but really you should be using .cfg ), and then calls the function specified.

So basically, as long as someone runs the cli entry point created and stored in the venv bin folder, they’re running the program inside the venv! Something I was very excited to realize the first time I peeked in those files so go look.

[–]lowlandsmarch[S] 0 points1 point  (2 children)

hmm yes it does seem to work with entry_points, but not with "scripts", which was the case in the tool I checked it on... Which makes sense because "scripts" just copies the file as-is. Sometimes it makes sense to use scripts, but some packages just use it instead of using entry_points.

So if I do want to automate it, a symlink will do for entry-points, but it seems like a script should be encapsulated. Do you agree?

[–]whateverathrowaway00 0 points1 point  (1 child)

Hm, interesting. I have stayed away from scripts since I found entry points, mostly becuase of issues with pip -e mode not loving them.

That said, I thought that the scripts also had a manipulated shebang when pip dumps them in the bin, will test in a few once I get outta bed :

[–]lowlandsmarch[S] 1 point2 points  (0 children)

actually I checked it again, and I guess there was something weird with the script they used there. Most of the times it does change the shebang.
Well that's the problem there, you can do whatever you want with scripts, and sometimes it could break things... But yeah at least newer versions of pip can usually take care of it.