Skip to content
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@ re-vendor run by the vendored-tree check on every pull request.
[Mutator](https://github.com/unclebob/mutator) are vendored under
`src/ub_cli/vendor` at the commits in `src/ub_cli/vendor/VENDORED`, with their
imports rewritten to `ub_cli.vendor`. Never edit that directory by hand.
A fix not yet upstream goes in `scripts/vendor-patches/NAME-*.patch`, which
`scripts/vendor.py` applies after vendoring; delete the patch once the pin
includes the fix. Current patch: `mutator` decodes test output with
`errors="replace"`, so output that is not valid UTF-8 no longer crashes a run.
`make check-upstreams` compares the pins with upstream and prints the update
command, `python scripts/vendor.py NAME COMMIT`. The CI and Release workflows
fail when the directory differs from what `scripts/vendor.py` produces.
Expand Down
12 changes: 12 additions & 0 deletions scripts/vendor-patches/mutator-runner-undecodable-output.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/src/ub_cli/vendor/mutator/runner.py b/src/ub_cli/vendor/mutator/runner.py
index e554c76..fb73927 100644
--- a/src/ub_cli/vendor/mutator/runner.py
+++ b/src/ub_cli/vendor/mutator/runner.py
@@ -97,6 +97,7 @@ class CommandRunner:
stderr=subprocess.STDOUT,
start_new_session=True,
text=True,
+ errors="replace",
env=environment,
)
except OSError as exc:
8 changes: 7 additions & 1 deletion scripts/vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
installs top-level packages that collide with unrelated PyPI projects of the same name.
The directory is named `vendor` because the engines skip directories of that name,
so `ub crap`, `ub dry`, `ub mutate`, and `ub check` never analyze the engines themselves.
Never edit vendored code by hand; change the pin and rerun this script.
After the rewrite, each scripts/vendor-patches/NAME-*.patch is applied with `git apply`,
for fixes not yet upstream; delete a patch once the pin includes its fix.
Never edit vendored code by hand; change the pin or add a patch and rerun this script.
"""

import re
Expand All @@ -20,6 +22,7 @@
ROOT = Path(__file__).resolve().parents[1]
VENDOR = ROOT / "src" / "ub_cli" / "vendor"
PINS = VENDOR / "VENDORED"
PATCHES = ROOT / "scripts" / "vendor-patches"
ENGINES = ("crapper", "dryer", "mutator")
NAMES = "|".join(ENGINES)
FROM_IMPORT = re.compile(rf"^(\s*)from ({NAMES})(\.[\w.]+)? import ", re.M)
Expand Down Expand Up @@ -65,6 +68,9 @@ def vendor(name: str, url: str, commit: str) -> None:
shutil.copyfile(checkout / "LICENSE", target / "LICENSE")
for path in sorted(target.rglob("*.py")):
path.write_text(rewrite(path.read_text(), path))
for patch in sorted(PATCHES.glob(f"{name}-*.patch")):
subprocess.run(["git", "apply", str(patch)], cwd=ROOT, check=True)
print(f"{name}: applied {patch.name}")
print(f"{name}: vendored {commit[:12]}")


Expand Down
1 change: 1 addition & 0 deletions src/ub_cli/vendor/mutator/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def run(self, command: Command, cwd: Path, timeout: float | None) -> CommandResu
stderr=subprocess.STDOUT,
start_new_session=True,
text=True,
errors="replace",
env=environment,
)
except OSError as exc:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_vendor.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import importlib.util
import sys
import unittest
from pathlib import Path

from ub_cli.vendor.crapper.discover import iter_source_files as crap_files
from ub_cli.vendor.dryer.discover import iter_source_files as dry_files
from ub_cli.vendor.mutator.runner import CommandRunner

SCRIPT = Path(__file__).resolve().parents[1] / "scripts" / "vendor.py"
spec = importlib.util.spec_from_file_location("vendor", SCRIPT)
Expand Down Expand Up @@ -53,5 +55,13 @@ def test_engines_skip_the_vendored_tree(self):
self.assertFalse([path for path in files if vendor.VENDOR in path.parents])


class PatchTests(unittest.TestCase):
def test_test_output_that_is_not_utf8_does_not_crash_mutator(self):
# scripts/vendor-patches/mutator-runner-undecodable-output.patch
emit = "import sys; sys.stdout.buffer.write(bytes([111, 107, 255])); sys.exit(3)"
result = CommandRunner().run([sys.executable, "-c", emit], Path.cwd(), 30)
self.assertEqual((result.code, result.output), (3, "ok\ufffd"))


if __name__ == "__main__":
unittest.main()
Loading