From fce6bdd6b64dc76c6ae8e416ec6ed429fc4c4d2d Mon Sep 17 00:00:00 2001 From: Will Manning Date: Fri, 8 Sep 2023 12:43:25 -0400 Subject: [PATCH 1/5] docs tweaks --- README.md | 9 +++++---- docs/getting_started.md | 19 ++++++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index c9ca64e6..ac124c18 100644 --- a/README.md +++ b/README.md @@ -72,20 +72,21 @@ Pydust supports: Please reach out if you're interested in helping us to expand compatibility. -## Getting Started +## Resources Pydust docs can be found [here](https://pydust.fulcrum.so). + Zig documentation (beta) can be found [here](https://pydust.fulcrum.so/latest/zig). -There is also a [template repository](https://github.com/fulcrum-so/ziggy-pydust-template) including Poetry build, Pytest and publishing from Github Actions. +There is also a [template repository](https://github.com/fulcrum-so/ziggy-pydust-template) including Poetry build, Pytest, and publishing from Github Actions. ## Contributing We welcome contributions! Pydust is in its early stages so there is lots of low hanging -fruit when it comes to contributions. +fruit when it comes to contributions. If you are interested in contributing, please feel free to: - Assist other Pydust users with GitHub issues or discussions. -- Suggest or implement features, fix bugs, fix performance issues. +- Suggest or implement features, fix bugs, or fix performance issues. - Improve our documentation. - Write articles or other content demonstrating how you have used Pydust. diff --git a/docs/getting_started.md b/docs/getting_started.md index b3a3bc8a..cd5c5afc 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -10,21 +10,25 @@ By far the easiest way to get started is by creating a project from our GitHub t This template includes: -- A Python Poetry project -- A `src/` directory containing a Pydust Python module -- Pytest setup for running both Python and Zig unit tests. -- GitHub Actions workflows for building and publishing the package. -- VSCode settings for recommended extensions, debugger configurations, etc. +* A Python Poetry project +* A `src/` directory containing a Pydust Python module +* Pytest setup for running both Python and Zig unit tests +* GitHub Actions workflows for building and publishing the package +* VSCode settings for recommended extensions, debugger configurations, etc. ## Poetry Setup Assuming you have an existing Poetry project, these are the changes you need to make to -your `pyproject.toml` to setup Ziggy Pydust. But first, add Pydust as a dev dependency: +your project to setup Ziggy Pydust. + +First, add Pydust as a dev dependency: ```bash poetry add -G dev ziggy-pydust ``` +Second, make the following additions to your existing `pyproject.toml`: + ```diff title="pyproject.toml" [tool.poetry] name = "your-package" @@ -40,7 +44,8 @@ packages = [ { include = "your-module" } ] build-backend = "poetry.core.masonry.api" ``` -As well as creating the `build.py` for Poetry to invoke the Pydust build. +Finally, for Poetry to invoke the Pydust build create a `build.py` file in the same directory +as `pyproject.toml` with the following contents: ```python title="build.py" from pydust.build import build From 44ea94ff199cff99c6cf468c3c9f79937f94ddba Mon Sep 17 00:00:00 2001 From: Will Manning Date: Tue, 21 Nov 2023 14:54:17 -0500 Subject: [PATCH 2/5] fix errors on compiler upgrade --- pydust/src/modules.zig | 2 +- pydust/src/pytypes.zig | 8 ++++---- pydust/src/types/bytes.zig | 2 +- pydust/src/types/str.zig | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pydust/src/modules.zig b/pydust/src/modules.zig index d86a8ae0..699e777e 100644 --- a/pydust/src/modules.zig +++ b/pydust/src/modules.zig @@ -50,7 +50,7 @@ pub fn Module(comptime name: [:0]const u8, comptime definition: type) type { /// A function to initialize the Python module from its definition. pub fn init() !py.PyObject { - var pyModuleDef = try py.allocator.create(ffi.PyModuleDef); + const pyModuleDef = try py.allocator.create(ffi.PyModuleDef); pyModuleDef.* = ffi.PyModuleDef{ .m_base = ffi.PyModuleDef_Base{ .ob_base = ffi.PyObject{ diff --git a/pydust/src/pytypes.zig b/pydust/src/pytypes.zig index d3c95f30..585f41f9 100644 --- a/pydust/src/pytypes.zig +++ b/pydust/src/pytypes.zig @@ -509,7 +509,7 @@ fn GC(comptime definition: type) type { } fn tp_clear(pyself: *ffi.PyObject) callconv(.C) c_int { - var self: *PyTypeStruct(definition) = @ptrCast(pyself); + const self: *PyTypeStruct(definition) = @ptrCast(pyself); clearFields(self.state); return 0; } @@ -562,8 +562,8 @@ fn GC(comptime definition: type) type { } inline fn pyClear(obj: *ffi.PyObject) void { - var objRef = @constCast(&obj); - const objOld = objRef.*; + const objRef: *ffi.PyObject = @constCast(obj); + const objOld: ffi.PyObject = objRef.*; objRef.* = undefined; py.decref(objOld); } @@ -665,7 +665,7 @@ fn Members(comptime definition: type) type { // We compute the offset of the attribute within the type, and then the value field within the attribute. // Although the value within the attribute should always be 0 since it's the only field. - var offset = @offsetOf(PyTypeStruct(definition), "state") + @offsetOf(definition, field.name) + @offsetOf(field.type, "value"); + const offset = @offsetOf(PyTypeStruct(definition), "state") + @offsetOf(definition, field.name) + @offsetOf(field.type, "value"); const T = @typeInfo(field.type).Struct.fields[0].type; diff --git a/pydust/src/types/bytes.zig b/pydust/src/types/bytes.zig index 8c8429a8..149b153a 100644 --- a/pydust/src/types/bytes.zig +++ b/pydust/src/types/bytes.zig @@ -60,7 +60,7 @@ test "PyBytes" { var ps = try PyBytes.create(a); defer ps.decref(); - var ps_slice = try ps.asSlice(); + const ps_slice = try ps.asSlice(); try testing.expectEqual(a.len, ps_slice.len); try testing.expectEqual(a.len, try ps.length()); try testing.expectEqual(@as(u8, 0), ps_slice[ps_slice.len]); diff --git a/pydust/src/types/str.zig b/pydust/src/types/str.zig index 52762b03..f2d85c3d 100644 --- a/pydust/src/types/str.zig +++ b/pydust/src/types/str.zig @@ -105,7 +105,7 @@ test "PyString" { ps = try ps.appendSlice(b); defer ps.decref(); - var ps_slice = try ps.asSlice(); + const ps_slice = try ps.asSlice(); // Null-terminated strings have len == non-null bytes, but are guaranteed to have a null byte // when indexed by their length. From 99d21107c03e53891d165820d987118d1e329bf9 Mon Sep 17 00:00:00 2001 From: Will Manning Date: Tue, 21 Nov 2023 17:15:13 -0500 Subject: [PATCH 3/5] back --- pydust/src/pytypes.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pydust/src/pytypes.zig b/pydust/src/pytypes.zig index 585f41f9..13da6f80 100644 --- a/pydust/src/pytypes.zig +++ b/pydust/src/pytypes.zig @@ -562,8 +562,8 @@ fn GC(comptime definition: type) type { } inline fn pyClear(obj: *ffi.PyObject) void { - const objRef: *ffi.PyObject = @constCast(obj); - const objOld: ffi.PyObject = objRef.*; + const objRef = @constCast(obj); + const objOld = objRef.*; objRef.* = undefined; py.decref(objOld); } From f7e62c6760354c65eb1151639b13c1861bce0499 Mon Sep 17 00:00:00 2001 From: Will Manning Date: Tue, 21 Nov 2023 17:17:25 -0500 Subject: [PATCH 4/5] Revert "docs tweaks" This reverts commit fce6bdd6b64dc76c6ae8e416ec6ed429fc4c4d2d. --- README.md | 9 ++++----- docs/getting_started.md | 19 +++++++------------ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index ac124c18..c9ca64e6 100644 --- a/README.md +++ b/README.md @@ -72,21 +72,20 @@ Pydust supports: Please reach out if you're interested in helping us to expand compatibility. -## Resources +## Getting Started Pydust docs can be found [here](https://pydust.fulcrum.so). - Zig documentation (beta) can be found [here](https://pydust.fulcrum.so/latest/zig). -There is also a [template repository](https://github.com/fulcrum-so/ziggy-pydust-template) including Poetry build, Pytest, and publishing from Github Actions. +There is also a [template repository](https://github.com/fulcrum-so/ziggy-pydust-template) including Poetry build, Pytest and publishing from Github Actions. ## Contributing We welcome contributions! Pydust is in its early stages so there is lots of low hanging -fruit when it comes to contributions. If you are interested in contributing, please feel free to: +fruit when it comes to contributions. - Assist other Pydust users with GitHub issues or discussions. -- Suggest or implement features, fix bugs, or fix performance issues. +- Suggest or implement features, fix bugs, fix performance issues. - Improve our documentation. - Write articles or other content demonstrating how you have used Pydust. diff --git a/docs/getting_started.md b/docs/getting_started.md index cd5c5afc..b3a3bc8a 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -10,25 +10,21 @@ By far the easiest way to get started is by creating a project from our GitHub t This template includes: -* A Python Poetry project -* A `src/` directory containing a Pydust Python module -* Pytest setup for running both Python and Zig unit tests -* GitHub Actions workflows for building and publishing the package -* VSCode settings for recommended extensions, debugger configurations, etc. +- A Python Poetry project +- A `src/` directory containing a Pydust Python module +- Pytest setup for running both Python and Zig unit tests. +- GitHub Actions workflows for building and publishing the package. +- VSCode settings for recommended extensions, debugger configurations, etc. ## Poetry Setup Assuming you have an existing Poetry project, these are the changes you need to make to -your project to setup Ziggy Pydust. - -First, add Pydust as a dev dependency: +your `pyproject.toml` to setup Ziggy Pydust. But first, add Pydust as a dev dependency: ```bash poetry add -G dev ziggy-pydust ``` -Second, make the following additions to your existing `pyproject.toml`: - ```diff title="pyproject.toml" [tool.poetry] name = "your-package" @@ -44,8 +40,7 @@ packages = [ { include = "your-module" } ] build-backend = "poetry.core.masonry.api" ``` -Finally, for Poetry to invoke the Pydust build create a `build.py` file in the same directory -as `pyproject.toml` with the following contents: +As well as creating the `build.py` for Poetry to invoke the Pydust build. ```python title="build.py" from pydust.build import build From 16c974e146ad7ecb1bd17683eaa4d09b00513e6e Mon Sep 17 00:00:00 2001 From: Will Manning Date: Tue, 21 Nov 2023 17:20:44 -0500 Subject: [PATCH 5/5] ampersand --- pydust/src/pytypes.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydust/src/pytypes.zig b/pydust/src/pytypes.zig index 13da6f80..4e28b101 100644 --- a/pydust/src/pytypes.zig +++ b/pydust/src/pytypes.zig @@ -562,7 +562,7 @@ fn GC(comptime definition: type) type { } inline fn pyClear(obj: *ffi.PyObject) void { - const objRef = @constCast(obj); + const objRef = @constCast(&obj); const objOld = objRef.*; objRef.* = undefined; py.decref(objOld);