Repository: pypi/warehouse

Issue:
Unpin constraint on `packaging`
This was constrained in https://github.com/pypi/warehouse/pull/12664/ due to https://github.com/googleapis/python-bigquery/issues/1435 which is now resolved:

https://github.com/pypi/warehouse/blob/186180c600da5a99a7bdc0da548f852351d91e84/requirements/deploy.in#L4

We attempted to unconstrain it in https://github.com/pypi/warehouse/pull/12871, however due to https://github.com/pypa/packaging/pull/407, we can't migrate to the latest version until https://github.com/pypa/packaging/pull/669 is resolved.


Discussion:
This now needs a release of `packaging` which includes https://github.com/pypa/packaging/pull/669, a release of https://github.com/di/packaging_legacy, and an update here to use that dependency.

Resolving patch:
diff --git a/warehouse/forklift/legacy.py b/warehouse/forklift/legacy.py
--- a/warehouse/forklift/legacy.py
+++ b/warehouse/forklift/legacy.py
@@ -25,6 +25,7 @@
 import packaging.specifiers
 import packaging.utils
 import packaging.version
+import packaging_legacy.version
 import pkg_resources
 import requests
 import wtforms
@@ -214,10 +215,10 @@ def _exc_with_message(exc, message, **kwargs):
 
 
 def _validate_pep440_version(form, field):
-    parsed = packaging.version.parse(field.data)
-
     # Check that this version is a valid PEP 440 version at all.
-    if not isinstance(parsed, packaging.version.Version):
+    try:
+        parsed = packaging.version.parse(field.data)
+    except packaging.version.InvalidVersion:
         raise wtforms.validators.ValidationError(
             "Start and end with a letter or numeral containing only "
             "ASCII numeric and '.', '_' and '-'."
@@ -1163,7 +1164,7 @@ def file_upload(request):
         .all()
     )
     for i, r in enumerate(
-        sorted(releases, key=lambda x: packaging.version.parse(x.version))
+        sorted(releases, key=lambda x: packaging_legacy.version.parse(x.version))
     ):
         r._pypi_ordering = i
 


Test patch:
diff --git a/requirements/tests.in b/requirements/tests.in
--- a/requirements/tests.in
+++ b/requirements/tests.in
@@ -7,5 +7,3 @@ pytest-postgresql>=3.1.3,<4.0.0
 pytest-socket
 responses>=0.5.1
 webtest
-# Until resolved https://github.com/googleapis/python-bigquery/issues/1435
-packaging<22.0
diff --git a/requirements/tests.txt b/requirements/tests.txt
--- a/requirements/tests.txt
+++ b/requirements/tests.txt
@@ -183,12 +183,10 @@ mirakuru==2.5.1 \
     --hash=sha256:0a16f897841741f8cd784f790e54d74e61456ba36be9cb9de731b49e2e7a45dc \
     --hash=sha256:5a60d641fa92c8bfcd383f6e52f7a0bf3f081da0467fc6e3e6a3f6b3e3e47a7b
     # via pytest-postgresql
-packaging==21.3 \
-    --hash=sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb \
-    --hash=sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522
-    # via
-    #   -r requirements/tests.in
-    #   pytest
+packaging==23.1 \
+    --hash=sha256:994793af429502c4ea2ebf6bf664629d07c1a9fe974af92966e4b8d2df7edc61 \
+    --hash=sha256:a392980d2b6cffa644431898be54b0045151319d1e7ec34f0cfed48767dd334f
+    # via pytest
 pluggy==1.0.0 \
     --hash=sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159 \
     --hash=sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3
@@ -217,10 +215,6 @@ psutil==5.9.4 \
     --hash=sha256:efeae04f9516907be44904cc7ce08defb6b665128992a56957abc9b61dca94b7 \
     --hash=sha256:fd8522436a6ada7b4aad6638662966de0d61d241cb821239b2ae7013d41a43d4
     # via mirakuru
-pyparsing==3.0.9 \
-    --hash=sha256:2b020ecf7d21b687f219b71ecad3631f644a47f01403fa1d1036b0c6416d70fb \
-    --hash=sha256:5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc
-    # via packaging
 pytest==7.2.2 \
     --hash=sha256:130328f552dcfac0b1cec75c12e3f005619dc5f874f0a06e8ff7263f0ee6225e \
     --hash=sha256:c99ab0c73aceb050f68929bc93af19ab6db0558791c6a0715723abe9d0ade9d4