Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Report: cimg/python:x.y is unusable with venv caching #250

Open
christophehenry opened this issue Sep 30, 2024 · 5 comments
Open

Bug Report: cimg/python:x.y is unusable with venv caching #250

christophehenry opened this issue Sep 30, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@christophehenry
Copy link

Describe the bug
Caching venv si common practice as documented. However, on cimg/python, python -m venv venv produces a virtual environment with a symlink to a fixed x.y.z python version (/home/circleci/.pyenv/versions/3.11.10/bin/python for instance on cimg/python:3.11.

This causes . venv/activate to fail with Error: [Errno 2] No such file or directory: 'venv/bin/python' as soon as the image is updated with a new minor Python version.

To Reproduce
Using the following config.yml:

jobs:
  build:
    docker:
      - image: cimg/python:3.11.4
    steps:
      - checkout
      - restore_cache:
          keys:
            - << pipeline.parameters.cache-version >>-{{ checksum "Pipfile.lock" }}
            - << pipeline.parameters.cache-version >>-
      - run:
          name: install dependencies
          command: |
            python -m venv /tmp/venv
            . /tmp/venv/bin/activate
            pip install pipenv
            pipenv install --dev
      - save_cache:
          paths:
            - /tmp/venv
          key: << pipeline.parameters.cache-version >>-{{ checksum "Pipfile.lock" }}

Change the used image from cimg/python:3.11.4 to cimg/python:3.11 and the CI should fail with the No such file or directory error.

Expected behavior
Caching the venv should not make the CI to suddenly fail as soon as the Python minor changes when using cimg/python:x.y.

Workarounds
Use cimg/python:x.y.z instead of cimg/python:x.y wich is inconveniant.

@christophehenry christophehenry added the bug Something isn't working label Sep 30, 2024
@christophehenry
Copy link
Author

IDK how to solve that, though. I couldn't find a way to make python -m venv to use /home/circleci/.pyenv/shims/ rather than /home/circleci/.pyenv/versions/3.11.10/bin/.

@christophehenry christophehenry changed the title Bug Report: using cimg/python:x.y is unusable with venv caching Bug Report: cimg/python:x.y is unusable with venv caching Sep 30, 2024
@cclauss
Copy link

cclauss commented Oct 15, 2024

https://pipenv.pypa.io/en/latest/installation.html#installing-packages-for-your-project

pipenv install requests will automatically create a virtualenv (which is different that Python's builtin venv).

@christophehenry
Copy link
Author

I'm sorry, how does that solve the problem?

@cclauss
Copy link

cclauss commented Oct 15, 2024

      - run:
          name: install dependencies
          command: |
-           python -m venv /tmp/venv
-           . /tmp/venv/bin/activate
-           pip install pipenv
+           pip install --user pipenv
            pipenv install --dev
+           # Look at the logs to see where the `virtualenv` is being created.
      - save_cache:
          paths:
-           - /tmp/venv
+           # We need something related to `virtualenv` here (NOT `venv`)
          key: << pipeline.parameters.cache-version >>-{{ checksum "Pipfile.lock" }}
+         # We need `pipenv run` to access the installed deps.
+         run: pipenv run ABC

@christophehenry
Copy link
Author

That won't work either. pipenv also takes Pyenv's Python as the reference implementation:

$ pipenv install requests
Creating a virtualenv for this project...
Pipfile: /home/circleci/repo/Pipfile
Using /home/circleci/.pyenv/versions/3.11.10/bin/python (3.11.10) to create virtualenv...
  Creating virtual environment...created virtual environment CPython3.11.10.final.0-64 in 848ms
  creator CPython3Posix(dest=/home/circleci/.local/share/virtualenvs/repo-eQF46Ow3, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/circleci/.local/share/virtualenv)
    added seed packages: pip==24.2, setuptools==74.1.2, wheel==0.44.0
  activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator

Successfully created virtual environment!
Virtualenv location: /home/circleci/.local/share/virtualenvs/repo-eQF46Ow3

$ ll ~/.local/share/virtualenvs/repo-eQF46Ow3/bin
python -> /home/circleci/.pyenv/versions/3.11.10/bin/python

And again: if I'm caching that virtualenv, it'll break as soon as the image changed the minor version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants