From de87c0e992f15353abc5b75634fb5d7b4f327340 Mon Sep 17 00:00:00 2001 From: Hilton Rudham Date: Thu, 9 Jul 2020 19:02:36 +0200 Subject: [PATCH] fixes #7: console_scripts file names now have the major python version appended for python3 --- src/_wheel2deb/debian.py | 18 +++++++++++++++++- testing/test_wheel2deb.py | 6 +++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/_wheel2deb/debian.py b/src/_wheel2deb/debian.py index 2319198..8d0037d 100644 --- a/src/_wheel2deb/debian.py +++ b/src/_wheel2deb/debian.py @@ -334,9 +334,25 @@ def run_install_scripts(self): config = configparser.ConfigParser() config.read_string(self.wheel.entrypoints) + # Some python debian packages have separate python2 and python3 + # Debian packages released. If a package has a `console_scripts` + # entry, and the python2 version of a debian package is already + # installed, when we attempt to install a python3 package created + # by wheel2deb, it will fail because apt will not let it overwrite + # an existing file. + # An example of this is the `pyjwt` package: for the officially + # released Debian packages, this creates `/usr/bin/pyjwt` (apt install + # python-jwt) and `/usr/bin/pyjwt3` (apt install python3-jwt). + # The code below follows a similar pattern, by appending the python + # major version to `console_scripts` entries for versions greater + # than three. + endpoint_python_version = "" + if self.pyvers.major >= 3: + endpoint_python_version = str(self.pyvers.major) + entrypoints = {} for section in config: - x = ['%s=%s' % k for k in config.items(section)] + x = ['%s%s=%s' % (k[0], endpoint_python_version, k[1]) for k in config.items(section)] if x: entrypoints[section] = x diff --git a/testing/test_wheel2deb.py b/testing/test_wheel2deb.py index 4beb610..6d9e5ed 100644 --- a/testing/test_wheel2deb.py +++ b/testing/test_wheel2deb.py @@ -87,8 +87,12 @@ def test_conversion(tmp_path, wheel_path): package_hash = digests(package_list[0]) + endpoint_python_version = "" + if sys.version_info[0] >= 3: + endpoint_python_version = str(sys.version_info[0]) + # check that the entrypoint will be installed in /usr/bin - entrypoint = (unpack_path / 'debian/python3-foobar/usr/bin/entrypoint') + entrypoint = (unpack_path / ('debian/python3-foobar/usr/bin/entrypoint'+endpoint_python_version)) assert entrypoint.exists() # check shebang