Skip to content

Commit

Permalink
Update update-sanity-requirements.py script (ansible#81424)
Browse files Browse the repository at this point in the history
Frozen requirements can now preserve any explicitly installed package that would normally be omitted, not just setuptools.
  • Loading branch information
mattclay authored Aug 3, 2023
1 parent 2ebeb43 commit dbb3fed
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions hacking/update-sanity-requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import packaging.version
import packaging.specifiers
import packaging.requirements

try:
import argcomplete
Expand All @@ -34,6 +35,11 @@ class SanityTest:
source_path: pathlib.Path

def freeze_requirements(self) -> None:
source_requirements = [packaging.requirements.Requirement(re.sub(' #.*$', '', line)) for line in self.source_path.read_text().splitlines()]

install_packages = {requirement.name for requirement in source_requirements}
exclude_packages = {'distribute', 'pip', 'setuptools', 'wheel'} - install_packages

with tempfile.TemporaryDirectory() as venv_dir:
venv.create(venv_dir, with_pip=True)

Expand All @@ -49,13 +55,6 @@ def freeze_requirements(self) -> None:
subprocess.run(pip + ['install', 'wheel'], env=env, check=True) # make bdist_wheel available during pip install
subprocess.run(pip + ['install', '-r', self.source_path], env=env, check=True)

keep_setuptools = any(line.startswith('setuptools ') for line in self.source_path.read_text().splitlines())

exclude_packages = ['pip', 'distribute', 'wheel']

if not keep_setuptools:
exclude_packages.append('setuptools')

freeze_options = ['--all']

for exclude_package in exclude_packages:
Expand Down

0 comments on commit dbb3fed

Please sign in to comment.