Skip to content

Commit

Permalink
global: deprecated pkg_resources parse_version
Browse files Browse the repository at this point in the history
Since we are only using parse_version for comparison (typically checking
that we are greater than some minimum version for tool or package), one
would think we can use packaging.version.parse as if it was parse_version

Unfortunately, this requires conforming to PEP-440 version definitions,
which does not work for e.g. autotools (2.72d) nor older openssl (1.1.1p).
We rely in these (and to be sure other) cases on the LegacyVersion behavior.

https://packaging.python.org/en/latest/specifications/version-specifiers/#summary-of-differences-from-pkg-resources-parse-version

"This specification purposely restricts the syntax which constitutes a
valid version while pkg_resources.parse_version attempts to provide some
meaning from any arbitrary string."

In order to have the least impact to the overall code, we instead add
packaging_legacy to requirements.txt and use packaging_legacy.version.parse
as if it was parse_version.

https://pypi.org/project/packaging-legacy/
pypa/packaging#407

Since pypi.org itself is depending on packaging_legacy (in fact, a pypi dev
developed the package), we can expect it to be supported for quite some time.

pypi/warehouse#13500

[YOCTO #15348]

Signed-off-by: Tim Orling <tim.orling@konsulko.com>
  • Loading branch information
moto-timo committed Jan 23, 2024
1 parent 0f3299e commit 83378f2
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion layerindex/update.py
Expand Up @@ -17,7 +17,7 @@
import logging
import subprocess
from datetime import datetime, timedelta
from pkg_resources import parse_version
from packaging_legacy.version import parse as parse_version
import utils
import operator
import re
Expand Down
2 changes: 1 addition & 1 deletion layerindex/update_layer.py
Expand Up @@ -19,7 +19,7 @@
import tempfile
import shutil
import errno
from pkg_resources import parse_version
from packaging_legacy.version import parse as parse_version
import itertools
import utils
import recipeparse
Expand Down
2 changes: 1 addition & 1 deletion layerindex/views.py
Expand Up @@ -11,7 +11,7 @@
import re
from datetime import datetime
from itertools import islice
from pkg_resources import parse_version
from packaging_legacy.version import parse as parse_version

import reversion
from django import forms
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -24,6 +24,7 @@ gitdb==4.0.11
GitPython==3.1.41
kombu==5.3.4
mysqlclient==2.2.1
packaging_legacy==23.0.post0
Pillow==10.2.0
prompt-toolkit==3.0.43
python-dateutil==2.8.2
Expand Down
2 changes: 1 addition & 1 deletion rrs/tools/upgrade_history_internal.py
Expand Up @@ -16,7 +16,7 @@
import optparse
import logging
import re
from pkg_resources import parse_version
from packaging_legacy.version import parse as parse_version
import git
from datetime import datetime
import calendar
Expand Down

0 comments on commit 83378f2

Please sign in to comment.