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] virtualenv.managed broken because of yanked setuptools #61424

Closed
vdloo opened this issue Jan 6, 2022 · 2 comments
Closed

[BUG] virtualenv.managed broken because of yanked setuptools #61424

vdloo opened this issue Jan 6, 2022 · 2 comments
Assignees
Labels
Bug broken, incorrect, or confusing behavior needs-triage

Comments

@vdloo
Copy link
Contributor

vdloo commented Jan 6, 2022

We noticed that this setuptools issue pypa/setuptools#3002 also affected the pip module in saltstack today:

return [os.path.normpath(sys.executable), "-m", "pip"]

with a sufficiently old version of virtualenv the yanked metadata isn't handled and the salt module will error with:

          ID: ensure somepackage python virtualenv
    Function: virtualenv.managed
        Name: /usr/local/venv/somepackage
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python3/dist-packages/salt/state.py", line 2154, in call
                  *cdata["args"], **cdata["kwargs"]
                File "/usr/lib/python3/dist-packages/salt/loader.py", line 2106, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/states/virtualenv_mod.py", line 298, in managed
                  before = set(__salt__["pip.freeze"](bin_env=name, user=user, use_vt=use_vt))
                File "/usr/lib/python3/dist-packages/salt/modules/pip.py", line 1209, in freeze
                  cur_version = version(bin_env, cwd)
                File "/usr/lib/python3/dist-packages/salt/modules/pip.py", line 1336, in version
                  raise CommandNotFoundError("Could not find a `pip` binary")
              salt.exceptions.CommandNotFoundError: Could not find a `pip` binary

for something like:

ensure python virtualenv directory:
  file.directory:
    - name: /usr/local/venv/somepackage
    - user: root
    - group: root
    - mode: 0755
    - makedirs: true

ensure somepackage python virtualenv:
  virtualenv.managed:
    - name: /usr/local/venv/somepackage
    - system_site_package: false
    - python: /usr//bin/python3.7
    - pip_pkgs:
      - something
  require:
    - file: /usr/local/venv/somepackage

because it does python -m pip.

a temporary workaround is to pin setuptools to 60.2.0 manually before using virtualenv.managed to install any pip pkgs:

ensure python virtualenv directory:
  file.directory:
    - name: /usr/local/venv/somepackage
    - user: root
    - group: root
    - mode: 0755
    - makedirs: true

ensure somepackage python virtualenv:
  virtualenv.managed:
    - name: /usr/local/venv/somepackage
    - system_site_package: false
    - python: /usr//bin/python3.7
  require:
    - file: /usr/local/venv/somepackage

pin setuptools in virtualenv:
  cmd.run:
    - name: /usr/local/venv/somepackage/bin/pip install --upgrade setuptools==60.2.0
  require:
    - virtualenv: /usr/local/venv/somepackage

install dependencies in virtualenv:
  virtualenv.managed:
    - name: /usr/local/venv/somepackage
    - system_site_package: false
    - python: /usr//bin/python3.7
    - pip_pkgs:
      - something
  require:
    - virtualenv: /usr/local/venv/somepackage

the setuptools people will probably publish a new not broken version soon and this won't be a problem anymore, but in the mean time I wanted to report this here in case people are running into this issue and are looking for answers on google.

@vdloo vdloo added Bug broken, incorrect, or confusing behavior needs-triage labels Jan 6, 2022
@hybby
Copy link

hybby commented Jan 6, 2022

Thanks for this, I've just been debugging the same thing for the past couple of hours and came to the exact same conclusion (and solution) as you. Appreciate the time you've taken to document this, and glad it wasn't just me. :)

@vdloo
Copy link
Contributor Author

vdloo commented Jan 7, 2022

closing because setuptools 60.3.1 is out and this is no longer an issue

@vdloo vdloo closed this as completed Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior needs-triage
Projects
None yet
Development

No branches or pull requests

3 participants