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

Do not sanitize user python requirements #336

Merged
merged 2 commits into from
Jan 6, 2022

Conversation

Shrews
Copy link
Contributor

@Shrews Shrews commented Dec 21, 2021

Fixes #334

User Python requirements, specified via the --user-pip CLI option, will have duplicates removed, but will not go through the Python package exclusion process.

@Shrews Shrews requested a review from a team as a code owner December 21, 2021 16:39
@github-actions github-actions bot added docs Changes to documentation needs_triage New item that needs to be triaged labels Dec 21, 2021
@Shrews
Copy link
Contributor Author

Shrews commented Dec 23, 2021

Likely need an option to build to pass this through.

be excluded. For instance, these Python requirements will *always* be excluded
since they should be a part of execution environment definition itself:

- ansible

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this depends on the version of ansible.

After 2.9, the ansible package isn't strictly necessary and this is reflected in the published images for ansible-runner, for example:

# for version in 2.12 2.11 2.10 2.9
> do
> podman run -it quay.io/ansible/ansible-runner:stable-${version}-devel pip freeze | grep ansible
> done
ansible-core @ file:///output/wheels/ansible_core-2.12.1.post0-py3-none-any.whl
ansible-runner @ file:///output/wheels/ansible_runner-2.1.2.dev2-py3-none-any.whl
ansible-core @ file:///output/wheels/ansible_core-2.11.7.post0-py3-none-any.whl
ansible-runner @ file:///output/wheels/ansible_runner-2.1.2.dev2-py3-none-any.whl
ansible-base @ file:///output/wheels/ansible_base-2.10.16.post0-py3-none-any.whl
ansible-runner @ file:///output/wheels/ansible_runner-2.1.1.dev14-py3-none-any.whl
ansible @ file:///output/wheels/ansible-2.9.27.post0-py3-none-any.whl
ansible-runner @ file:///output/wheels/ansible_runner-2.1.2.dev2-py3-none-any.whl

After 2.10, the ansible package on pypi moved to a model where it only includes a set of collections.
My use case was to mirror the UX of installing 'ansible' from PyPI and then bumped into that issue (thanks for pointing me here)

I don't mind too much because there's simple workarounds like mentioned in that issue in addition to installing collections "manually" with a galaxy requirements.yml.

I could have missed it but it would be great to print a message that says a package was "sanitized" to avoid the effect of surprise.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could have missed it but it would be great to print a message that says a package was "sanitized" to avoid the effect of surprise.

I think that was attempted as a comment in the resultant requirements file, but with subsequent refactoring with the assemble script and other stuff, I think that file may wind up getting trashed, as more things were moved inside of ephemeral build stages.

logger.debug(f'# Excluding requirement {req.name} from {req.collections}')

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlanCoding would it make sense to bump the verbosity of that from debug to warning, perhaps ?

@@ -43,7 +54,7 @@ def sanitize_requirements(collection_py_reqs):
# removal of unwanted packages
sanitized = []
for req in consolidated:
if req.name and req.name.lower() in EXCLUDE_REQUIREMENTS:
if (req.name and (req.name.lower() in EXCLUDE_ALWAYS_REQUIREMENTS or (req.name.lower() in EXCLUDE_OPTIONAL_REQUIREMENTS and exclude))):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me put forward my alternative suggestion here - instead of documenting a new thing, we could avoid sanitizing anything from the user's requirements.

I find it hazardous to turn off sanitization of a collection's dependencies. I also don't see why we should ever sanitize the user's requirements. This would be much easier for documentation, probably just a mention in the --sanitize option help text.

To implement this, it might be adding something like and "user" not in req.collections

Just an idea. I'm always in favor of adding less configuration options if it will accomplish the same goal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm, I have to consider this some more, but I sort of like this solution at first read. I think we would still want to sanitize the user requirements to remove duplicates, but skip the part where we remove the excluded packages.

@Shrews Shrews changed the title Add option to ignore exclusions during sanitization Do not sanitize user python requirements Jan 5, 2022
@Shrews
Copy link
Contributor Author

Shrews commented Jan 5, 2022

recheck

Copy link
Member

@AlanCoding AlanCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me, thanks for incorporating the feedback.

@eqrx eqrx added the gate label Jan 6, 2022
Copy link
Contributor

@ansible-zuul ansible-zuul bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ansible-zuul ansible-zuul bot merged commit 51d0cb3 into ansible:devel Jan 6, 2022
@Shrews Shrews deleted the issue/334 branch January 6, 2022 16:39
@Shrews
Copy link
Contributor Author

Shrews commented Jan 6, 2022

Since this is a bit of a behavior change, I don't think I'm going to backport this to release_1.0.

@Akasurde Akasurde removed the needs_triage New item that needs to be triaged label Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Changes to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ansible-builder introspect --sanitize removes yamllint and ansible-lint from requirements.txt
5 participants