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
Conversation
the merge with iso6 will fail again. I'll open a pr for that one once this is merged. |
src/inmanta/env.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 _
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/inmanta/env.py
Outdated
@@ -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()) |
There was a problem hiding this comment.
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,)) | ||
|
||
|
There was a problem hiding this comment.
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
src/inmanta/env.py
Outdated
@@ -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()) |
There was a problem hiding this comment.
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.
src/inmanta/util/__init__.py
Outdated
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,)) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Co-authored-by: arnaudsjs <2684622+arnaudsjs@users.noreply.github.com>
Co-authored-by: arnaudsjs <2684622+arnaudsjs@users.noreply.github.com>
@@ -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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I don't want to even think about the implication of including a piece of licensed code for this little gain
- This is not correct wrt the behavior of pip https://pip.pypa.io/en/stable/topics/configuration/#environment-variables
Co-authored-by: Wouter De Borger <wouter.deborger@inmanta.com>
Co-authored-by: Wouter De Borger <wouter.deborger@inmanta.com>
Processing this pull request |
Pull request rejected by merge tool. Multiple change entry files found:
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. |
Processing this pull request |
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). |
…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)
Merged into branches master, iso7 in 1b3a952 |
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. |
This branch was not deleted as it seems to still be in use. |
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