Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid version: '1.19.7ubuntu3' #280

Closed
serghov opened this issue Dec 9, 2022 · 5 comments
Closed

Invalid version: '1.19.7ubuntu3' #280

serghov opened this issue Dec 9, 2022 · 5 comments

Comments

@serghov
Copy link
Contributor

serghov commented Dec 9, 2022

appimage-builder seems to fail with some apt dependencies with versions that are incompatible with PEP 440.

Traceback (most recent call last):
  File "/root/.local/bin/appimage-builder", line 11, in <module>
    sys.exit(__main__())
  File "/root/.local/lib/python3.8/site-packages/appimagebuilder/__main__.py", line 44, in __main__
    invoker.execute(commands)
  File "/root/.local/lib/python3.8/site-packages/appimagebuilder/invoker.py", line 29, in execute
    command()
  File "/root/.local/lib/python3.8/site-packages/appimagebuilder/commands/apt_deploy.py", line 46, in __call__
    deployed_packages = apt_deploy.deploy(
  File "/root/.local/lib/python3.8/site-packages/appimagebuilder/modules/deploy/apt/deploy.py", line 40, in deploy
    self._prepare_apt_venv()
  File "/root/.local/lib/python3.8/site-packages/appimagebuilder/modules/deploy/apt/deploy.py", line 56, in _prepare_apt_venv
    apt_core_packages = self._remove_old_packages(apt_core_packages)
  File "/root/.local/lib/python3.8/site-packages/appimagebuilder/modules/deploy/apt/deploy.py", line 112, in _remove_old_packages
    if package > latest_packages[pkg_tuple]:
  File "/root/.local/lib/python3.8/site-packages/appimagebuilder/modules/deploy/apt/package.py", line 79, in __gt__
    return version.parse(self.version) > version.parse(other.version)
  File "/root/.local/lib/python3.8/site-packages/packaging/version.py", line 52, in parse
    return Version(version)
  File "/root/.local/lib/python3.8/site-packages/packaging/version.py", line 197, in __init__
    raise InvalidVersion(f"Invalid version: '{version}'")
packaging.version.InvalidVersion: Invalid version: '1.19.7ubuntu3'

This happens because appiamge-builder uses python packaging module to parse versions of apt packages.

There are several similar issues in other projects;

https://github.com/python-poetry/poetry/issues/6013
https://github.com/python-poetry/poetry/issues/2167#issuecomment-748436046
https://bugs.launchpad.net/ubuntu/+source/python-debian/+bug/1926870

As a quick and dirty workaround I made the following .patch

diff --git a/package.py b/package.py
index 792a724..d8175a4 100644
--- a/.local/lib/python3.8/site-packages/appimagebuilder/modules/deploy/apt/package.py
+++ b/package.py
@@ -76,7 +76,7 @@ class Package:
 
     def __gt__(self, other):
         if isinstance(other, Package):
-            return version.parse(self.version) > version.parse(other.version)
+            return version.parse(self.version.replace("ubuntu", "")) > version.parse(other.version.replace("ubuntu", ""))
 
     def __hash__(self):
         return self.__str__().__hash__()

This will work for this particular case where there is "ubuntu" in the version name, however should be a more robust solution for this.

@ianconsolata
Copy link

ianconsolata commented Dec 11, 2022

This is breaking all our builds using appimage-builder. @serghov can you explain how you applied that patch to get it working again?

@serghov
Copy link
Contributor Author

serghov commented Dec 11, 2022

@ianconsolata it broke my CI pipeline, that is why I posted the patch here.
Just use something like this

patch -u ~/.local/lib/python3.8/site-packages/appimagebuilder/modules/deploy/apt/package.py -i appimagebuilder-patch.patch

In case your appimagebuilder is installed globally, the file might in a different place.

Note: This is a very very very hacky way of doing things, please don't use this solution long term.

@g-bougard
Copy link

Hi,
getting the same issue, following this fix and following another advice on the linked launchpad issue, I added the following script to my repo which I'm starting between the appimage-builder pip install and its usage.

#! /bin/bash

# Patch appimage-builder installed via pip has it fails to parse few packages version
# See https://github.com/AppImageCrafters/appimage-builder/issues/280

set -e

LOCATION="$( pip show appimage-builder | grep Location: | sed -re 's/^Location: //' )"

cd "$LOCATION/appimagebuilder/modules/deploy/apt"

patch -p1 <<PACKAGE_PY_PATCH
diff --git a/package.py b/package.py
--- a/package.py
+++ b/package.py
@@ -76,7 +76,7 @@ class Package:
 
     def __gt__(self, other):
         if isinstance(other, Package):
-            return version.parse(self.version) > version.parse(other.version)
+            return version.parse(self.version.replace("ubuntu", "+ubuntu")) > version.parse(other.version.replace("ubuntu", "+ubuntu"))
 
     def __hash__(self):
         return self.__str__().__hash__()
PACKAGE_PY_PATCH

I follow the patch from @serghov (Thank you for the idea), but the purpose here is to better replace "ubuntu" by "+ubuntu" so the version parsing doesn't fail and this won't corrupt the version is a number is behind the "ubuntu" string. This is what I understood after reading the launchpad issue.

The script also find the right path to the "package.py" file installed via pip so you can use the script out-of-the-box in a GH Actions workflow.

Here is my resulting commit which fixes our GH Actions building workflow: 0818da1

Thank again @serghov for the quick, even if temporary, fix.

@iTrooz
Copy link
Contributor

iTrooz commented Dec 17, 2022

+1 here
Thanks @serghov for the fix !

@serghov
Copy link
Contributor Author

serghov commented Dec 22, 2022

Closed by #281

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants