zig-zon 0.2.0__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {zig-zon-0.2.0 → zig-zon-0.2.2}/PKG-INFO +27 -2
- {zig-zon-0.2.0 → zig-zon-0.2.2}/build.zig +28 -22
- {zig-zon-0.2.0 → zig-zon-0.2.2}/build.zig.zon +4 -3
- zig-zon-0.2.2/pkg-info.zon +11 -0
- {zig-zon-0.2.0 → zig-zon-0.2.2}/setup.py +1 -1
- {zig-zon-0.2.0 → zig-zon-0.2.2}/setup.zig.json +1 -1
- {zig-zon-0.2.0 → zig-zon-0.2.2}/src/zig_zon.zig +14 -8
- {zig-zon-0.2.0 → zig-zon-0.2.2}/zig-pkg/zig_python_sdist/build.zig +10 -5
- {zig-zon-0.2.0 → zig-zon-0.2.2}/zig-pkg/zig_python_sdist/build.zig.zon +1 -0
- zig-zon-0.2.2/zig-pkg/zig_python_sdist/pkg-info.zon +11 -0
- {zig-zon-0.2.0 → zig-zon-0.2.2}/zig-pkg/zig_python_sdist/src/build/CPython.zig +1 -66
- {zig-zon-0.2.0 → zig-zon-0.2.2}/zig-pkg/zig_python_sdist/src/build/SDistStep.zig +18 -2
- {zig-zon-0.2.0 → zig-zon-0.2.2}/zig-pkg/zig_python_sdist/src/build/VenvInstallTest.zig +34 -9
- zig-zon-0.2.2/zig-pkg/zig_python_sdist/src/build/extract_link_info.py +84 -0
- zig-zon-0.2.2/zig-pkg/zig_python_sdist/src/build/pkg_info.zig +51 -0
- zig-zon-0.2.0/zig-pkg/zig_python_sdist/src/build/extract_link_info.py +0 -72
- {zig-zon-0.2.0 → zig-zon-0.2.2}/zig-pkg/zig_python_sdist/LICENSE +0 -0
- {zig-zon-0.2.0 → zig-zon-0.2.2}/zig-pkg/zig_python_sdist/README.md +0 -0
- {zig-zon-0.2.0 → zig-zon-0.2.2}/zig-pkg/zig_python_sdist/src/build/LowerDashStringFormatter.zig +0 -0
- {zig-zon-0.2.0 → zig-zon-0.2.2}/zig-pkg/zig_python_sdist/src/build/python.zig +0 -0
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: zig-zon
|
|
3
|
-
Version: 0.2.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Summary: a native cpython extension to parse zig object notation strings
|
|
5
|
+
Author-email: Tobias Simetsreiter <dasimmet@gmail.com>
|
|
6
|
+
Maintainer-email: Tobias Simetsreiter <dasimmet@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Keywords: zig,ziglang,cpython,native,sdist,zon
|
|
9
|
+
Requires-Python: >=3.8
|
|
10
|
+
Project-URL: Homepage, https://codeberg.org/dasimmet/python-zig-zon
|
|
11
|
+
Project-URL: Issues, https://codeberg.org/dasimmet/python-zig-zon/issues
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
5
13
|
Description-Content-Type: text/markdown
|
|
6
14
|
|
|
7
15
|
# Python Zig Zon Parser
|
|
@@ -33,6 +41,23 @@ print(parsed)
|
|
|
33
41
|
|
|
34
42
|
or, look at the [test file](https://codeberg.org/dasimmet/python-zig-zon/src/branch/main/src/test_zig_zon.py)
|
|
35
43
|
|
|
44
|
+
## Supported values and their python type
|
|
45
|
+
|
|
46
|
+
- `structs` -> `dict`
|
|
47
|
+
- `tuples` -> `list`
|
|
48
|
+
- `integer literals` -> `int`
|
|
49
|
+
- `hex literals` -> `int`
|
|
50
|
+
- `float literals` -> `float`
|
|
51
|
+
- `booleans` -> `bool`
|
|
52
|
+
- `null` -> `None`
|
|
53
|
+
- `string literals` -> `str`
|
|
54
|
+
- `bare enum literals` -> `str`
|
|
55
|
+
- `quoted enum literals` -> `str`
|
|
56
|
+
|
|
57
|
+
## Not supported values
|
|
58
|
+
|
|
59
|
+
- `bigint`
|
|
60
|
+
|
|
36
61
|
## How it works
|
|
37
62
|
|
|
38
63
|
The `zig build` commands produces a python source distribution archive ready
|
|
@@ -10,35 +10,18 @@ pub fn build(b: *Build) void {
|
|
|
10
10
|
|
|
11
11
|
// this target and section of our build is used at pip install time
|
|
12
12
|
const ext_install_step = b.step("pyext", "build python extension module");
|
|
13
|
-
{
|
|
14
|
-
const cpython = zig_python_sdist.CPython.find(b);
|
|
15
|
-
|
|
16
|
-
const lib = b.addLibrary(.{
|
|
17
|
-
.name = "zig_zon",
|
|
18
|
-
.root_module = b.addModule("zig_zon", .{
|
|
19
|
-
.root_source_file = b.path("src/zig_zon.zig"),
|
|
20
|
-
.target = target,
|
|
21
|
-
.optimize = optimize,
|
|
22
|
-
}),
|
|
23
|
-
.linkage = .dynamic,
|
|
24
|
-
});
|
|
25
|
-
cpython.link(b, .{
|
|
26
|
-
.lib = lib,
|
|
27
|
-
.version = zon.version,
|
|
28
|
-
.optimize = .ReleaseSmall,
|
|
29
|
-
});
|
|
30
|
-
const ext_install = zig_python_sdist.CPython.installExtLib(b, lib);
|
|
31
|
-
|
|
32
|
-
ext_install_step.dependOn(&ext_install.step);
|
|
33
|
-
}
|
|
34
13
|
|
|
35
14
|
// this generates a python sdist archive
|
|
36
15
|
const sdist = zig_python_sdist.create(b, .{
|
|
37
16
|
.name = "zig-zon",
|
|
38
17
|
.version = zon.version,
|
|
39
18
|
.description = b.path("README.md"),
|
|
40
|
-
.
|
|
19
|
+
.build = .{
|
|
20
|
+
.args = &.{ ext_install_step.name, b.fmt("-Doptimize={s}", .{@tagName(optimize)}) },
|
|
21
|
+
},
|
|
22
|
+
.extra_pkg_info = @import("pkg-info.zon"),
|
|
41
23
|
.files = &.{
|
|
24
|
+
.{ .src = b.path("pkg-info.zon"), .dest = "pkg-info.zon" },
|
|
42
25
|
.{ .src = b.path("build.zig.zon"), .dest = "build.zig.zon" },
|
|
43
26
|
.{ .src = b.path("build.zig"), .dest = "build.zig" },
|
|
44
27
|
.{ .src = b.path("src/zig_zon.zig"), .dest = "src/zig_zon.zig" },
|
|
@@ -59,8 +42,31 @@ pub fn build(b: *Build) void {
|
|
|
59
42
|
.{
|
|
60
43
|
.sdist = sdist.getEmittedArchive(),
|
|
61
44
|
.test_py = b.path("src/test_zig_zon.py"),
|
|
45
|
+
.twine_check = true,
|
|
62
46
|
.no_clean = b.option(bool, "pip-no-clean", "dont cleanup pip temp dirs") orelse false,
|
|
63
47
|
},
|
|
64
48
|
);
|
|
65
49
|
b.step("test-pip-install", "").dependOn(test_pip_install.step);
|
|
50
|
+
|
|
51
|
+
{
|
|
52
|
+
const cpython = zig_python_sdist.CPython.find(b);
|
|
53
|
+
|
|
54
|
+
const lib = b.addLibrary(.{
|
|
55
|
+
.name = "zig_zon",
|
|
56
|
+
.root_module = b.addModule("zig_zon", .{
|
|
57
|
+
.root_source_file = b.path("src/zig_zon.zig"),
|
|
58
|
+
.target = target,
|
|
59
|
+
.optimize = optimize,
|
|
60
|
+
}),
|
|
61
|
+
.linkage = .dynamic,
|
|
62
|
+
});
|
|
63
|
+
cpython.link(b, .{
|
|
64
|
+
.lib = lib,
|
|
65
|
+
.version = zon.version,
|
|
66
|
+
.optimize = .ReleaseSmall,
|
|
67
|
+
});
|
|
68
|
+
const ext_install = zig_python_sdist.CPython.installExtLib(b, lib);
|
|
69
|
+
|
|
70
|
+
ext_install_step.dependOn(&ext_install.step);
|
|
71
|
+
}
|
|
66
72
|
}
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
.{
|
|
2
2
|
.name = .python_zig_zon,
|
|
3
3
|
.fingerprint = 0x3d332656a3644fc9,
|
|
4
|
-
.version = "0.2.
|
|
4
|
+
.version = "0.2.2",
|
|
5
5
|
.minimum_zig_version = "0.16.0",
|
|
6
6
|
.dependencies = .{
|
|
7
7
|
.zig_python_sdist = .{
|
|
8
|
-
.url = "git+https://codeberg.org/dasimmet/zig-python-sdist.git#
|
|
9
|
-
.hash = "zig_python_sdist-0.0.1-
|
|
8
|
+
.url = "git+https://codeberg.org/dasimmet/zig-python-sdist.git#d5bd94633cf5923342108c824f61b377a2a8c492",
|
|
9
|
+
.hash = "zig_python_sdist-0.0.1-wjgdOsiNAAC2GtJiAx3dGIloYzgt1_sojmm62pPPalAS",
|
|
10
10
|
},
|
|
11
11
|
},
|
|
12
12
|
.paths = .{
|
|
13
13
|
"src",
|
|
14
14
|
"build.zig",
|
|
15
15
|
"build.zig.zon",
|
|
16
|
+
"pkg-info.zon",
|
|
16
17
|
"LICENSE",
|
|
17
18
|
"README.md",
|
|
18
19
|
"setup.py",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
.{
|
|
2
|
+
.{ .key = "Summary", .value = "a native cpython extension to parse zig object notation strings" },
|
|
3
|
+
.{ .key = "Author-email", .value = "Tobias Simetsreiter <dasimmet@gmail.com>" },
|
|
4
|
+
.{ .key = "Maintainer-email", .value = "Tobias Simetsreiter <dasimmet@gmail.com>" },
|
|
5
|
+
.{ .key = "License-Expression", .value = "MIT" },
|
|
6
|
+
.{ .key = "Keywords", .value = "zig,ziglang,cpython,native,sdist,zon" },
|
|
7
|
+
.{ .key = "Requires-Python", .value = ">=3.8" },
|
|
8
|
+
.{ .key = "Project-URL", .value = "Homepage, https://codeberg.org/dasimmet/python-zig-zon" },
|
|
9
|
+
.{ .key = "Project-URL", .value = "Issues, https://codeberg.org/dasimmet/python-zig-zon/issues" },
|
|
10
|
+
.{ .key = "Classifier", .value = "Development Status :: 4 - Beta" },
|
|
11
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"zig_zon","version":{"major":0,"minor":2,"patch":
|
|
1
|
+
{"name":"zig_zon","version":{"major":0,"minor":2,"patch":2,"pre":null,"build":null},"zig_version":{"major":0,"minor":16,"patch":0,"pre":null,"build":null},"build":{"args":["pyext","-Doptimize=ReleaseSafe","--fork=zig-pkg/zig_python_sdist"],"requires":[]}}
|
|
@@ -66,7 +66,7 @@ pub fn parse(self: [*]PyObject, args: [*]PyObject) callconv(.c) [*c]PyObject {
|
|
|
66
66
|
|
|
67
67
|
const main_node_index = ast.nodeData(.root).node;
|
|
68
68
|
|
|
69
|
-
return
|
|
69
|
+
return parseZonAst(arena, ast, main_node_index) catch |err| {
|
|
70
70
|
const errstr = std.fmt.allocPrintSentinel(
|
|
71
71
|
arena,
|
|
72
72
|
"zig-zon parse error: {s}",
|
|
@@ -86,10 +86,11 @@ const ZonError = error{
|
|
|
86
86
|
StructExpected,
|
|
87
87
|
StructIdentifierExpected,
|
|
88
88
|
NotImplemented,
|
|
89
|
-
|
|
89
|
+
ZonArrayInitFailed,
|
|
90
|
+
InvalidLiteral, // from quoted enum literal parse function
|
|
90
91
|
} || IdentifierError || NumberLiteralError;
|
|
91
92
|
|
|
92
|
-
fn
|
|
93
|
+
fn parseZonAst(arena: Allocator, tree: Ast, node: Ast.Node.Index) ZonError!*c.PyObject {
|
|
93
94
|
const node_tag = tree.nodeTag(node);
|
|
94
95
|
switch (node_tag) {
|
|
95
96
|
.struct_init_comma,
|
|
@@ -114,8 +115,13 @@ fn parseZon(arena: Allocator, tree: Ast, node: Ast.Node.Index) ZonError!*c.PyObj
|
|
|
114
115
|
const name_token = tree.firstToken(node);
|
|
115
116
|
const enum_name = tree.tokenSlice(name_token + 1);
|
|
116
117
|
if (std.mem.startsWith(u8, enum_name, "@")) {
|
|
117
|
-
std.
|
|
118
|
-
|
|
118
|
+
std.debug.assert(std.mem.startsWith(u8, enum_name, "@\""));
|
|
119
|
+
std.debug.assert(std.mem.endsWith(u8, enum_name, "\""));
|
|
120
|
+
const enum_parsed_name = try std.zig.string_literal.parseAlloc(
|
|
121
|
+
arena,
|
|
122
|
+
enum_name[1..enum_name.len],
|
|
123
|
+
);
|
|
124
|
+
return c.Py_BuildValue("s#", enum_parsed_name.ptr, enum_parsed_name.len);
|
|
119
125
|
}
|
|
120
126
|
|
|
121
127
|
return c.Py_BuildValue("s#", enum_name.ptr, enum_name.len);
|
|
@@ -208,7 +214,7 @@ fn parseZonStruct(arena: Allocator, tree: Ast, node: Ast.Node.Index) ZonError!*c
|
|
|
208
214
|
for (struct_init.ast.fields) |field_init| {
|
|
209
215
|
const name_token = tree.firstToken(field_init) - 2;
|
|
210
216
|
const field_name = try identifierTokenString(arena, tree, name_token);
|
|
211
|
-
const field_obj = try
|
|
217
|
+
const field_obj = try parseZonAst(arena, tree, field_init);
|
|
212
218
|
const set_result = c.PyDict_SetItemString(ret, field_name, field_obj);
|
|
213
219
|
assert(set_result >= 0);
|
|
214
220
|
}
|
|
@@ -221,13 +227,13 @@ fn parseZonArray(arena: Allocator, tree: Ast, node: Ast.Node.Index) !*c.PyObject
|
|
|
221
227
|
const array_init = tree.fullArrayInit(&buf, node) orelse {
|
|
222
228
|
const tok = tree.nodeMainToken(node);
|
|
223
229
|
std.log.err("expected paths expression to be a list of strings, got: {d}", .{tok});
|
|
224
|
-
return error.
|
|
230
|
+
return error.ZonArrayInitFailed;
|
|
225
231
|
};
|
|
226
232
|
|
|
227
233
|
const ret = c.PyList_New(0);
|
|
228
234
|
|
|
229
235
|
for (array_init.ast.elements) |elem_node| {
|
|
230
|
-
const field_ret = try
|
|
236
|
+
const field_ret = try parseZonAst(arena, tree, elem_node);
|
|
231
237
|
assert(c.PyList_Append(ret, field_ret) >= 0);
|
|
232
238
|
}
|
|
233
239
|
return ret;
|
|
@@ -49,10 +49,14 @@ pub fn build(b: *Build) void {
|
|
|
49
49
|
.name = "zig-python-sdist-dummy",
|
|
50
50
|
.version = zon.version,
|
|
51
51
|
.description = b.path("README.md"),
|
|
52
|
-
.
|
|
52
|
+
.build = .{
|
|
53
|
+
.args = &.{build_ext_step.name},
|
|
54
|
+
},
|
|
55
|
+
.extra_pkg_info = @import("pkg-info.zon"),
|
|
53
56
|
.files = &.{
|
|
54
57
|
.{ .src = b.path("build.zig.zon"), .dest = "build.zig.zon" },
|
|
55
58
|
.{ .src = b.path("build.zig"), .dest = "build.zig" },
|
|
59
|
+
.{ .src = b.path("pkg-info.zon"), .dest = "pkg-info.zon" },
|
|
56
60
|
.{ .src = b.path("example/sdist_dummy.zig"), .dest = "example/sdist_dummy.zig" },
|
|
57
61
|
},
|
|
58
62
|
.directories = &.{
|
|
@@ -74,6 +78,7 @@ pub fn build(b: *Build) void {
|
|
|
74
78
|
.{
|
|
75
79
|
.sdist = sdist.getEmittedArchive(),
|
|
76
80
|
.test_py = b.path("example/test_ext.py"),
|
|
81
|
+
.twine_check = true,
|
|
77
82
|
.no_clean = b.option(bool, "pip-no-clean", "cleanup pip temp dirs") orelse false,
|
|
78
83
|
},
|
|
79
84
|
);
|
|
@@ -93,6 +98,7 @@ pub fn create(b: *Build, options: SDistStep.Options) *SDistStep {
|
|
|
93
98
|
const extra_files: []const SDistStep.Content = &.{
|
|
94
99
|
.{ .src = sdist.path("build.zig.zon"), .dest = "zig-pkg/zig_python_sdist/build.zig.zon" },
|
|
95
100
|
.{ .src = sdist.path("build.zig"), .dest = "zig-pkg/zig_python_sdist/build.zig" },
|
|
101
|
+
.{ .src = sdist.path("pkg-info.zon"), .dest = "zig-pkg/zig_python_sdist/pkg-info.zon" },
|
|
96
102
|
.{ .src = sdist.path("README.md"), .dest = "zig-pkg/zig_python_sdist/README.md" },
|
|
97
103
|
.{ .src = sdist.path("LICENSE"), .dest = "zig-pkg/zig_python_sdist/LICENSE" },
|
|
98
104
|
};
|
|
@@ -108,7 +114,6 @@ pub fn create(b: *Build, options: SDistStep.Options) *SDistStep {
|
|
|
108
114
|
{
|
|
109
115
|
var dirs: std.ArrayList(SDistStep.Content) = .empty;
|
|
110
116
|
const extra_dirs: []const SDistStep.Content = &.{
|
|
111
|
-
// .{ .src = sdist.path("src"), .dest = "zig-pkg/zig_python_sdist/src" },
|
|
112
117
|
.{ .src = sdist.path("src/build"), .dest = "zig-pkg/zig_python_sdist/src/build" },
|
|
113
118
|
};
|
|
114
119
|
dirs.ensureTotalCapacity(
|
|
@@ -124,11 +129,11 @@ pub fn create(b: *Build, options: SDistStep.Options) *SDistStep {
|
|
|
124
129
|
var args: std.ArrayList([]const u8) = .empty;
|
|
125
130
|
args.ensureTotalCapacity(
|
|
126
131
|
b.allocator,
|
|
127
|
-
opt.
|
|
132
|
+
opt.build.args.len + 1,
|
|
128
133
|
) catch @panic("OOM");
|
|
129
|
-
args.appendSliceAssumeCapacity(opt.
|
|
134
|
+
args.appendSliceAssumeCapacity(opt.build.args);
|
|
130
135
|
args.appendAssumeCapacity("--fork=zig-pkg/zig_python_sdist");
|
|
131
|
-
opt.
|
|
136
|
+
opt.build.args = args.toOwnedSlice(b.allocator) catch @panic("OOM");
|
|
132
137
|
}
|
|
133
138
|
|
|
134
139
|
return SDistStep.createInternal(b, opt);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
.{
|
|
2
|
+
.{ .key = "Summary", .value = "Just a Test" },
|
|
3
|
+
.{ .key = "Author-email", .value = "Tobias Simetsreiter <dasimmet@gmail.com>" },
|
|
4
|
+
.{ .key = "Maintainer-email", .value = "Tobias Simetsreiter <dasimmet@gmail.com>" },
|
|
5
|
+
.{ .key = "License-Expression", .value = "MIT" },
|
|
6
|
+
.{ .key = "Keywords", .value = "zig,ziglang,cpython,native,sdist" },
|
|
7
|
+
.{ .key = "Requires-Python", .value = ">=3.8" },
|
|
8
|
+
.{ .key = "Project-URL", .value = "Homepage, https://codeberg.org/dasimmet/zig-python-sdist" },
|
|
9
|
+
.{ .key = "Project-URL", .value = "Issues, https://codeberg.org/dasimmet/zig-python-sdist/issues" },
|
|
10
|
+
.{ .key = "Classifier", .value = "Development Status :: 4 - Beta" },
|
|
11
|
+
}
|
|
@@ -77,7 +77,7 @@ pub fn link(self: CPython, b: *Build, options: LinkOptions) void {
|
|
|
77
77
|
const python_inc = self.generateIncludeDir(b);
|
|
78
78
|
|
|
79
79
|
const cpython = b.addTranslateC(.{
|
|
80
|
-
.root_source_file = python_inc.path(b, "
|
|
80
|
+
.root_source_file = python_inc.path(b, "zig_python_include.h"),
|
|
81
81
|
.optimize = options.optimize orelse options.lib.root_module.optimize orelse .ReleaseSafe,
|
|
82
82
|
.target = target,
|
|
83
83
|
});
|
|
@@ -124,71 +124,6 @@ pub fn lib_ext_name(b: *Build, lib: *Build.Step.Compile) []const u8 {
|
|
|
124
124
|
b.fmt("{s}.so", .{lib.name});
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
pub fn run_test(
|
|
128
|
-
self: CPython,
|
|
129
|
-
b: *Build,
|
|
130
|
-
lib: *Build.Step.Compile,
|
|
131
|
-
test_py_file: Build.LazyPath,
|
|
132
|
-
) *Build.Step.Run {
|
|
133
|
-
const wf = b.addWriteFiles();
|
|
134
|
-
const python_runner = wf.add("python-runner.zig", @embedFile("python-runner.zig"));
|
|
135
|
-
|
|
136
|
-
const runner = b.addExecutable(.{
|
|
137
|
-
.name = "python-runner",
|
|
138
|
-
.root_module = b.createModule(.{
|
|
139
|
-
.root_source_file = python_runner,
|
|
140
|
-
.target = b.graph.host,
|
|
141
|
-
.optimize = .ReleaseSmall,
|
|
142
|
-
}),
|
|
143
|
-
});
|
|
144
|
-
const run_step = b.addRunArtifact(runner);
|
|
145
|
-
const python_ext = writeExtensionFile(b, lib);
|
|
146
|
-
run_step.addFileArg(self.exe);
|
|
147
|
-
run_step.addDirectoryArg(python_ext.dirname());
|
|
148
|
-
run_step.addFileArg(test_py_file);
|
|
149
|
-
run_step.has_side_effects = true;
|
|
150
|
-
return run_step;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
pub fn writeExtensionFile(b: *Build, lib: *Build.Step.Compile) Build.LazyPath {
|
|
154
|
-
const ext_lib_name = lib_ext_name(b, lib);
|
|
155
|
-
const wf = b.addWriteFiles();
|
|
156
|
-
return wf.addCopyFile(lib.getEmittedBin(), ext_lib_name);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
pub fn addSdistList(b: *Build) void {
|
|
160
|
-
const wf = b.addWriteFiles();
|
|
161
|
-
var wr: std.Io.Writer.Allocating = .init(b.allocator);
|
|
162
|
-
var jw: std.json.Stringify = .{ .writer = &wr.writer };
|
|
163
|
-
jw.beginObject() catch @panic("OOM");
|
|
164
|
-
if (b.graph.global_cache_root.path) |global_cache| {
|
|
165
|
-
jw.objectField("global_cache_dir") catch @panic("OOM");
|
|
166
|
-
jw.write(global_cache) catch @panic("OOM");
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
jw.objectField("dependencies") catch @panic("OOM");
|
|
170
|
-
jw.beginArray() catch @panic("OOM");
|
|
171
|
-
writeDeps(b, &jw) catch @panic("OOM");
|
|
172
|
-
jw.endArray() catch @panic("OOM");
|
|
173
|
-
jw.endObject() catch @panic("OOM");
|
|
174
|
-
|
|
175
|
-
const out = wf.add("sdistlist.json", wr.written());
|
|
176
|
-
const sdist_step = b.step("sdistlist", "generate a list of files for python sdist");
|
|
177
|
-
sdist_step.dependOn(&b.addInstallFile(out, "sdistlist.json").step);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
fn writeDeps(b: *std.Build, w: *std.json.Stringify) !void {
|
|
181
|
-
for (b.available_deps) |dep| {
|
|
182
|
-
try w.beginArray();
|
|
183
|
-
try w.write(dep[0]);
|
|
184
|
-
try w.write(dep[1]);
|
|
185
|
-
try w.endArray();
|
|
186
|
-
if (b.lazyDependency(dep[0], .{})) |lazy_dep| {
|
|
187
|
-
try writeDeps(lazy_dep.builder, w);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
127
|
// compat for 0.16.0 and 0.17.0
|
|
193
128
|
pub fn findProgramCompat(b: *std.Build, names: []const []const u8) ?[]const u8 {
|
|
194
129
|
if (comptime (@import("builtin").zig_version.order(std.SemanticVersion.parse("0.16.0") catch unreachable) == .gt)) {
|
|
@@ -2,22 +2,29 @@ const std = @import("std");
|
|
|
2
2
|
const Build = std.Build;
|
|
3
3
|
const LazyPath = Build.LazyPath;
|
|
4
4
|
const LowerDashStringFormatter = @import("LowerDashStringFormatter.zig");
|
|
5
|
+
const PkgInfo = @import("pkg_info.zig");
|
|
5
6
|
|
|
6
7
|
const SDistStep = @This();
|
|
7
8
|
|
|
8
9
|
basename: []const u8,
|
|
9
10
|
builder: *Build.Step.Compile,
|
|
10
11
|
archive: LazyPath,
|
|
12
|
+
|
|
11
13
|
pub const Content = struct {
|
|
12
14
|
src: LazyPath,
|
|
13
15
|
dest: []const u8,
|
|
14
16
|
};
|
|
17
|
+
|
|
15
18
|
pub const Options = struct {
|
|
16
19
|
name: []const u8,
|
|
17
20
|
version: []const u8,
|
|
18
21
|
description: ?LazyPath = null,
|
|
19
22
|
files: []const Content = &.{},
|
|
20
|
-
|
|
23
|
+
build: struct {
|
|
24
|
+
args: []const []const u8 = &.{},
|
|
25
|
+
requires: []const []const u8 = &.{},
|
|
26
|
+
} = .{},
|
|
27
|
+
extra_pkg_info: []const PkgInfo.Header = &.{},
|
|
21
28
|
directories: []const Content = &.{},
|
|
22
29
|
sdist_builder: ?*Build.Step.Compile = null,
|
|
23
30
|
// the version of the ziglang python package to depend on.
|
|
@@ -60,9 +67,18 @@ pub fn createInternal(b: *Build, options: Options) *SDistStep {
|
|
|
60
67
|
run.addPrefixedDirectoryArg("--dir=", content.src);
|
|
61
68
|
run.addArg(content.dest);
|
|
62
69
|
}
|
|
63
|
-
for (options.
|
|
70
|
+
for (options.build.args) |ba| {
|
|
64
71
|
run.addArg(b.fmt("--build={s}", .{ba}));
|
|
65
72
|
}
|
|
73
|
+
for (options.build.requires) |br| {
|
|
74
|
+
run.addArg(b.fmt("--build-requires={s}", .{br}));
|
|
75
|
+
}
|
|
76
|
+
if (options.extra_pkg_info.len > 0) {
|
|
77
|
+
const extra_info = std.fmt.allocPrint(b.allocator, "--extra-pkg-info={f}", .{
|
|
78
|
+
std.json.fmt(options.extra_pkg_info, .{ .whitespace = .minified }),
|
|
79
|
+
}) catch @panic("OOM");
|
|
80
|
+
run.addArg(extra_info);
|
|
81
|
+
}
|
|
66
82
|
|
|
67
83
|
self.* = .{
|
|
68
84
|
.basename = basename,
|
|
@@ -16,6 +16,7 @@ pub const Options = struct {
|
|
|
16
16
|
no_clean: bool,
|
|
17
17
|
// pass in python interpreter. uses system python if null
|
|
18
18
|
python: ?LazyPath = null,
|
|
19
|
+
twine_check: bool = false,
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
pub fn create(b: *Build, options: Options) *VenvInstallTest {
|
|
@@ -44,19 +45,43 @@ pub fn create(b: *Build, options: Options) *VenvInstallTest {
|
|
|
44
45
|
|
|
45
46
|
const deps_run = std.Build.Step.Run.create(b, "venv");
|
|
46
47
|
deps_run.addFileArg(venv_python);
|
|
47
|
-
deps_run.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
deps_run.step.dependOn(&wf.step);
|
|
49
|
+
|
|
50
|
+
if (options.twine_check) {
|
|
51
|
+
deps_run.addArgs(&.{
|
|
52
|
+
"-m",
|
|
53
|
+
"pip",
|
|
54
|
+
"install",
|
|
55
|
+
"-U",
|
|
56
|
+
"pip",
|
|
57
|
+
"wheel",
|
|
58
|
+
"twine",
|
|
59
|
+
});
|
|
60
|
+
} else {
|
|
61
|
+
deps_run.addArgs(&.{
|
|
62
|
+
"-m",
|
|
63
|
+
"pip",
|
|
64
|
+
"install",
|
|
65
|
+
"-U",
|
|
66
|
+
"pip",
|
|
67
|
+
"wheel",
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
55
71
|
deps_run.step.dependOn(&venv_run.step);
|
|
56
72
|
|
|
57
|
-
self.install_run = std.Build.Step.Run.create(b, "
|
|
73
|
+
self.install_run = std.Build.Step.Run.create(b, "pip install");
|
|
58
74
|
self.step = &self.install_run.step;
|
|
59
75
|
|
|
76
|
+
if (options.twine_check) {
|
|
77
|
+
const twine_check = std.Build.Step.Run.create(b, "twine check");
|
|
78
|
+
twine_check.step.dependOn(&deps_run.step);
|
|
79
|
+
twine_check.addFileArg(venv_python);
|
|
80
|
+
twine_check.addArgs(&.{ "-m", "twine", "check", "--strict" });
|
|
81
|
+
twine_check.addFileArg(options.sdist);
|
|
82
|
+
self.step.dependOn(&twine_check.step);
|
|
83
|
+
}
|
|
84
|
+
|
|
60
85
|
self.install_run.addFileArg(venv_python);
|
|
61
86
|
self.install_run.addArgs(&.{ "-m", "pip", "install", "--force-reinstall", "--verbose" });
|
|
62
87
|
if (options.no_clean) self.install_run.addArg("--no-clean");
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
import sysconfig
|
|
4
|
+
import sys
|
|
5
|
+
import shutil
|
|
6
|
+
import os
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def main():
|
|
10
|
+
output_dir = sys.argv[1]
|
|
11
|
+
syspath = sysconfig.get_paths()
|
|
12
|
+
|
|
13
|
+
python_h = os.path.join(output_dir, 'Python.h')
|
|
14
|
+
output_header = os.path.join(output_dir, 'zig_python_include.h')
|
|
15
|
+
|
|
16
|
+
os.makedirs(output_dir, exist_ok=True)
|
|
17
|
+
shutil.copytree(syspath['include'], output_dir, dirs_exist_ok=True)
|
|
18
|
+
|
|
19
|
+
sources = [syspath['include']]
|
|
20
|
+
|
|
21
|
+
if sys.platform in ['windows', 'win32', 'cygwin']:
|
|
22
|
+
find_lib(output_dir, sources)
|
|
23
|
+
|
|
24
|
+
if not os.path.isfile(python_h):
|
|
25
|
+
raise Exception("Python.h missing! syspath include: {}\n output: {}".format(
|
|
26
|
+
syspath['include'], output_dir))
|
|
27
|
+
|
|
28
|
+
output_h_str = '''
|
|
29
|
+
// zig_python_include.h generated by extract_link_info.py
|
|
30
|
+
// sources: {}
|
|
31
|
+
#ifndef PY_SSIZE_T_CLEAN
|
|
32
|
+
#define PY_SSIZE_T_CLEAN
|
|
33
|
+
#endif
|
|
34
|
+
|
|
35
|
+
#ifndef PYHEXVER
|
|
36
|
+
#define PYHEXVER {}
|
|
37
|
+
#endif
|
|
38
|
+
|
|
39
|
+
#include "Python.h"
|
|
40
|
+
'''.format(sources, sys.hexversion)
|
|
41
|
+
|
|
42
|
+
with open(output_header, 'w') as fd:
|
|
43
|
+
fd.write(output_h_str)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def find_lib(output_dir, sources=[]):
|
|
47
|
+
lib_filename = 'python{}{}.lib'.format(
|
|
48
|
+
sys.version_info.major, sys.version_info.minor)
|
|
49
|
+
found_lib = False
|
|
50
|
+
for k, v in sysconfig.get_config_vars().items():
|
|
51
|
+
if not isinstance(v, str):
|
|
52
|
+
continue
|
|
53
|
+
vf = os.path.join(v, lib_filename)
|
|
54
|
+
if os.path.exists(vf):
|
|
55
|
+
try:
|
|
56
|
+
shutil.copyfile(vf, os.path.join(output_dir, 'python.lib'))
|
|
57
|
+
found_lib = True
|
|
58
|
+
sources.append(vf)
|
|
59
|
+
break
|
|
60
|
+
except:
|
|
61
|
+
pass
|
|
62
|
+
else:
|
|
63
|
+
pass
|
|
64
|
+
|
|
65
|
+
vfl = os.path.join(v, 'libs', lib_filename)
|
|
66
|
+
if os.path.exists(vfl):
|
|
67
|
+
try:
|
|
68
|
+
shutil.copyfile(vfl, os.path.join(
|
|
69
|
+
output_dir, 'python.lib'))
|
|
70
|
+
found_lib = True
|
|
71
|
+
sources.append(vfl)
|
|
72
|
+
break
|
|
73
|
+
except:
|
|
74
|
+
pass
|
|
75
|
+
else:
|
|
76
|
+
pass
|
|
77
|
+
|
|
78
|
+
if not found_lib:
|
|
79
|
+
raise Exception(
|
|
80
|
+
" ".join(["Warning: Did not find", str(lib_filename)]))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
if __name__ == '__main__':
|
|
84
|
+
main()
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/// Representation of pythons sdist's PKG_INFO file
|
|
2
|
+
///
|
|
3
|
+
const std = @import("std");
|
|
4
|
+
const PkgInfo = @This();
|
|
5
|
+
pub const empty: PkgInfo = .{
|
|
6
|
+
.headers = .empty,
|
|
7
|
+
.description = .empty,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
headers: std.ArrayList(Header),
|
|
11
|
+
description: std.ArrayList(u8),
|
|
12
|
+
|
|
13
|
+
pub const Header = struct {
|
|
14
|
+
key: []const u8,
|
|
15
|
+
value: []const u8,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
pub fn format(self: @This(), w: *std.Io.Writer) !void {
|
|
19
|
+
for (self.headers.items) |h| {
|
|
20
|
+
if (std.mem.containsAtLeast(u8, h.key, 1, "\n")) {
|
|
21
|
+
std.log.err("newlines are not allowed in pkg-info header keys: {s}", .{h.key});
|
|
22
|
+
return error.WriteFailed;
|
|
23
|
+
}
|
|
24
|
+
if (std.mem.containsAtLeast(u8, h.value, 1, "\n")) {
|
|
25
|
+
std.log.err("newlines are not allowed in pkg-info headers values: {s}", .{h.value});
|
|
26
|
+
return error.WriteFailed;
|
|
27
|
+
}
|
|
28
|
+
try w.print("{s}: {s}\n", .{ h.key, h.value });
|
|
29
|
+
}
|
|
30
|
+
try w.writeAll("\n");
|
|
31
|
+
try w.writeAll(self.description.items);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Metadata-Version: 2.4
|
|
35
|
+
// Name: zig-zon
|
|
36
|
+
// Version: 0.1.3
|
|
37
|
+
// Summary: a native cpython extension to parse zig object notation strings
|
|
38
|
+
// Author-email: Tobias Simetsreiter <dasimmet@gmail.com>
|
|
39
|
+
// Maintainer-email: Tobias Simetsreiter <dasimmet@gmail.com>
|
|
40
|
+
// License-Expression: MIT
|
|
41
|
+
// Project-URL: Homepage, https://codeberg.org/dasimmet/python-zig-zon
|
|
42
|
+
// Project-URL: Issues, https://codeberg.org/dasimmet/python-zig-zon/issues
|
|
43
|
+
// Keywords: zig,ziglang,zon,cpython
|
|
44
|
+
// Classifier: Development Status :: 4 - Beta
|
|
45
|
+
// Classifier: Intended Audience :: Developers
|
|
46
|
+
// Classifier: Programming Language :: Python :: 3
|
|
47
|
+
// Classifier: Programming Language :: Python :: 3.9
|
|
48
|
+
// Requires-Python: >=3.9
|
|
49
|
+
// Description-Content-Type: text/markdown
|
|
50
|
+
// License-File: LICENSE
|
|
51
|
+
// Dynamic: license-file
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
|
|
3
|
-
import sysconfig
|
|
4
|
-
import sys
|
|
5
|
-
import shutil
|
|
6
|
-
import os
|
|
7
|
-
|
|
8
|
-
output_dir = sys.argv[1]
|
|
9
|
-
syspath = sysconfig.get_paths()
|
|
10
|
-
|
|
11
|
-
lib_filename = 'python{}{}.lib'.format(
|
|
12
|
-
sys.version_info.major, sys.version_info.minor)
|
|
13
|
-
|
|
14
|
-
os.makedirs(output_dir, exist_ok=True)
|
|
15
|
-
shutil.copytree(syspath['include'], output_dir, dirs_exist_ok=True)
|
|
16
|
-
|
|
17
|
-
found_lib = False
|
|
18
|
-
sources = [syspath['include']]
|
|
19
|
-
|
|
20
|
-
for k, v in sysconfig.get_config_vars().items():
|
|
21
|
-
if not isinstance(v, str):
|
|
22
|
-
continue
|
|
23
|
-
vf = os.path.join(v, lib_filename)
|
|
24
|
-
if os.path.exists(vf):
|
|
25
|
-
try:
|
|
26
|
-
shutil.copyfile(vf, os.path.join(output_dir, 'python.lib'))
|
|
27
|
-
found_lib = True
|
|
28
|
-
sources.append(vf)
|
|
29
|
-
break
|
|
30
|
-
except:
|
|
31
|
-
pass
|
|
32
|
-
else:
|
|
33
|
-
pass
|
|
34
|
-
|
|
35
|
-
vfl = os.path.join(v, 'libs', lib_filename)
|
|
36
|
-
if os.path.exists(vfl):
|
|
37
|
-
try:
|
|
38
|
-
shutil.copyfile(vfl, os.path.join(output_dir, 'python.lib'))
|
|
39
|
-
found_lib = True
|
|
40
|
-
sources.append(vfl)
|
|
41
|
-
break
|
|
42
|
-
except:
|
|
43
|
-
pass
|
|
44
|
-
else:
|
|
45
|
-
pass
|
|
46
|
-
|
|
47
|
-
if sys.platform == 'windows' and not found_lib:
|
|
48
|
-
print("Warning: Did not find", lib_filename, "in:", file=sys.stderr)
|
|
49
|
-
print(lib_paths, file=sys.stderr)
|
|
50
|
-
|
|
51
|
-
python_h = os.path.join(output_dir, 'Python.h')
|
|
52
|
-
if not os.path.isfile(python_h):
|
|
53
|
-
raise Exception("Python.h missing! syspath include: {}\n output: {}".format(
|
|
54
|
-
syspath['include'], output_dir))
|
|
55
|
-
|
|
56
|
-
output_header = os.path.join(output_dir, 'Zig_Python_With_Hexver.h')
|
|
57
|
-
|
|
58
|
-
with open(output_header, 'w') as fd:
|
|
59
|
-
fd.write('''
|
|
60
|
-
// Zig_Python_With_Hexver.h generated by extract_link_info.py
|
|
61
|
-
// sources: {}
|
|
62
|
-
#ifndef PY_SSIZE_T_CLEAN
|
|
63
|
-
#define PY_SSIZE_T_CLEAN
|
|
64
|
-
#endif
|
|
65
|
-
|
|
66
|
-
#ifndef PYHEXVER
|
|
67
|
-
#define PYHEXVER {}
|
|
68
|
-
#endif
|
|
69
|
-
|
|
70
|
-
#include "Python.h"
|
|
71
|
-
'''.format(sources, sys.hexversion))
|
|
72
|
-
print('OK:', output_header)
|
|
File without changes
|
|
File without changes
|
{zig-zon-0.2.0 → zig-zon-0.2.2}/zig-pkg/zig_python_sdist/src/build/LowerDashStringFormatter.zig
RENAMED
|
File without changes
|
|
File without changes
|