Bug 15348

Summary: layerindex: update_layer.py remove use of deprecated pkg_resources
Product: [Yocto Project Subprojects] Layer Index Reporter: Tim Orling <tim.orling>
Component: Layer IndexAssignee: Tim Orling <tim.orling>
Status: RESOLVED FIXED QA Contact: apoorv sangal <apoorvsangal>
Severity: normal    
Priority: Medium    
Version: 5.0   
Target Milestone: 5.0 M3   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: Don't know

Description Tim Orling 2024-01-17 01:31:19 UTC
/opt/layerindex/layerindex/update_layer.py:22: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
 
  from pkg_resources import parse_version
Comment 2 Tim Orling 2024-01-22 20:19:28 UTC
packaging.version.parse() seemed like a good replacement, but it cannot handle versions like autotools (2.72d) since it does not match the PEP-440 patterns for allowed Python package versions.

https://github.com/pypa/packaging/issues/631

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."

Which means that any Python which has "packaging" >= 22 will no longer parse LegacyVersion() and it throws an InvalidVersion exception with "packaging" == 21

Invalid version: '2.72e'

Probably better off using the vercmp code from lib/bb/utils.py.
Comment 3 Tim Orling 2024-01-23 01:08:32 UTC
pypi.org has a similar problem of needing the LegacyVersion behavior, so we use their packaging_legacy instead in v2:

https://patchwork.yoctoproject.org/project/yocto/patch/20240123001125.1470142-1-tim.orling@konsulko.com/