Skip to content

Commit be3a6d0

Browse files
support patches in pip package
1 parent d1a3a77 commit be3a6d0

File tree

7 files changed

+106
-1
lines changed

7 files changed

+106
-1
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
include src/west/west-commands-schema.yml
22
include src/west/manifest-schema.yml
33
include src/west/py.typed
4+
recursive-include patches *.patch

build_backend.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python3
2+
3+
import subprocess
4+
5+
from pathlib import Path
6+
from setuptools.build_meta import build_wheel as actual_build_wheel
7+
from setuptools.build_meta import prepare_metadata_for_build_wheel as actual_prepare_metadata_for_build_wheel
8+
9+
def apply_patches():
10+
print("Info: Function apply_patches()")
11+
patch_dir = Path(__file__).parent / "patches"
12+
for patch in sorted(patch_dir.glob("*.patch")):
13+
print(f"Applying patch: {patch.name}")
14+
#subprocess.check_call(["patch", "-p1", "-i", str(patch)])
15+
subprocess.check_call(["git", "am", str(patch)])
16+
17+
def prepare_metadata_for_build_wheel(*args, **kwargs):
18+
print("Info: Function prepare_metadata_for_build_wheel()")
19+
apply_patches()
20+
return actual_prepare_metadata_for_build_wheel(*args, **kwargs)
21+
22+
def build_wheel(*args, **kwargs):
23+
print("Info: Function build_wheel()")
24+
apply_patches()
25+
return actual_build_wheel(*args, **kwargs)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build-system]
22
requires = ["setuptools>=77.0.3"]
3-
build-backend = "setuptools.build_meta"
3+
build-backend = "build_backend"
44

55
[project]
66
name = "west"

scripts/create-patches.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
GIT_ROOT=$(git rev-parse --show-toplevel)
4+
PATCH_DIR="$GIT_ROOT/patches"
5+
6+
# original remote
7+
REMOTE_NAME="original"
8+
REMOTE_BRANCH="main"
9+
10+
# create patch files for each commit from FORK_BRANCH not in REMOTE_BRANCH
11+
mkdir -p "$PATCH_DIR"
12+
git format-patch "$REMOTE_NAME/$REMOTE_BRANCH" -o "$PATCH_DIR"
13+
14+
echo "Done!"

scripts/create-wheel.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
GIT_ROOT=$(git rev-parse --show-toplevel)
4+
PATCH_DIR="$GIT_ROOT/patches"
5+
6+
cd $GIT_ROOT
7+
PYTHONPATH="." python3 -m build --wheel

scripts/merge_upstream.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# original remote
4+
REMOTE_NAME="original"
5+
REMOTE_BRANCH="main"
6+
7+
# fork details
8+
FORK_NAME="fork"
9+
FORK_BRANCH="main-with-patches"
10+
11+
# fetch fork and original remote
12+
git fetch fork
13+
git fetch original
14+
15+
# checkout FORK_BRANCH from fork
16+
git checkout -B "$FORK_BRANCH" "fork/$FORK_BRANCH" || \
17+
git checkout -b "$FORK_BRANCH" "original/$REMOTE_BRANCH"
18+
19+
# merge REMOTE_BRANCH into FORK_BRANCH to keep a linear history
20+
git merge "original/$REMOTE_BRANCH" || (
21+
echo "Merge encountered conflicts. Please resolve them and run 'git merge --continue' or abort"
22+
)
23+
24+
echo "Done!"

scripts/rebase_fork.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
# original remote
4+
ORIGINAL_URL="https://github.com/zephyrproject-rtos/west.git"
5+
REMOTE_BRANCH="main"
6+
7+
# fork details
8+
FORK_URL="https://github.com/thorsten-klein/west.git"
9+
FORK_BRANCH="main-with-patches"
10+
11+
# add remote "fork" if not already exists
12+
if ! git remote | grep -q "^fork$"; then
13+
git remote add fork "$FORK_URL"
14+
fi
15+
16+
# add remote original if not already exists
17+
if ! git remote | grep -q "^original$"; then
18+
git remote add original "$ORIGINAL_URL"
19+
fi
20+
21+
# fetch fork and original remote
22+
git fetch fork
23+
git fetch original
24+
25+
# checkout FORK_BRANCH from fork
26+
git checkout -B "$FORK_BRANCH" "fork/$FORK_BRANCH" || \
27+
git checkout -b "$FORK_BRANCH" "original/$REMOTE_BRANCH"
28+
29+
# rebase FORK_BRANCH onto REMOTE_BRANCH
30+
git rebase "original/$REMOTE_BRANCH" || (
31+
echo "Rebase encountered conflicts. Please resolve them and run 'git rebase --continue' or abort"
32+
)
33+
34+
echo "Done!"

0 commit comments

Comments
 (0)