From 7bd1bf6a8b219c31e5a83ba3e78b6eca1efcaeb0 Mon Sep 17 00:00:00 2001 From: jwiltse Date: Wed, 5 Feb 2025 13:29:28 -0500 Subject: [PATCH] Add support to patch dep sources after download --- portable-python.yml | 7 +++++++ src/portable_python/__init__.py | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/portable-python.yml b/portable-python.yml index 1a46319..2c05172 100644 --- a/portable-python.yml +++ b/portable-python.yml @@ -19,3 +19,10 @@ folders: cpython-additional-packages: # - Pillow==10.0.0 # - flake8==6.0.0 + +# Uncomment if you need to patch the source code of a module before compiling it +#cpython-modules: zlib +#zlib-patches: +# - file: configure +# regex: "# start off configure.log" +# replacement: "echo starting zlib configure script with patches" diff --git a/src/portable_python/__init__.py b/src/portable_python/__init__.py index c854051..7e01f2e 100644 --- a/src/portable_python/__init__.py +++ b/src/portable_python/__init__.py @@ -491,6 +491,9 @@ def is_usable_module(self, name): def cfg_version(self, default): return PPG.config.get_value("%s-version" % self.m_name) or default + def cfg_patches(self): + return PPG.config.get_value("%s-patches" % self.m_name) + @property def url(self): """Url of source tarball, if any""" @@ -639,6 +642,7 @@ def compile(self): folder = folder / self.m_build_cwd with runez.CurrentFolder(folder): + self._apply_patches() self._prepare() func() self._finalize() @@ -652,6 +656,15 @@ def compile(self): else: os.environ[k] = v + def _apply_patches(self): + if patches := self.cfg_patches(): + for patch in patches: + if runez.DRYRUN: + print(f"Would apply patch: {patch}") + else: + print(f"Applying patch: {patch}") + patch_file(patch["file"], patch["regex"], patch["replacement"]) + def _get_env_vars(self): """Yield all found env vars, first found wins""" result = {}