Skip to content

Commit

Permalink
Adapting git requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
jyejare committed Oct 18, 2024
1 parent dcb9afc commit da7b4a2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
5 changes: 2 additions & 3 deletions pytest_plugins/requirements/req_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class ReqUpdater:
'dynaconf': 'dynaconf[vault]',
'Jinja2': 'jinja2',
'Sphinx': 'sphinx',
'airgun': 'airgun @ git+https://github.com/SatelliteQE/airgun.git@master#egg=airgun',
'nailgun': 'nailgun @ git+https://github.com/SatelliteQE/nailgun.git@master#egg=nailgun',
'pyyaml': 'PyYAML',
}

@cached_property
Expand Down Expand Up @@ -98,7 +97,7 @@ def install_req_deviations(self):
if self.req_deviation:
if (
subprocess.run(
f"{self.packagae_manager} install {' '.join(f'\'{req}\'' for req in self.req_deviation)}",
f"{self.packagae_manager} install {' '.join(f"'{req}'" for req in self.req_deviation)}",
shell=True,
stdout=subprocess.PIPE,
).returncode
Expand Down
35 changes: 30 additions & 5 deletions pytest_plugins/requirements/update_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@
updater = ReqUpdater()


def ignore_git_deviations(deviations):
git_packages = 'nailgun'
_deviations = deviations
for git_pckg in git_packages:
for deviation in deviations:
if git_pckg in deviation:
_deviations.remove(deviation)
break
return _deviations


def git_deviation_filter(deviation):
"""Packages installed from Git branch and the version cant be compared, so ignore them from reporting"""
git_packages = ['nailgun', 'airgun']
return all(git_pckg not in deviation for git_pckg in git_packages)


def pytest_addoption(parser):
"""Options to allow user to update the requirements"""
update_options = {
Expand All @@ -28,22 +45,30 @@ def pytest_report_header(config):
# Following will update the mandatory and optional requirements
# pytest tests/foreman --collect-only --update-all-reqs
"""
if updater.req_deviation:
print(f"Mandatory Requirements Mismatch: {' '.join(updater.req_deviation)}")
req_deviations = updater.req_deviation
if req_deviations:
# req_deviations = ignore_git_deviations(req_deviations)
req_deviations = list(filter(git_deviation_filter, req_deviations))
if req_deviations:
print(f"Mandatory Requirements Mismatch: {' '.join(req_deviations)}")
if config.getoption('update_required_reqs') or config.getoption('update_all_reqs'):
updater.install_req_deviations()
else:
print('Mandatory Requirements are up to date.')

if updater.opt_deviation:
print(f"Optional Requirements Mismatch: {' '.join(updater.opt_deviation)}")
opt_deviations = updater.opt_deviation
if opt_deviations:
# opt_deviations = ignore_git_deviations(opt_deviations)
opt_deviations = list(filter(git_deviation_filter, opt_deviations))
if opt_deviations:
print(f"Optional Requirements Mismatch: {' '.join(updater.opt_deviation)}")
if config.getoption('update_all_reqs'):
updater.install_opt_deviations()
else:
print('Optional Requirements are up to date.')

if updater.req_deviation or updater.opt_deviation:
print(
"To update mismatched requirements, run the pytest command with "
"To update requirements, run the pytest with "
"'--update-required-reqs' OR '--update-all-reqs' option."
)

0 comments on commit da7b4a2

Please sign in to comment.