replace package.version.Version by internal code

This drops the dependency on the Python `packaging` module.

Signed-off-by: Ernesto de Gracia Herranz <ernestodgh@jfrog.com>
This commit is contained in:
Ernesto de Gracia Herranz 2024-07-04 11:04:38 +00:00 committed by Philip Withnall
parent 5de4d59c31
commit 38faeca62e
7 changed files with 29 additions and 9 deletions

View File

@ -691,7 +691,6 @@ macos-x86_64:
- source .venv/bin/activate
- pip3 install meson==1.2.3
- pip3 install ninja==1.11.1
- pip3 install packaging==23.2
script:
# FIXME: Use --wrap-mode=default so we download dependencies each time,
# until the macOS runner is a VM where we can use a pre-made image which

View File

@ -37,7 +37,6 @@ RUN apt-get update -qq && apt-get install --no-install-recommends -qq -y \
locales \
ninja-build \
python3 \
python3-packaging \
python3-pip \
python3-setuptools \
python3-wheel \

View File

@ -50,7 +50,6 @@ RUN dnf -y update \
pcre2-devel \
"python3-dbusmock >= 0.18.3-2" \
python3-docutils \
python3-packaging \
python3-pip \
python3-pygments \
python3-wheel \

View File

@ -12,7 +12,7 @@ for %%x in (%*) do (
set args=%args:~1%
:: FIXME: make warnings fatal
pip3 install --upgrade --user meson==1.2.3 packaging==23.2 || goto :error
pip3 install --upgrade --user meson==1.2.3 || goto :error
meson setup %args% _build || goto :error
meson compile -C _build || goto :error

View File

@ -29,8 +29,6 @@ CCACHE_BASEDIR="$(pwd)"
CCACHE_DIR="${CCACHE_BASEDIR}/_ccache"
export CCACHE_BASEDIR CCACHE_DIR
pip3 install --upgrade --user packaging==23.2
PATH="$(cygpath "$USERPROFILE")/.local/bin:$HOME/.local/bin:$PATH"
DIR="$(pwd)"
export PATH CFLAGS

View File

@ -23,6 +23,7 @@
import os
import sys
import re
import packaging.version
@ -162,11 +163,35 @@ def lookup_brief_docs(annotations):
def version_cmp_key(key):
# If the 'since' version is 'UNRELEASED', compare higher than anything else
# If it is empty put a 0 in its place as this will
# allow LooseVersion to work and will always compare lower.
# allow _parse_version() to work and will always compare lower.
if key[0] == "UNRELEASED":
v = "9999"
elif key[0]:
v = str(key[0])
else:
v = "0"
return (packaging.version.Version(v), key[1])
return (_parse_version(v), key[1])
def _parse_version(version):
"""
Parse a version string into a list of integers and strings.
This function takes a version string and breaks it down into its component parts.
It separates numeric and non-numeric segments, converting numeric segments to integers.
Args:
version (str): The version string to parse.
Returns:
list: A list where each element is either an integer (for numeric parts)
or a string (for non-numeric parts).
Example:
>>> parseversion("1.2.3a")
[1, 2, 3, 'a']
>>> parseversion("2.0.0-rc1")
[2, 0, 0, 'rc1']
"""
blocks = re.findall(r"(\d+|\w+)", version)
return [int(b) if b.isdigit() else b for b in blocks]

View File

@ -2457,7 +2457,7 @@ endif
glib_conf.set('HAVE_PROC_SELF_CMDLINE', have_proc_self_cmdline)
python = import('python').find_installation(modules: ['packaging'])
python = import('python').find_installation()
python_version = python.language_version()
python_version_req = '>=3.7'