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

Issue/drop pkg resources - first part #7990

Closed
wants to merge 89 commits into from

Conversation

hlloreda
Copy link
Contributor

@hlloreda hlloreda commented Aug 21, 2024

Description

First part that migrates the use of the deprecated library: pkg_resources. This part preserves the venv caching mechanism that allows us to speed up the test suite. The second part should migrate this mechanism

Related to #6668

Self Check:

Strike through any lines that are not applicable (~~line~~) then check the box

  • Attached issue to pull request
  • Changelog entry
  • Type annotations are present
  • Code is clear and sufficiently documented
  • No (preventable) type errors (check using make mypy or make mypy-diff)
  • Sufficient test cases (reproduces the bug/tests the requested feature)
  • Correct, in line with design
  • End user documentation is included or an issue is created for end-user documentation (add ref to issue here: )
  • If this PR fixes a race condition in the test suite, also push the fix to the relevant stable branche(s) (see test-fixes for more info)

@hlloreda hlloreda self-assigned this Aug 21, 2024
@@ -182,7 +182,7 @@ def get_table(header: list[str], rows: list[list[str]], data_type: Optional[list
return table.draw()


@with_plugins(iter_entry_points("inmanta.cli_plugins"))
@with_plugins(importlib_metadata.entry_points(group="inmanta.cli_plugins"))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

mypy is raising a warning here:

src/inmanta/main.py:185: error: Argument 1 to "with_plugins" has incompatible type "EntryPoints"; expected "Generator[EntryPoint, None, None]"  [arg-type]

I don't know how should I fix this

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@with_plugins(importlib_metadata.entry_points(group="inmanta.cli_plugins"))
@with_plugins(iter(importlib_metadata.entry_points(group="inmanta.cli_plugins")))

like so?

Copy link
Contributor

Choose a reason for hiding this comment

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

this doesn't seem to be maintained I think it is good to figure out why it is here at all (I suspect LSM).

We may want to vendor it or find a fork if we need it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are now experiencing this error:

src/inmanta/main.py:185: error: Argument 1 to "iter" has incompatible type "EntryPoints"; expected "SupportsIter[Generator[EntryPoint, None, None]]"  [arg-type]
src/inmanta/main.py:185: note: Following member(s) of "EntryPoints" have conflicts:
src/inmanta/main.py:185: note:     Expected:
src/inmanta/main.py:185: note:         def __iter__(self) -> Generator[EntryPoint, None, None]
src/inmanta/main.py:185: note:     Got:
src/inmanta/main.py:185: note:         def __iter__(self) -> Iterator[Any]

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, click-plugin is just outdated, perhaps we can vendor it?

@hlloreda hlloreda marked this pull request as ready for review August 21, 2024 14:23
@hlloreda hlloreda changed the title Issue/drop pkg resources 2 Issue/drop pkg resources - first part Aug 21, 2024
Copy link
Contributor

@wouterdb wouterdb left a comment

Choose a reason for hiding this comment

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

  1. is there a migration guide that was followed? (I don't know if it exists, didn't find it either)

src/inmanta/env.py Outdated Show resolved Hide resolved
src/inmanta/env.py Outdated Show resolved Hide resolved
class SafeRequirement(Requirement):
def __init__(self, requirement_string: str) -> None:
# Packaging Requirement is not able to parse requirements with comment. Therefore, we need to remove the `comment` part
drop_comment = requirement_string.split("#")[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this handle the inputs

""
"#"
" # " 
"#this is a comment"

src/inmanta/env.py Outdated Show resolved Hide resolved
# set as a marker. The line below makes sure that the "extra" marker matches. The marker is not set by
# `Distribution.requires()` when the package is installed in editable mode, but setting it always doesn't make
# the marker evaluation fail.
environment_marker_evaluation = {"extra": contained_in_extra} if contained_in_extra else None
if r.marker and not r.marker.evaluate(environment=environment_marker_evaluation):
# The marker of the requirement doesn't apply on this environment
continue
if r.key not in installed_packages or str(installed_packages[r.key]) not in r:
if (
r.name.lower() not in installed_packages
Copy link
Contributor

Choose a reason for hiding this comment

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

why is the lower added?

@@ -234,7 +253,7 @@ def get_packages_in_working_set(cls, inmanta_modules_only: bool = False) -> dict
:param inmanta_modules_only: Only return inmanta modules from the working set
"""
return {
dist_info.key: version.Version(dist_info.version)
utils.canonicalize_name(dist_info.key): version.Version(dist_info.version)
Copy link
Contributor

Choose a reason for hiding this comment

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

We may want to write a comment or adr about name Vs canonicalize_name. What should be used where.

@@ -182,7 +182,7 @@ def get_table(header: list[str], rows: list[list[str]], data_type: Optional[list
return table.draw()


@with_plugins(iter_entry_points("inmanta.cli_plugins"))
@with_plugins(importlib_metadata.entry_points(group="inmanta.cli_plugins"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@with_plugins(importlib_metadata.entry_points(group="inmanta.cli_plugins"))
@with_plugins(iter(importlib_metadata.entry_points(group="inmanta.cli_plugins")))

like so?

@@ -182,7 +182,7 @@ def get_table(header: list[str], rows: list[list[str]], data_type: Optional[list
return table.draw()


@with_plugins(iter_entry_points("inmanta.cli_plugins"))
@with_plugins(importlib_metadata.entry_points(group="inmanta.cli_plugins"))
Copy link
Contributor

Choose a reason for hiding this comment

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

this doesn't seem to be maintained I think it is good to figure out why it is here at all (I suspect LSM).

We may want to vendor it or find a fork if we need it.

@@ -182,7 +182,7 @@ def get_table(header: list[str], rows: list[list[str]], data_type: Optional[list
return table.draw()


@with_plugins(iter_entry_points("inmanta.cli_plugins"))
@with_plugins(importlib_metadata.entry_points(group="inmanta.cli_plugins"))
Copy link
Contributor

Choose a reason for hiding this comment

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

src/inmanta/module.py Show resolved Hide resolved
@@ -107,7 +105,7 @@ def __init__(self, requirement: packaging.requirements.Requirement) -> None:
f"Problematic case: {str(requirement)}"
)
self._requirement: inmanta.util.CanonicalRequirement = inmanta.util.parse_requirement(str(requirement))
self._project_name = re.sub('[^A-Za-z0-9.]+', '-', requirement.name)
self._project_name = re.sub("[^A-Za-z0-9.]+", "-", requirement.name)
Copy link
Contributor Author

@hlloreda hlloreda Sep 30, 2024

Choose a reason for hiding this comment

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

Maybe it would be better to only receive a string?

Copy link
Contributor

@sanderr sanderr left a comment

Choose a reason for hiding this comment

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

As discussed in person

Copy link
Contributor

@sanderr sanderr left a comment

Choose a reason for hiding this comment

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

As discussed

src/inmanta/module.py Outdated Show resolved Hide resolved
@hlloreda hlloreda added the merge-tool-ready This ticket is ready to be merged in label Oct 3, 2024
@inmantaci
Copy link
Contributor

Processing this pull request

@inmantaci inmantaci removed the merge-tool-ready This ticket is ready to be merged in label Oct 3, 2024
@inmantaci
Copy link
Contributor

Failed to merge changes into iso7 due to merge conflict. Please open a pull request for these branches separately by cherry-picking the commit that was made on the branch master (git cherry-pick d048e728d2a0a518801b39a76d8bd039e8a8195b).

@inmantaci
Copy link
Contributor

Merged into branches master in d048e72

inmantaci pushed a commit that referenced this pull request Oct 3, 2024
# Description

First part that migrates the use of the deprecated library: pkg_resources. This part preserves the venv caching mechanism that allows us to speed up the test suite. The second part should migrate this mechanism

Related to #6668

# Self Check:

Strike through any lines that are not applicable (`~~line~~`) then check the box

- [ ] Attached issue to pull request
- [ ] Changelog entry
- [ ] Type annotations are present
- [ ] Code is clear and sufficiently documented
- [ ] No (preventable) type errors (check using make mypy or make mypy-diff)
- [ ] Sufficient test cases (reproduces the bug/tests the requested feature)
- [ ] Correct, in line with design
- [ ] End user documentation is included or an issue is created for end-user documentation (add ref to issue here: )
- [ ] If this PR fixes a race condition in the test suite, also push the fix to the relevant stable branche(s) (see [test-fixes](https://internal.inmanta.com/development/core/tasks/build-master.html#test-fixes) for more info)
@inmantaci
Copy link
Contributor

Not closing this pull request due to previously commented issues for some of the destination branches. Please open a separate pull request for those branches by cherry-picking the relevant commit. You can safely close this pull request and delete the source branch.

@inmantaci
Copy link
Contributor

This branch was not deleted as it seems to still be in use.

inmantaci pushed a commit that referenced this pull request Oct 3, 2024
# Description

Implementation of #7990 for ISO7

Related to #6668

# Self Check:

Strike through any lines that are not applicable (`~~line~~`) then check the box

- [ ] Attached issue to pull request
- [ ] Changelog entry
- [ ] Type annotations are present
- [ ] Code is clear and sufficiently documented
- [ ] No (preventable) type errors (check using make mypy or make mypy-diff)
- [ ] Sufficient test cases (reproduces the bug/tests the requested feature)
- [ ] Correct, in line with design
- [ ] End user documentation is included or an issue is created for end-user documentation (add ref to issue here: )
- [ ] If this PR fixes a race condition in the test suite, also push the fix to the relevant stable branche(s) (see [test-fixes](https://internal.inmanta.com/development/core/tasks/build-master.html#test-fixes) for more info)
@hlloreda
Copy link
Contributor Author

hlloreda commented Oct 3, 2024

Everything has been merged (ISO7 and master)

@hlloreda hlloreda closed this Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants