From 38faeca62ebd5be89b1ec3e6c530e499ce2d7240 Mon Sep 17 00:00:00 2001 From: Ernesto de Gracia Herranz Date: Thu, 4 Jul 2024 11:04:38 +0000 Subject: [PATCH] replace package.version.Version by internal code This drops the dependency on the Python `packaging` module. Signed-off-by: Ernesto de Gracia Herranz --- .gitlab-ci.yml | 1 - .gitlab-ci/debian-stable.Dockerfile | 1 - .gitlab-ci/fedora.Dockerfile | 1 - .gitlab-ci/test-msvc.bat | 2 +- .gitlab-ci/test-msys2.sh | 2 -- gio/gdbus-2.0/codegen/utils.py | 29 +++++++++++++++++++++++++++-- meson.build | 2 +- 7 files changed, 29 insertions(+), 9 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8180003cd..bc008796e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 diff --git a/.gitlab-ci/debian-stable.Dockerfile b/.gitlab-ci/debian-stable.Dockerfile index 4bcee4e2c..cdcfdc293 100644 --- a/.gitlab-ci/debian-stable.Dockerfile +++ b/.gitlab-ci/debian-stable.Dockerfile @@ -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 \ diff --git a/.gitlab-ci/fedora.Dockerfile b/.gitlab-ci/fedora.Dockerfile index f13f0427e..745d804b5 100644 --- a/.gitlab-ci/fedora.Dockerfile +++ b/.gitlab-ci/fedora.Dockerfile @@ -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 \ diff --git a/.gitlab-ci/test-msvc.bat b/.gitlab-ci/test-msvc.bat index 02f8b0753..6fddb36a4 100644 --- a/.gitlab-ci/test-msvc.bat +++ b/.gitlab-ci/test-msvc.bat @@ -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 diff --git a/.gitlab-ci/test-msys2.sh b/.gitlab-ci/test-msys2.sh index e03cccf15..e2700f7a6 100755 --- a/.gitlab-ci/test-msys2.sh +++ b/.gitlab-ci/test-msys2.sh @@ -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 diff --git a/gio/gdbus-2.0/codegen/utils.py b/gio/gdbus-2.0/codegen/utils.py index 2863557b8..6cfa8f7d7 100644 --- a/gio/gdbus-2.0/codegen/utils.py +++ b/gio/gdbus-2.0/codegen/utils.py @@ -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] diff --git a/meson.build b/meson.build index de82c0049..29b61fc40 100644 --- a/meson.build +++ b/meson.build @@ -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'