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] Pip doesn't support programmatic usage #60635

Open
dwoz opened this issue Jul 27, 2021 · 2 comments
Open

[BUG] Pip doesn't support programmatic usage #60635

dwoz opened this issue Jul 27, 2021 · 2 comments
Labels
Bug broken, incorrect, or confusing behavior
Milestone

Comments

@dwoz
Copy link
Contributor

dwoz commented Jul 27, 2021

Description

The maintainers of pip have had a pretty strong stance that pip should not be imported and used pragmatically. https://pip.pypa.io/en/stable/user_guide/#using-pip-from-your-program

We should try and comply with their policy. There are only a couple places where we import pip today.

The biggest offender is in salt/states/pip_state.py https://github.com/saltstack/salt/blob/master/salt/states/pip_state.py#L122
It looks like we have enough support in salt.utils to be able to handle the requirements version parsing ourselves. Then we should be shelling out to install the packages. This is a more complete fix to avoid potential breakage in the future see #60626 and pypa/pip#10212

Another place we are importing pip is in salt/cloud/deploy/bootstrap-salt.sh
https://github.com/saltstack/salt/blob/master/salt/cloud/deploy/bootstrap-salt.sh#L2702
From the looks of it, this code is less prone to breakage but we should evaluate if there are any options other than importing pip.

@dwoz dwoz added Bug broken, incorrect, or confusing behavior needs-triage and removed needs-triage labels Jul 27, 2021
@dwoz dwoz removed the needs-triage label Jul 27, 2021
@sagetherage sagetherage added this to the Approved milestone Jul 27, 2021
@dwoz dwoz assigned s0undt3ch and unassigned sagetherage Jul 28, 2021
@OrangeDog
Copy link
Contributor

For some tasks, there is a library requirementslib that is safe to import and use.

@s0undt3ch
Copy link
Collaborator

For the bootstrap side we could either use subprocess or even pass the output of pip --version to the script and then get the version using something like regex = re.compile("(:?pip )?(?P<version>(:?[\d]+)(:?\.[\d]+)?(:?\.[\d]+)?)(:?.*)?") and do the comparison

@s0undt3ch s0undt3ch removed their assignment Jun 4, 2024
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
Projects
None yet
Development

No branches or pull requests

4 participants