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/6096-log-which-pip-index-no-index #7148

Closed
wants to merge 23 commits into from
Closed

Conversation

FloLey
Copy link
Contributor

@FloLey FloLey commented Feb 8, 2024

Description

Add the used pip indexes to the PackageNotFound exception in run_pip didn't take --no-index into account. This Pr fixes this.

part of #6096

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)

@FloLey FloLey changed the title update issue/6096-log-which-pip-index-no-index Feb 8, 2024
@FloLey
Copy link
Contributor Author

FloLey commented Feb 8, 2024

the merge with iso6 will fail again. I'll open a pr for that one once this is merged.

@FloLey FloLey requested a review from arnaudsjs February 8, 2024 13:52
@FloLey FloLey self-assigned this Feb 8, 2024
tests/test_env.py Outdated Show resolved Hide resolved
tests/test_env.py Outdated Show resolved Hide resolved
tests/test_env.py Outdated Show resolved Hide resolved
@@ -508,6 +508,7 @@ def create_log_content_files(title: str, files: list[str]) -> list[str]:
not_found: list[str] = []
conflicts: list[str] = []
indexes: str = ""
no_index: bool = "--no-index" in cmd
Copy link
Contributor

Choose a reason for hiding this comment

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

It's also possible to set --no-index through an environment variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you know where all the pip env vars are documented? I see in is mentioned at some places and when I try it it does work but I don't find any doc about it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think every cli option can be set using an environment variable by prefixing the option with PIP_, capitalizing all the characters and replacing all the - chars with _.

Copy link
Contributor

Choose a reason for hiding this comment

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

FloLey and others added 6 commits February 8, 2024 15:56
@@ -508,6 +511,7 @@ def create_log_content_files(title: str, files: list[str]) -> list[str]:
not_found: list[str] = []
conflicts: list[str] = []
indexes: str = ""
no_index: bool = "--no-index" in cmd or strtobool(env.get("PIP_NO_INDEX", "false").lower())
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 don't really like this but I don't see what else can be done. I think at some point I have to read the value in the env vars to see if it is used or not.

else:
raise ValueError("invalid truth value %r" % (val,))


Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the same implementation as in distutils but I didn't like that it returned 1/0 instead of True/False

@FloLey FloLey requested a review from arnaudsjs February 8, 2024 15:53
tests/test_env.py Outdated Show resolved Hide resolved
src/inmanta/env.py Outdated Show resolved Hide resolved
@@ -508,6 +511,7 @@ def create_log_content_files(title: str, files: list[str]) -> list[str]:
not_found: list[str] = []
conflicts: list[str] = []
indexes: str = ""
no_index: bool = "--no-index" in cmd or strtobool(env.get("PIP_NO_INDEX", "false").lower())
Copy link
Contributor

Choose a reason for hiding this comment

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

We have to move this code into the if not_found block. Otherwise this code can raise a ValueError if the value of the environment variable is invalid. Once we enter the if non_found block, we know that the input was not rejected by pip and we know that there will be no ValueError. Let's also add a comment about this in the code.

Comment on lines 81 to 94
def strtobool(val: str) -> bool:
"""Convert a string representation of truth to true (1) or false (0).

True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
'val' is anything else.
"""
val = val.lower()
if val in ("y", "yes", "t", "true", "on", "1"):
return True
elif val in ("n", "no", "f", "false", "off", "0"):
return False
else:
raise ValueError("invalid truth value %r" % (val,))
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure to which extend we should consider this code to be copied and we should make sure we are in-line with the copy-right obligations of distutils. @wouterdb do you know?

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 don't think it is really needed by I added the license just in case.

src/inmanta/env.py Outdated Show resolved Hide resolved
FloLey and others added 9 commits February 9, 2024 09:01
Co-authored-by: arnaudsjs <2684622+arnaudsjs@users.noreply.github.com>
Co-authored-by: arnaudsjs <2684622+arnaudsjs@users.noreply.github.com>
@FloLey FloLey requested a review from arnaudsjs February 9, 2024 13:36
src/inmanta/env.py Outdated Show resolved Hide resolved
src/inmanta/env.py Show resolved Hide resolved
@@ -78,6 +78,43 @@ def is_sub_dict(subdct: dict[PrimitiveTypes, PrimitiveTypes], dct: dict[Primitiv
return not any(True for k, v in subdct.items() if k not in dct or dct[k] != v)


def strtobool(val: str) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. I don't want to even think about the implication of including a piece of licensed code for this little gain
  2. This is not correct wrt the behavior of pip https://pip.pypa.io/en/stable/topics/configuration/#environment-variables

FloLey and others added 2 commits February 9, 2024 14:56
Co-authored-by: Wouter De Borger <wouter.deborger@inmanta.com>
Co-authored-by: Wouter De Borger <wouter.deborger@inmanta.com>
@FloLey FloLey requested a review from wouterdb February 9, 2024 14:19
@FloLey FloLey added the merge-tool-ready This ticket is ready to be merged in label Feb 12, 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 Feb 12, 2024
@inmantaci
Copy link
Contributor

Pull request rejected by merge tool. Multiple change entry files found:

  • changelogs/unreleased/7066-stale_last_success.yml
  • changelogs/unreleased/fix-log-pip-index.yml
  • changelogs/unreleased/fix_increment_tests.yml

This may happen when a change entry was removed from the remote repository due to a reverted change. In that case, make sure the latest changes from origin/master are merged into fix-log-no-index before triggering merge bot.

@FloLey FloLey added the merge-tool-ready This ticket is ready to be merged in label Feb 12, 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 Feb 12, 2024
@inmantaci
Copy link
Contributor

Failed to merge changes into iso6 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 1b3a952).

inmantaci pushed a commit that referenced this pull request Feb 12, 2024
…e or third-party Python dependency if that package could not be found in the case of --no-index (Issue #6096, PR #7148)

# Description

[Add the used pip indexes to the PackageNotFound exception in run_pip](#7064) didn't take --no-index into account. This Pr fixes this.

part of #6096

# Self Check:

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

- [ ] Attached issue to pull request
- [x] Changelog entry
- [x] Type annotations are present
- [x] Code is clear and sufficiently documented
- [x] No (preventable) type errors (check using make mypy or make mypy-diff)
- [x] Sufficient test cases (reproduces the bug/tests the requested feature)
- [x] 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

Merged into branches master, iso7 in 1b3a952

@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.

@FloLey FloLey closed this Feb 14, 2024
@FloLey FloLey deleted the fix-log-no-index branch April 24, 2024 09:33
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.

None yet

4 participants