8000 Add support to patch sources after download by solvingj · Pull Request #60 · codrsquad/portable-python · GitHub
[go: up one dir, main page]

Skip to content

Add support to patch sources after download #60

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

Merged
merged 2 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions portable-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,11 @@ cpython-additional-packages:
# openssl-configure:
# - -v
# - --openssldir=/etc/ssl


# 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"
13 changes: 13 additions & 0 deletions src/portable_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ def cfg_configure(self, deps_lib):
configure_template = Template(configure)
return configure_template.substitute(deps_lib=deps_lib)

def cfg_patches(self):
return PPG.config.get_value("%s-patches" % self.m_name)

@property
def url(self):
"""Url of source tarball, if any"""
Expand Down Expand Up @@ -650,6 +653,7 @@ def compile(self):
folder = folder / self.m_build_cwd

with runez.CurrentFolder(folder):
self._apply_patches()
self._prepare()
func()
self._finalize()
Expand All @@ -663,6 +667,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}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: looks like patch_file() was naturally never called before in dryrun mode, but this could go in the patch_file() function itself (so that other places don't have to do/repeat if dryrun)

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 = {}
Expand Down
0