Repository: pypa/pip

Issue:
Automatically check for typos using codespell + pre-commit
> It could be worthwhile to look into whether a pre-commit hook spell-checking some files would be more helpful than not.

_Originally posted by @chrahunt in https://github.com/pypa/pip/pull/7642#issuecomment-581156528_

---

Looks like https://github.com/codespell-project/codespell has a pre-commit hook configuration. The configuration change would be to add the following to our `.pre-commit-config.yaml` file.

```yaml
- repo: https://github.com/codespell-project/codespell
  rev: v1.16.0
  hooks:
    - id: codespell
```

Codespell: config, action, pre-commit + few typos fixed 
There were codespell fixes submitted in the past but no action or pre-commit was configured, so new typos seems to penetrate.  So I decided to propose action/config and pre-commit to ensure that in the future `pip` would remain typos free




Discussion:
Some targets for this check would be:

1. docs
2. news files
3. README
4. code comments

What needs investigation is how often we'll get false positives and what the remediation is, but the best way to do that is to add it to the list of checks and submit a PR.
Bonus points for integrating sphinx-spellcheck too.
There is some more recent discussion about Codespell in #10569.
Need to fix the packaging check.
> Need to fix the packaging check.

should be done now.  I can also sort lines there within each block to simplify finding location to add, but didn't want to "impose" ;-)
ping on this one: AFAIK I have addressed all comments and even prior approval was given.

Resolving patch:
diff --git a/src/pip/_internal/cache.py b/src/pip/_internal/cache.py
--- a/src/pip/_internal/cache.py
+++ b/src/pip/_internal/cache.py
@@ -44,7 +44,7 @@ def _get_cache_path_parts(self, link: Link) -> List[str]:
         """Get parts of part that must be os.path.joined with cache_dir"""
 
         # We want to generate an url to use as our cache key, we don't want to
-        # just re-use the URL because it might have other items in the fragment
+        # just reuse the URL because it might have other items in the fragment
         # and we don't care about those.
         key_parts = {"url": link.url_without_fragment}
         if link.hash_name is not None and link.hash is not None:
diff --git a/src/pip/_internal/resolution/resolvelib/candidates.py b/src/pip/_internal/resolution/resolvelib/candidates.py
--- a/src/pip/_internal/resolution/resolvelib/candidates.py
+++ b/src/pip/_internal/resolution/resolvelib/candidates.py
@@ -519,7 +519,7 @@ def _warn_invalid_extras(
     def _calculate_valid_requested_extras(self) -> FrozenSet[str]:
         """Get a list of valid extras requested by this candidate.
 
-        The user (or upstream dependant) may have specified extras that the
+        The user (or upstream dependent) may have specified extras that the
         candidate doesn't support. Any unsupported extras are dropped, and each
         cause a warning to be logged here.
         """
diff --git a/src/pip/_internal/utils/_jaraco_text.py b/src/pip/_internal/utils/_jaraco_text.py
--- a/src/pip/_internal/utils/_jaraco_text.py
+++ b/src/pip/_internal/utils/_jaraco_text.py
@@ -88,7 +88,7 @@ def join_continuation(lines):
     ['foobarbaz']
 
     Not sure why, but...
-    The character preceeding the backslash is also elided.
+    The character preceding the backslash is also elided.
 
     >>> list(join_continuation(['goo\\', 'dly']))
     ['godly']


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -495,7 +495,7 @@ def virtualenv_template(
         dist_info, venv.site / dist_info.name, dirs_exist_ok=True, symlinks=True
     )
     # Create placeholder ``easy-install.pth``, as several tests depend on its
-    # existance.  TODO: Ensure ``tests.lib.TestPipResult.files_updated`` correctly
+    # existence.  TODO: Ensure ``tests.lib.TestPipResult.files_updated`` correctly
     # detects changed files.
     venv.site.joinpath("easy-install.pth").touch()
 
diff --git a/tests/functional/test_cli.py b/tests/functional/test_cli.py
--- a/tests/functional/test_cli.py
+++ b/tests/functional/test_cli.py
@@ -69,7 +69,7 @@ def test_no_network_imports(command: str, tmp_path: Path) -> None:
     This helps to reduce the startup time of these commands.
 
     Note: This won't catch lazy network imports, but it'll catch top-level
-    network imports which were accidently added (which is the most likely way
+    network imports which were accidentally added (which is the most likely way
     to regress anyway).
     """
     file = tmp_path / f"imported_modules_for_{command}.txt"
diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py
--- a/tests/functional/test_install.py
+++ b/tests/functional/test_install.py
@@ -1731,7 +1731,7 @@ def test_install_builds_wheels(script: PipTestEnvironment, data: TestData) -> No
     assert "Building wheel for wheelb" in str(res), str(res)
     assert "Failed to build wheelbroken" in str(res), str(res)
     # Wheels are built for local directories, but not cached.
-    assert "Building wheel for requir" in str(res), str(res)
+    assert "Building wheel for require" in str(res), str(res)
     # into the cache
     assert wheels != [], str(res)
     assert wheels == [
@@ -1754,7 +1754,7 @@ def test_install_no_binary_builds_wheels(
     )
     # Wheels are built for all requirements
     assert "Building wheel for wheelb" in str(res), str(res)
-    assert "Building wheel for requir" in str(res), str(res)
+    assert "Building wheel for require" in str(res), str(res)
     assert "Building wheel for upper" in str(res), str(res)
     # Wheelbroken failed to build
     assert "Failed to build wheelbroken" in str(res), str(res)
diff --git a/tests/functional/test_new_resolver_user.py b/tests/functional/test_new_resolver_user.py
--- a/tests/functional/test_new_resolver_user.py
+++ b/tests/functional/test_new_resolver_user.py
@@ -27,7 +27,7 @@ def test_new_resolver_install_user_satisfied_by_global_site(
     script: PipTestEnvironment,
 ) -> None:
     """
-    An install a matching version to user site should re-use a global site
+    An install a matching version to user site should reuse a global site
     installation if it satisfies.
     """
     create_basic_wheel_for_package(script, "base", "1.0.0")
diff --git a/tests/unit/test_collector.py b/tests/unit/test_collector.py
--- a/tests/unit/test_collector.py
+++ b/tests/unit/test_collector.py
@@ -911,7 +911,7 @@ def test_collect_sources__non_existing_path() -> None:
             index_url="ignored-by-no-index",
             extra_index_urls=[],
             no_index=True,
-            find_links=[os.path.join("this", "doesnt", "exist")],
+            find_links=[os.path.join("this", "does", "not", "exist")],
         ),
     )
     sources = collector.collect_sources(