From 6168557feabe032a372c21198322f587229b6eea Mon Sep 17 00:00:00 2001 From: Marcelo Duarte Date: Fri, 17 May 2024 20:48:04 -0300 Subject: [PATCH 1/2] bdist_deb: catch a cpio 3.13 bug --- cx_Freeze/command/bdist_deb.py | 18 +++++++++++++++--- tests/test_command_bdist_deb.py | 12 ++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/cx_Freeze/command/bdist_deb.py b/cx_Freeze/command/bdist_deb.py index 637cd7d77..200e82130 100644 --- a/cx_Freeze/command/bdist_deb.py +++ b/cx_Freeze/command/bdist_deb.py @@ -77,7 +77,7 @@ def run(self) -> None: rpm_filename = None for command, _, filename in self.distribution.dist_files: if command == "bdist_rpm": - rpm_filename = filename + rpm_filename = os.path.basename(filename) break if rpm_filename is None: msg = "could not build rpm" @@ -87,14 +87,26 @@ def run(self) -> None: # convert rpm to deb (by default in dist directory) logging.info("building DEB") - cmd = ["alien", "--to-deb", os.path.basename(rpm_filename)] + cmd = ["alien", "--to-deb", rpm_filename] if os.getuid() != 0: cmd.insert(0, "fakeroot") if self.dry_run: self.spawn(cmd) else: logging.info(subprocess.list2cmdline(cmd)) - output = subprocess.check_output(cmd, text=True, cwd=self.dist_dir) + process = subprocess.run( + cmd, + text=True, + capture_output=True, + check=False, + cwd=self.dist_dir, + ) + if process.returncode != 0: + msg = process.stderr.splitlines()[0] + if msg.startswith(f"Unpacking of '{rpm_filename}' failed at"): + msg = f"{msg}\n\t\x08Please check if you have `cpio 2.13` on Ubuntu 22.04.\n\t\x08You can try to install a previous version:\n\t\x08$ sudo apt-get install cpio=2.13+dfsg-7" + raise ExecError(msg) + output = process.stdout logging.info(output) filename = output.splitlines()[0].split()[0] filename = os.path.join(self.dist_dir, filename) diff --git a/tests/test_command_bdist_deb.py b/tests/test_command_bdist_deb.py index 68d3c67b5..6ff98827d 100644 --- a/tests/test_command_bdist_deb.py +++ b/tests/test_command_bdist_deb.py @@ -88,10 +88,12 @@ def test_bdist_deb_simple(datafiles: Path) -> None: check=False, cwd=datafiles, ) - print(process.stdout) if process.returncode != 0: - if "failed to find 'alien'" in process.stderr: + msg = process.stderr + if "failed to find 'alien'" in msg: pytest.xfail("alien not installed") + elif "Unpacking of '" in msg and "' failed at" in msg: + pytest.xfail("cpio 2.13 bug") else: pytest.fail(process.stderr) @@ -114,10 +116,12 @@ def test_bdist_deb(datafiles: Path) -> None: check=False, cwd=datafiles, ) - print(process.stdout) if process.returncode != 0: - if "failed to find 'alien'" in process.stderr: + msg = process.stderr + if "failed to find 'alien'" in msg: pytest.xfail("alien not installed") + elif "Unpacking of '" in msg and "' failed at" in msg: + pytest.xfail("cpio 2.13 bug") else: pytest.fail(process.stderr) From 530aa971b1bd56fcffcc3e4df17e11229c6af888 Mon Sep 17 00:00:00 2001 From: Marcelo Duarte Date: Fri, 17 May 2024 21:04:08 -0300 Subject: [PATCH 2/2] revert a ruff's overkill --- cx_Freeze/command/bdist_deb.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cx_Freeze/command/bdist_deb.py b/cx_Freeze/command/bdist_deb.py index 200e82130..4011dad36 100644 --- a/cx_Freeze/command/bdist_deb.py +++ b/cx_Freeze/command/bdist_deb.py @@ -104,7 +104,13 @@ def run(self) -> None: if process.returncode != 0: msg = process.stderr.splitlines()[0] if msg.startswith(f"Unpacking of '{rpm_filename}' failed at"): - msg = f"{msg}\n\t\x08Please check if you have `cpio 2.13` on Ubuntu 22.04.\n\t\x08You can try to install a previous version:\n\t\x08$ sudo apt-get install cpio=2.13+dfsg-7" + info = [ + "\n\t\x08Please check if you have `cpio 2.13` on " + "Ubuntu 22.04.", + "\t\x08You can try to install a previous version:", + "\t\x08$ sudo apt-get install cpio=2.13+dfsg-7", + ] + msg += "\n".join(info) raise ExecError(msg) output = process.stdout logging.info(output)