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

WIP python_requirements_info does not parse extra in dependencies #5802

Open
wants to merge 30 commits into
base: main
Choose a base branch
from

Conversation

Warkdev
Copy link
Contributor

@Warkdev Warkdev commented Jan 8, 2023

SUMMARY

Fixes #731

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

python_requirements_info

ADDITIONAL INFORMATION
  • Fixes the issue mentionned earlier
  • Also allows spaces inside the dependencies (which was not the case until now), shall this be a separate PR if.. ?

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added WIP Work in progress bug This issue/PR relates to a bug integration tests/integration module module new_contributor Help guide this first time contributor plugins plugin (any type) system tests tests labels Jan 8, 2023
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-5 backport-6 Automatically create a backport for the stable-6 branch labels Jan 8, 2023
@github-actions

This comment was marked as outdated.

Warkdev and others added 2 commits January 10, 2023 07:30
…arse-project-extra-syntax.yml

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
Copy link
Collaborator

@russoz russoz left a comment

Choose a reason for hiding this comment

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

So, second time around taking a look, I think I spotted a couple of things. I understand not all of the issues pointed will be handled in this PR, but please take a look.

Warkdev and others added 3 commits January 14, 2023 13:14
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

Quick comment (spotted when not really looking).

plugins/modules/python_requirements_info.py Outdated Show resolved Hide resolved
@ansibullbot ansibullbot removed the new_contributor Help guide this first time contributor label Jan 14, 2023
@Warkdev
Copy link
Contributor Author

Warkdev commented Jan 14, 2023

I have highly refactored the module to leverage the pkg_resources module capabilities, removing the need for a regex.

However, after many researches, it seems impossible to handle extras, the only guessable thing seems to be if a provided extra is valid or not.

Therefore, in case extra identifiers are provided, I propose to verify if the extra is valid, if not, an error is raised. Otherwise, the package is put inside an ignore list and a warning is issued.

@Warkdev
Copy link
Contributor Author

Warkdev commented Jan 14, 2023

Given the failing systems, I do think that this would require even more work to be consistent.

It may also be a good idea to start changing the submodule used on more recent versions of Python as requested by setuptools: https://setuptools.pypa.io/en/latest/pkg_resources.html

@ansibullbot ansibullbot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Jan 14, 2023
plugins/modules/python_requirements_info.py Outdated Show resolved Hide resolved
plugins/modules/python_requirements_info.py Outdated Show resolved Hide resolved
plugins/modules/python_requirements_info.py Outdated Show resolved Hide resolved
Comment on lines +23 to +35
- name: ensure module supports PEP-508 specification
python_requirements_info:
dependencies:
- SomeProject
- SomeProject == 1.3
- SomeProject >= 1.2, < 2.0
- SomeProject[foo, bar]
register: dep_info

- name: ensure python_requirements_info returns desired info
assert:
that:
- dep_info is not failed
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMHO this makes more sense in the 731-parse-project-extra-syntax.yml file. And shouldn't we use an existing package instead of SomeProject ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does it ? Because it should be handled by the general module normally :)

Regarding the SomeProject, given that we assess only the validity of the requirement format, I'm not sure which added-value we could benefit there. WDYT ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it ? Because it should be handled by the general module normally :)

That came from the fact that we are testing some extra deps in there, but I see what you mean. Yeah, I am OK with it as-is.

Regarding the SomeProject, given that we assess only the validity of the requirement format, I'm not sure which added-value we could benefit there. WDYT ?

Ok, fair enough. But me lazily not going through the whole thing again, are testing elsewhere that all the extras specified are present, when responding?

Comment on lines +18 to +19
- The requirements C(SomeProject == 5.4 ; python_version < "3.8"), C(SomeProject ; sys_platform == 'win32') are not considered valid.
- The version operator C(~=) is also not considered valid on every platform.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ha, I thought pkg_resources would be able to handle those cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought also but it seems to be platform-dependant. Check the CI results, some are working, some are giving errors.

Also, it seems we should not be using pkg_resources after Python 3.8. Going to check that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, I did not know about the platform dependency. Fair enough. Any idea on how to go around pkg_resources on >3.8 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I further checked it but my time has been limited. According to pkg_resources documentation, we should be using the embedded importlib:

Use of pkg_resources is discouraged in favor of importlib.resources, importlib.metadata, and their backports (importlib_resources, importlib_metadata). Please consider using those libraries instead of pkg_resources.

The migration guide being here: https://importlib-metadata.readthedocs.io/en/latest/migration.html

I am only worried that this could introduce a difference in how the module behaves (especially in term of input validation) between the two libs. Also the support for importlib is not the same between 3.8 and 3.9.

A third option that I have found, but not ideal because it adds yet another library is to use this pep-508 package to parse the input: https://pypi.org/project/pep508/

This could streamline it.

Definitely, the tag easyfix on the issue isn't or we need to scope exactly what this PR should support :-)

Warkdev and others added 3 commits January 15, 2023 20:19
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
@Warkdev Warkdev changed the title python_requirements_info does not parse extra in dependencies WIP python_requirements_info does not parse extra in dependencies Jan 18, 2023
@ansibullbot ansibullbot added the WIP Work in progress label Jan 18, 2023
@ansibullbot ansibullbot added the stale_ci CI is older than 7 days, rerun before merging label Jan 26, 2023
@felixfontein felixfontein added the backport-7 Automatically create a backport for the stable-7 branch label May 10, 2023
@ansibullbot ansibullbot added the needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html label Jun 19, 2023
@felixfontein
Copy link
Collaborator

This PR needs a rebase. Please rebase, or if you no longer want to continue it, please close it. Thanks!

needs_info

@ansibullbot ansibullbot added the needs_info This issue requires further information. Please answer any outstanding questions label Feb 23, 2024
@ansibullbot ansibullbot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI and removed stale_ci CI is older than 7 days, rerun before merging labels Mar 10, 2024
@ansibullbot
Copy link
Collaborator

@Warkdev This pullrequest is waiting for your response. Please respond or the pullrequest will be closed.

click here for bot help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-6 Automatically create a backport for the stable-6 branch backport-7 Automatically create a backport for the stable-7 branch bug This issue/PR relates to a bug check-before-release PR will be looked at again shortly before release and merged if possible. integration tests/integration module module needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_info This issue requires further information. Please answer any outstanding questions needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR plugins plugin (any type) system tests tests WIP Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

python_requirements_info does not parse project[extra] syntax
4 participants