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

Normalize python package names during sanitization #359

Merged
merged 1 commit into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ansible_builder/requirements.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import requirements
from pkg_resources import safe_name


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -37,6 +38,8 @@ def sanitize_requirements(collection_py_reqs):
for collection, lines in collection_py_reqs.items():
try:
for req in requirements.parse('\n'.join(lines)):
if req.specifier:
req.name = safe_name(req.name)
req.collections = [collection] # add backref for later
if req.name is None:
consolidated.append(req)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python_dateutil # intentional underscore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pytz
python-dateutil>=2.8.2 # intentional dash
-r extra_req.txt
4 changes: 3 additions & 1 deletion test/integration/test_introspect_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_introspect_write_python(cli, data_dir, tmp_path):
assert dest_file.read_text() == '\n'.join([
'pyvcloud>=14 # from collection test.metadata',
'pytz # from collection test.reqfile',
'python-dateutil>=2.8.2 # from collection test.reqfile',
'tacacs_plus # from collection test.reqfile',
'pyvcloud>=18.0.10 # from collection test.reqfile',
'',
Expand All @@ -48,7 +49,8 @@ def test_introspect_write_python_and_sanitize(cli, data_dir, tmp_path):
assert dest_file.read_text() == '\n'.join([
'pyvcloud>=14,>=18.0.10 # from collection test.metadata,test.reqfile',
'pytz # from collection test.reqfile',
'tacacs_plus # from collection test.reqfile',
'python-dateutil>=2.8.2 # from collection test.reqfile',
'tacacs-plus # from collection test.reqfile',
'',
])

Expand Down
5 changes: 4 additions & 1 deletion test/unit/test_introspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ def test_multiple_collection_metadata(data_dir):
assert files == {'python': [
'pyvcloud>=14,>=18.0.10 # from collection test.metadata,test.reqfile',
'pytz # from collection test.reqfile',
'tacacs_plus # from collection test.reqfile'
# python-dateutil should appear only once even though referenced in
# multiple places, once with a dash and another with an underscore in the name.
'python-dateutil>=2.8.2 # from collection test.reqfile',
'tacacs-plus # from collection test.reqfile'
], 'system': [
'subversion [platform:rpm] # from collection test.bindep',
'subversion [platform:dpkg] # from collection test.bindep'
Expand Down