Repository: pre-commit/pre-commit-mirror-maker

Issue:
Support for packages with "extras"
I ran across the issue to (have to) mirror a package which needs "extras" to function:

```
pre-commit-mirror mirrors-CleverCSV --language python --package-name "clevercsv[full]" --entry "clevercsv standardize" --args="--in-place" --types csv
```

The extras are of course not part the PyPI URL, where `package-name` gets inserted to:

https://github.com/pre-commit/pre-commit-mirror-maker/blob/aea1d0ff0765295f779cc2e8dc5a43d05bcb3887/pre_commit_mirror_maker/languages.py#L21-L24

Yet, the resulting `setup.py` needs to have `clevercsv[full]` in its `install_requires` that the installed package can function properly → Thus, one would need to strip off any `[..]` from the `package_name` for URL creation.

Is it too ugly to just do a `package_name.split("[")[0]`? Should be save though, as a bracket should not be an allow character in package names.

PS: Sorry for all the spam, this is the last one, i promise 😉

Discussion:

Patch:
diff --git a/pre_commit_mirror_maker/languages.py b/pre_commit_mirror_maker/languages.py
index e6aef84..ae86d2b 100644
--- a/pre_commit_mirror_maker/languages.py
+++ b/pre_commit_mirror_maker/languages.py
@@ -4,6 +4,7 @@ import json
 import subprocess
 import urllib.request
 
+from packaging import requirements
 from packaging import version
 
 
@@ -20,7 +21,8 @@ def node_get_package_versions(package_name: str) -> list[str]:
 
 
 def python_get_package_versions(package_name: str) -> list[str]:
-    url = f'https://pypi.org/pypi/{package_name}/json'
+    pypi_name = requirements.Requirement(package_name).name
+    url = f'https://pypi.org/pypi/{pypi_name}/json'
     resp = json.load(urllib.request.urlopen(url))
     return sorted(resp['releases'], key=lambda k: version.parse(k))
 


Test patch:
diff --git a/tests/languages_test.py b/tests/languages_test.py
index 8f5833f..07c59d8 100644
--- a/tests/languages_test.py
+++ b/tests/languages_test.py
@@ -23,6 +23,12 @@ def test_python_get_package_version_output():
     assert_all_text(ret)
 
 
+def test_python_get_package_version_extras_output():
+    ret = python_get_package_versions('bandit[yaml]')
+    assert ret
+    assert_all_text(ret)
+
+
 def test_ruby_get_package_version_output():
     ret = ruby_get_package_versions('scss-lint')
     assert ret