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

Prevent pip install pip install #11898

Conversation

MaddyGuthridge
Copy link

@MaddyGuthridge MaddyGuthridge commented Mar 26, 2023

Resolves #11484.

If a user pastes an install command into their terminal, but has already typed pip install beforehand, this currently results in pip installing the install package, which is likely never their intention given that install is a nearly useless package to prevent typosquatting.

This appears to be a common mistake given that the install package has around 30000 installs on most weekdays.

This PR adds a check to prevent users from running pip install pip install package and pip install install package, which should hopefully save users some time and frustration, since there won't be a need to follow their mistaken command up with a pip uninstall install to rectify their mistake.

Note that it is still possible to install the install package using pip install install by itself or by specifying it as not being the first package.

  • Implement
  • Add tests
  • Add news entry

As far as I'm aware, this feature shouldn't require documentation, but I'm happy to write some if required (let me know where since I can't think of a good place for it).

This is my first PR to pip, so please let me know if there's anything I've overlooked! Thanks!

@MaddyGuthridge MaddyGuthridge force-pushed the miguel/fix-pip-install-pip-install branch 2 times, most recently from e713c5c to 100732c Compare April 30, 2023 03:00
@pradyunsg
Copy link
Member

x-ref pypi/support#451

I'm down to do this, if no one else has concerns. :)

@MaddyGuthridge
Copy link
Author

Shouldn't be a problem if install does get used for a meaningful package, since this PR is specifically blocking pip install pip install ..., since that's likely the most common mistake people would make.

@MaddyGuthridge MaddyGuthridge force-pushed the miguel/fix-pip-install-pip-install branch from d4a2947 to 6629510 Compare May 21, 2023 17:20
@MaddyGuthridge MaddyGuthridge force-pushed the miguel/fix-pip-install-pip-install branch from 7e5a089 to 5ff87a3 Compare May 24, 2023 02:27
@MaddyGuthridge MaddyGuthridge force-pushed the miguel/fix-pip-install-pip-install branch from c1e506c to 275af31 Compare August 23, 2023 04:41
Copy link

@danielhollas danielhollas left a comment

Choose a reason for hiding this comment

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

@MiguelGuthridge LGTM, but I am not a pip maintainer so cannot help with landing this. :-)

Comment on lines +274 to +281
"\n".join(
[
"Likely incorrect command: pip install pip install ...",
f"Did you mean \"pip install {' '.join(args[2:])}\"?",
'To install the "install" package, run '
'"pip install install" separately',
]
)
Copy link
Member

@uranusjr uranusjr Sep 5, 2023

Choose a reason for hiding this comment

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

The join call is unnecessary since you can use implicit string join instead.

@@ -2560,3 +2560,65 @@ def test_install_pip_prints_req_chain_pypi(script: PipTestEnvironment) -> None:
f"Collecting python-openid "
f"(from Paste[openid]==1.7.5.1->-r {req_path} (line 1))" in result.stdout
)


def test_prevent_pip_install_pip_install(script: PipTestEnvironment) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

These two tests can be combined into one with pytest.mark.parametrize.

@woodruffw
Copy link
Member

Just closing a loop here: pypi/support#451 was closed, with install now being prohibited on PyPI 🙂

@pradyunsg
Copy link
Member

It looks like this issue has been resolved.

@pradyunsg pradyunsg closed this Jul 18, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent pip installs that start with pip install pip install
5 participants