pkgxdev / brewkit

build infra & `$ pkg build`
58 stars 18 forks source link

python-venv.py and "v{version}+brewing" errors #286

Open magnusviri opened 9 months ago

magnusviri commented 9 months ago

When building (bk build ...) a python project using python-venv.py, I see this output in the terminal.

DEBUG:root:+TMPDIR=/Users/u0076374/_/pkgx/repos/pantry_mag/builds/github.com__univ-of-utah-marriott-library-apple__jctl-1.1.21/dev.pkgx.python.build bin/pip install /Users/u0076374/_/pkgx/repos/pantry_mag/builds/github.com__univ-of-utah-marriott-library-apple__jctl-1.1.21 --verbose --no-clean --require-virtualenv
Using pip 23.2.1 from /opt/pkgx/github.com/univ-of-utah-marriott-library-apple/jctl/v1.1.21+brewing/venv/lib/python3.12/site-packages/pip

The activate file (/opt/pkgx/github.com/univ-of-utah-marriott-library-apple/jctl/v1.1.21+brewing/venv/bin/activate) points to the path

/opt/pkgx/github.com/univ-of-utah-marriott-library-apple/jctl/v1.1.21+brewing/venv/

But the file system path is

/opt/pkgx/github.com/univ-of-utah-marriott-library-apple/jctl/v1.1.21/venv/ (without the "+brewing").

Thus the venv never activates.

magnusviri commented 9 months ago

It looks like "+brewing" is in all of the venv/bin files.

jhheider commented 9 months ago

hm. python-venv.py might need an update (or a deprecation).

if you compare the stub python-venv.py writes with the one made by python-venv-stubber.sh, you can see it introduces a hard-dependency on the build-time $VIRTUAL_ENV.

Perhaps even better, you might want to switch to the newer bkpyvenv command. It works like this:

  - bkpyvenv stage {{prefix}} {{version}}
  - # do any install steps, pip install, poetry install, etc
  - bkpyvenv seal {{prefix}} name_of_binary

it's more flexible, and allows for finer-grained control of the python interior install processes.

edited to add:

in particular, complex problems can be more easily solved, such as in OCRmyPDF:

    - bkpyvenv stage {{prefix}} {{version}}
    - ${{prefix}}/venv/bin/pip install .
    # pikepdf libs are compiled for MACOSX_DEPLOYMENT_TARGET=12.0
    - run: '{{prefix}}/venv/bin/pip install --no-cache-dir --force-reinstall --no-binary :all: pikepdf'
      if: darwin
    - bkpyvenv seal {{prefix}} ocrmypdf
mxcl commented 9 months ago

Yeah that script needs an update, though probs just use the new two part system since it made the reason you created the .py version obsolete since you can control the pip instantiation now.