Skip to content

Commit

Permalink
Account for PEP668 in pip invocations
Browse files Browse the repository at this point in the history
Set the PIP_BREAK_SYSTEM_PACKAGES environment variable anywhere
pip is in use to account for PEP668 which would change pip to not
allow us to install in the system environment for newer versions of
pip.
  • Loading branch information
Shrews committed Oct 20, 2023
1 parent 4d15d2b commit c132dde
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ansible_builder/_target_scripts/assemble
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
# at build time.
set -ex

# Account for PEP668
export PIP_BREAK_SYSTEM_PACKAGES=1

RELEASE=$(source /etc/os-release; echo $ID)

# NOTE(pabelanger): Allow users to force either microdnf or dnf as a package
Expand Down
4 changes: 4 additions & 0 deletions src/ansible_builder/_target_scripts/install-from-bindep
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
# limitations under the License.

set -ex

# Account for PEP668
export PIP_BREAK_SYSTEM_PACKAGES=1

# NOTE(pabelanger): Allow users to force either microdnf or dnf as a package
# manager.
PKGMGR="${PKGMGR:-}"
Expand Down
4 changes: 4 additions & 0 deletions src/ansible_builder/containerfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ def _insert_global_args(self, include_values: bool = False) -> None:
self.steps.append(f'ARG {arg}="{value}"')
else:
self.steps.append(f"ARG {arg}")

# To account for PEP668 (https://peps.python.org/pep-0668/), always set this
# pip environment variable for every EE version in every stage.
self.steps.append("ENV PIP_BREAK_SYSTEM_PACKAGES=1")
self.steps.append("")

def _create_folder_copy_files(self) -> None:
Expand Down
47 changes: 47 additions & 0 deletions test/unit/test_containerfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,50 @@ def test__handle_additional_build_files(build_dir_and_ee_yml):
config_dir = tmpdir / '_build' / 'configs'
assert config_dir.exists()
assert (config_dir / 'ansible.cfg').exists()


def test_pep668_env_var_v1(build_dir_and_ee_yml):
"""
Test that we add the pip env var to handle PEP668.
"""
ee_data = """
version: 1
"""
tmpdir, ee_path = build_dir_and_ee_yml(ee_data)
c = make_containerfile(tmpdir, ee_path, run_validate=True)
c.prepare()
assert "ENV PIP_BREAK_SYSTEM_PACKAGES=1" in c.steps


def test_pep668_env_var_v2(build_dir_and_ee_yml):
"""
Test that we add the pip env var to handle PEP668.
"""
ee_data = """
version: 2
images:
base_image:
name: quay.io/user/mycustombaseimage:latest
builder_image:
name: quay.io/user/mycustombuilderimage:latest
"""
tmpdir, ee_path = build_dir_and_ee_yml(ee_data)
c = make_containerfile(tmpdir, ee_path, run_validate=True)
c.prepare()
assert "ENV PIP_BREAK_SYSTEM_PACKAGES=1" in c.steps


def test_pep668_env_var_v3(build_dir_and_ee_yml):
"""
Test that we add the pip env var to handle PEP668.
"""
ee_data = """
version: 3
images:
base_image:
name: quay.io/user/mycustombaseimage:latest
"""
tmpdir, ee_path = build_dir_and_ee_yml(ee_data)
c = make_containerfile(tmpdir, ee_path, run_validate=True)
c.prepare()
assert "ENV PIP_BREAK_SYSTEM_PACKAGES=1" in c.steps

0 comments on commit c132dde

Please sign in to comment.