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
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ jobs:
- uses: mlugg/setup-zig@d1434d08867e3ee9daa34448df10607b98908d29 # v2.2.1
with:
version: 0.17.1
# The decimal digit table is pinned to Unicode 16.0.0, the unicodedata
# of Python 3.14; the parity test skips its comparison under another.
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.14"
- run: zig fmt --check build.zig build.zig.zon src tests
- run: zig build test --summary all
- name: parity with python's json and text calls
Expand All @@ -43,6 +48,14 @@ jobs:
fi
zig build fs-lock-parity-probe
python3 tests/test_fs_lock_parity.py
- name: parity with python's tempfile.gettempdir
run: |
if ! command -v python3 >/dev/null 2>&1; then
echo "python3 not found, skipping the parity test"
exit 0
fi
zig build tempdir-probe
python3 tests/test_gettempdir_parity.py
- name: no site names in the tree
run: |
! git grep -nIiE 'snellius|surf\.nl|/gpfs/|/projects/0|rg\.terra|scratch-shared' -- . ':!.github/workflows/ci.yml'
Expand Down
21 changes: 21 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,27 @@ pub fn build(b: *std.Build) void {
const install_ap_probe = b.addInstallArtifact(ap_probe, .{});
b.step("argparse-parity-probe", "Build the argparse parity probe").dependOn(&install_ap_probe.step);

// Rewrite src/pytext_nd.zig from the Python on PATH, which moves the
// table's Unicode pin to that Python's. The library never needs Python
// to build; tests/test_json_pytext_parity.py fails when the file no
// longer matches unicodedata of the Unicode version it is pinned to.
const gen_nd = b.addSystemCommand(&.{ "python3", "tools/gen_pytext_nd.py" });
const update_nd = b.addUpdateSourceFiles();
update_nd.addCopyFileToSource(gen_nd.captureStdOut(.{}), "src/pytext_nd.zig");
b.step("gen-pytext-nd", "Regenerate src/pytext_nd.zig from unicodedata").dependOn(&update_nd.step);

// The temporary directory probe, whose output
// tests/test_gettempdir_parity.py compares with tempfile.gettempdir.
const tempdir_mod = b.createModule(.{
.root_source_file = b.path("tests/tempdir_probe.zig"),
.target = target,
.optimize = optimize,
});
tempdir_mod.addImport("zig_common", mod);
const tempdir_probe = b.addExecutable(.{ .name = "tempdir_probe", .root_module = tempdir_mod });
const install_tempdir = b.addInstallArtifact(tempdir_probe, .{});
b.step("tempdir-probe", "Build the tempfile parity probe").dependOn(&install_tempdir.step);

// The API reference from the doc comments, into <prefix>/docs.
const lib = b.addLibrary(.{ .name = "zig_common", .root_module = mod });
const docs = b.addInstallDirectory(.{
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+fsx-gettempdir.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `fsx.TempDir`, a port of `tempfile.gettempdir`. It probes the candidates from the environment first and the system directories after. Each probe is a file write, as in Python. The answer is made absolute and normalized, and it is kept for later calls. A failure gives the text of Python's FileNotFoundError, which lists the candidates. The `TempDir` owns the answer and the message, and `deinit` frees them. `fsx.tempDirCandidates` returns the list alone, and `fsx.freeTempDirCandidates` frees it.
1 change: 1 addition & 0 deletions changelog.d/+fsx-mkdtemp-report.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`fsx.mkdtempReport` is `mkdtemp` with a `Why`. A failed create reports the OSError text that Python gives, with the whole path it tried, random name included, in one repr.
1 change: 1 addition & 0 deletions changelog.d/+fsx-mkstemp.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `fsx.mkstemp` to create a private `0600` file with a random suffix under a given directory. The file is open for reading and writing. As in Python, a relative directory is made absolute, so the path is absolute. A refused open reports its path, so the caller can format the error as Python does.
1 change: 1 addition & 0 deletions changelog.d/+pytext-decimal-digits.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `pytext.decimalDigit` and `pytext.decimalToAscii`. They read the decimal digits of every script as Python's `float()` and `int()` do. A generator script under tools builds the table from `unicodedata`, and the table is pinned to Unicode 16.0.0, the data of Python 3.14.
2 changes: 2 additions & 0 deletions docs/orgmode/explanation/python-compatibility.org
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ A cache entry the other build cannot read is a miss on every task, and a journal
Text stays bytes, read as Python reads them.
A Python tool decodes a byte string from the system with surrogateescape, so a byte that is not UTF-8 becomes one character, U+DC80 to U+DCFF, which encodes back to the same byte.
[[zig:zig_common.pytext.nextChar]] reads a byte string as that decoder does, and [[zig:zig_common.pytext.pyStrip]], [[zig:zig_common.pytext.pySplit]], [[zig:zig_common.pytext.shellQuote]] and [[zig:zig_common.json.pyTextLess]], Python's string order, work on those characters.
[[zig:zig_common.pytext.decimalToAscii]] writes the decimal digits of any script as ASCII digits, as =float()= and =int()= read their text, from a table that =tools/gen_pytext_nd.py= generates from =unicodedata=.
The table is pinned to Unicode 16.0.0, the data of Python 3.14, and its parity test compares it only under a Python with that data.

JSON strings come in the two encodings the tools used:

Expand Down
2 changes: 2 additions & 0 deletions docs/orgmode/reference/api.org
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ Error sets: [[zig:zig_common.json.ParseError]], [[zig:zig_common.json.DecodeErro
| [[zig:zig_common.pytext.decodeReplace]]| =Allocator.Error= |
| [[zig:zig_common.pytext.pyWhitespace]] | none |
| [[zig:zig_common.pytext.pyStrip]] | none |
| [[zig:zig_common.pytext.decimalDigit]] | none |
| [[zig:zig_common.pytext.decimalToAscii]]| =Allocator.Error= |
| [[zig:zig_common.pytext.pySplit]] | =Allocator.Error= |
| [[zig:zig_common.pytext.shellQuote]] | =Allocator.Error= |
| [[zig:zig_common.pytext.reprStr]] | =Allocator.Error= |
Expand Down
Loading
Loading