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

Pip deprecation warnings not displayed by default #11330

Closed
1 task done
sbidoul opened this issue Jul 31, 2022 · 20 comments · Fixed by #11333
Closed
1 task done

Pip deprecation warnings not displayed by default #11330

sbidoul opened this issue Jul 31, 2022 · 20 comments · Fixed by #11333
Labels
type: bug A confirmed bug or unintended behavior
Milestone

Comments

@sbidoul
Copy link
Member

sbidoul commented Jul 31, 2022

Description

Following #11229 the pip deprecation warnings are not displayed by default, because DeprecationWarnings are ignored by the default warning filters.

I propose to revert #11229 in pip 22.2.2 and we can think about a better solution for 22.3 or later.

Expected behavior

Pip deprecation warnings should be displayed with a default python installation, otherwise most users won't see them.

pip version

22.2

Python version

3

OS

any

How to Reproduce

...

Output

No response

Code of Conduct

@sbidoul sbidoul added type: bug A confirmed bug or unintended behavior S: needs triage Issues/PRs that need to be triaged labels Jul 31, 2022
@sbidoul sbidoul added this to the 22.2.2 milestone Jul 31, 2022
@sbidoul sbidoul removed the S: needs triage Issues/PRs that need to be triaged label Jul 31, 2022
@uranusjr
Copy link
Member

uranusjr commented Aug 1, 2022

Copying the problem from #11225. There is currently no good way to suppress pip’s deprecation warnings, even if they are expected for various reasons.

@pradyunsg
Copy link
Member

We can subclass from warning, and let user suppress PipDeprecationWarning?

@pradyunsg
Copy link
Member

Regardless, I’d prefer we unconditionally show warnings than not show them. ;)

@sbidoul
Copy link
Member Author

sbidoul commented Aug 1, 2022

FWIW, I've tried this:

❯ python -W 'ignore::pip._internal.utils.deprecation.PipDeprecationWarning' -m pip --version
Invalid -W option ignored: invalid module name: 'pip._internal.utils.deprecation'
...

I've not had time to dig further. So if no better low risk idea shows up I'm going to go ahead with #11333 for 22.2.2 and reopen #11225.

@pradyunsg
Copy link
Member

Just ignore PipDeprecationWarning, without any internal module path?

@sbidoul
Copy link
Member Author

sbidoul commented Aug 1, 2022

Nope, I had tried that too: Invalid -W option ignored: unknown warning category: 'PipDeprecationWarning'.

@pfmoore
Copy link
Member

pfmoore commented Aug 1, 2022

I can reproduce this in a standalone package:

ttt
    __init__.py (contains "class W(Warning): pass")
    __main__.py (contains a print("hi") statement)

❯ py -W ignore::ttt.W ttt
Invalid -W option ignored: invalid module name: 'ttt'
hi

I suspect this is a core Python bug, with -W not handling 3rd party module names for some reason.

@uranusjr
Copy link
Member

uranusjr commented Aug 1, 2022

Ah so the syntax seems pretty weird. https://docs.python.org/3/using/cmdline.html#cmdoption-w

So I think -W ignore::PipDeprecationWarning:pip._internal.utils.deprecation should work?

(I wonder if it’s worthwhile to make PipDeprecationWarning a top-level import so a user can write ignore:PipDeprecationWarning:pip)

@pradyunsg
Copy link
Member

python -W ignore::PipDeprecationWarning:pip._internal.utils.deprecation -m pip --version
Invalid -W option ignored: unknown warning category: 'PipDeprecationWarning'
pip 22.3.dev0 from /Users/pradyunsg/Developer/github/pip/src/pip (python 3.10)

@sbidoul
Copy link
Member Author

sbidoul commented Aug 1, 2022

BTW, using the fully qualified category class name as category filter is PEP 230, but I could not find it in the official docs, so maybe that has never been implemented.

@pradyunsg
Copy link
Member

pradyunsg commented Aug 1, 2022

Well, then let's use UserWarning then.

python -m pip --version
DEPRECATION: AAA
pip 22.3.dev0 from /Users/pradyunsg/Developer/github/pip/src/pip (python 3.10)python -W ignore::UserWarning -m pip --version
pip 22.3.dev0 from /Users/pradyunsg/Developer/github/pip/src/pip (python 3.10)git diff src/pip/_internal/utils 
diff --git a/src/pip/_internal/utils/deprecation.py b/src/pip/_internal/utils/deprecation.py
index 7964095ff..42f8b0738 100644
--- a/src/pip/_internal/utils/deprecation.py
+++ b/src/pip/_internal/utils/deprecation.py
@@ -13,7 +13,7 @@
 DEPRECATION_MSG_PREFIX = "DEPRECATION: "
 
 
