saltstack / saltstack/salt

[BUG] Pip doesn't support programmatic usage

Open
#60,635 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

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 https://github.com/pypa/pip/issues/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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect imports and package-install handling in salt/states/pip_state.py, then review the pip usage near line 2702 of salt/cloud/deploy/bootstrap-salt.sh. Start by checking the existing salt.utils requirements parsing support and the surrounding deployment flow. Done means both locations avoid direct pip imports while preserving package installation and bootstrap behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, shell
Domain
cloud, devops, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.