alan-turing-institute / data-safe-haven

https://data-safe-haven.readthedocs.io
BSD 3-Clause "New" or "Revised" License
57 stars 15 forks source link

Add pip to workspace software #2117

Closed jemrobinson closed 1 month ago

jemrobinson commented 1 month ago

:white_check_mark: Checklist

:vertical_traffic_light: Depends on

n/a

:arrow_heading_up: Summary

Add python3-pip to the workspaces

:closed_umbrella: Related issues

n/a

:microscope: Tests

Not tested

github-actions[bot] commented 1 month ago

Coverage report

This PR does not seem to contain any modification to coverable code.

jemrobinson commented 1 month ago

Sorry, I'm confused here. Isn't this the package that gives you the pip executable? What's that got to do with virtual environments vs. home directories?

JimMadge commented 1 month ago

python-pip provides pip globally and will by default install packages to ~/.local or /usr/.

It shouldn't be needed because we have python-venv which will put pip and setup-tools in a virtual environment when you create it. I think what we want to do is encourage people to always use python -m venv (or hatch, poetry, etc.) then pip inside that venv, never the global pip.

jemrobinson commented 1 month ago

Ah OK. So python-venv also provides pip then? I guess symlinked into the virtualenvs when you create them?

JimMadge commented 1 month ago

Yes, I'm not 100% certain how that works, however the venv has pip and when you activate it pip will be added to your path. So there will be pip in the venv but not globally.

(I think this is why pip always complains about being out of date now, because you have pip pinned to your python distribution so there is likely a newer version on PyPI).

jemrobinson commented 1 month ago

The entire content of the pip executable is just:

#!/home/james.robinson/testvenv/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

so (after testing) it looks like python-venv just writes that to VENV_PATH/bin. It must be installing the pip package to site-packages from somewhere, but I'm not sure where.

jemrobinson commented 1 month ago

Working as intended.