-class PipDeprecationWarning(DeprecationWarning):
+class PipDeprecationWarning(UserWarning):
     pass
 

@pfmoore
Copy link
Member

pfmoore commented Aug 1, 2022

If we have a consistent prefix like "Pip:" for the message, people could also use something like -W ignore:Pip:UserWarning

@pradyunsg
Copy link
Member

pradyunsg commented Aug 1, 2022

-W ignore:Pip:UserWarning

We have DEPRECATION: , so...

python -W 'ignore:DEPRECATION:UserWarning' -m pip --version 
pip 22.3.dev0 from /Users/pradyunsg/Developer/github/pip/src/pip (python 3.10)

@pradyunsg
Copy link
Member

pradyunsg commented Aug 1, 2022

Well, in that case, we can also change to a Warning:

python -m pip --version
DEPRECATION: AAA
pip 22.3.dev0 from /Users/pradyunsg/Developer/github/pip/src/pip (python 3.10)python -W 'ignore:DEPRECATION' -m pip --version
pip 22.3.dev0 from /Users/pradyunsg/Developer/github/pip/src/pip (python 3.10)g diff src/pip/_internal/utils
diff --git a/src/pip/_internal/utils/deprecation.py b/src/pip/_internal/utils/deprecation.py
index 7964095ff..72bd6f25a 100644
--- a/src/pip/_internal/utils/deprecation.py
+++ b/src/pip/_internal/utils/deprecation.py
@@ -13,7 +13,7 @@
 DEPRECATION_MSG_PREFIX = "DEPRECATION: "
 
 
-class PipDeprecationWarning(DeprecationWarning):
+class PipDeprecationWarning(Warning):
     pass
 

@sbidoul
Copy link
Member Author

sbidoul commented Aug 1, 2022

Simple enough :) Ok, merging #11333.

@uranusjr
Copy link
Member

uranusjr commented Aug 1, 2022

I really dislike suggesting either magic prefix or a non-pip-specific warning class though, since that could silence other meaningful warnings generated by vendor packages. (e.g. if something detects an environment configuration issue that has security implications)

@pradyunsg
Copy link
Member

Do you expect security issues to start with Deprecation, and somehow only occur for folks who are silencing the warning?

@uranusjr
Copy link
Member

uranusjr commented Aug 1, 2022

I expect deprecation issues to start with DEPRECATION, but a deprecation can be made for various reasons, including security issues. They don’t only occur for people silencing the warnings, but those who do silence will miss the chance to notice them.

@pfmoore
Copy link
Member

pfmoore commented Aug 1, 2022

I really dislike suggesting either magic prefix or a non-pip-specific warning class

I agree, but it appears that we're unable to do better because of the limitations of the core Python -W flag (combined with the core Python policy of suppressing deprecation warnings by default).

From #11229:

I’m not sure why this was not done in the first place—perhaps there were considerations I did not know.

Perhaps the issues with core Python's policy were the considerations here? I must admit, as it stands, I don't see how a user application can reasonably use the core DeprecationWarning class successfully...

@sbidoul
Copy link
Member Author

sbidoul commented Aug 2, 2022

I updated my comment in the original issue (#11225 (comment)) to mention the potential risk of hiding other important warnings.

I don't think there is anything else we need to do about this in 22.2.2.

If anyone thinks there is more to do for a future release, I suggest we open another issue to track the feature request.

inmantaci pushed a commit to inmanta/inmanta-core that referenced this issue Aug 4, 2022
Bumps [pip](https://github.com/pypa/pip) from 22.2.1 to 22.2.2.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/pypa/pip/blob/main/NEWS.rst">pip's changelog</a>.</em></p>
<blockquote>
<h1>22.2.2 (2022-08-03)</h1>
<h2>Bug Fixes</h2>
<ul>
<li>Avoid  <code>AttributeError</code> when removing the setuptools-provided <code>_distutils_hack</code> and it is missing its implementation. (<code>[#11314](pypa/pip#11314) &lt;https://github.com/pypa/pip/issues/11314&gt;</code>_)</li>
<li>Fix import error when reinstalling pip in user site. (<code>[#11319](pypa/pip#11319) &lt;https://github.com/pypa/pip/issues/11319&gt;</code>_)</li>
<li>Show pip deprecation warnings by default. (<code>[#11330](pypa/pip#11330) &lt;https://github.com/pypa/pip/issues/11330&gt;</code>_)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/pypa/pip/commit/10902ac52d49ec3f5a03a4ed67c4dee533bf8bc4"><code>10902ac</code></a> Bump for release</li>
<li><a href="https://github.com/pypa/pip/commit/534e4d23386f43114f3deed65b7ebdc821aacb4a"><code>534e4d2</code></a> Update AUTHORS.txt</li>
<li><a href="https://github.com/pypa/pip/commit/96675e90cc9b51d3ab2c4f33f8e5e7f2438dfb91"><code>96675e9</code></a> Do not parse JSON content with HTML parser</li>
<li><a href="https://github.com/pypa/pip/commit/4514d1f47300e6df8ad43b309811c876287f8f03"><code>4514d1f</code></a> Revert &quot;PipDeprecationWarning subclass DeprecationWarning&quot;</li>
<li><a href="https://github.com/pypa/pip/commit/1ac427b647b276acd92def9e6bfa223c0d74d103"><code>1ac427b</code></a> Remove TODO</li>
<li><a href="https://github.com/pypa/pip/commit/450fd26c2d4f97284eccb1e6a6f81e9a460b17af"><code>450fd26</code></a> Import distutils only if needed, but sooner</li>
<li><a href="https://github.com/pypa/pip/commit/0c9eb969ebc833454468e16a5fd8fe90548d4c75"><code>0c9eb96</code></a> Ensure that removing shim in older setuptools does not error</li>
<li>See full diff in <a href="https://github.com/pypa/pip/compare/22.2.1...22.2.2">compare view</a></li>
</ul>
</details>
<br />

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=pip&package-manager=pip&previous-version=22.2.1&new-version=22.2.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)

</details>
inmantaci pushed a commit to inmanta/inmanta-core that referenced this issue Aug 4, 2022
Bumps [pip](https://github.com/pypa/pip) from 22.2.1 to 22.2.2.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/pypa/pip/blob/main/NEWS.rst">pip's changelog</a>.</em></p>
<blockquote>
<h1>22.2.2 (2022-08-03)</h1>
<h2>Bug Fixes</h2>
<ul>
<li>Avoid  <code>AttributeError</code> when removing the setuptools-provided <code>_distutils_hack</code> and it is missing its implementation. (<code>[#11314](pypa/pip#11314) &lt;https://github.com/pypa/pip/issues/11314&gt;</code>_)</li>
<li>Fix import error when reinstalling pip in user site. (<code>[#11319](pypa/pip#11319) &lt;https://github.com/pypa/pip/issues/11319&gt;</code>_)</li>
<li>Show pip deprecation warnings by default. (<code>[#11330](pypa/pip#11330) &lt;https://github.com/pypa/pip/issues/11330&gt;</code>_)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/pypa/pip/commit/10902ac52d49ec3f5a03a4ed67c4dee533bf8bc4"><code>10902ac</code></a> Bump for release</li>
<li><a href="https://github.com/pypa/pip/commit/534e4d23386f43114f3deed65b7ebdc821aacb4a"><code>534e4d2</code></a> Update AUTHORS.txt</li>
<li><a href="https://github.com/pypa/pip/commit/96675e90cc9b51d3ab2c4f33f8e5e7f2438dfb91"><code>96675e9</code></a> Do not parse JSON content with HTML parser</li>
<li><a href="https://github.com/pypa/pip/commit/4514d1f47300e6df8ad43b309811c876287f8f03"><code>4514d1f</code></a> Revert &quot;PipDeprecationWarning subclass DeprecationWarning&quot;</li>
<li><a href="https://github.com/pypa/pip/commit/1ac427b647b276acd92def9e6bfa223c0d74d103"><code>1ac427b</code></a> Remove TODO</li>
<li><a href="https://github.com/pypa/pip/commit/450fd26c2d4f97284eccb1e6a6f81e9a460b17af"><code>450fd26</code></a> Import distutils only if needed, but sooner</li>
<li><a href="https://github.com/pypa/pip/commit/0c9eb969ebc833454468e16a5fd8fe90548d4c75"><code>0c9eb96</code></a> Ensure that removing shim in older setuptools does not error</li>
<li>See full diff in <a href="https://github.com/pypa/pip/compare/22.2.1...22.2.2">compare view</a></li>
</ul>
</details>
<br />

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=pip&package-manager=pip&previous-version=22.2.1&new-version=22.2.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)

</details>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants