From 6e79bf9ed020f88b0663c3b9a3adff249e4b718d Mon Sep 17 00:00:00 2001 From: Thomas Kirchner Date: Wed, 30 Sep 2026 08:54:33 +0200 Subject: [PATCH] chore: PyPI metadata, Linux-only note, auto-close default trace at exit Co-Authored-By: Claude Opus 5.5 --- README.md | 5 +++-- pyproject.toml | 16 ++++++++++++++++ src/dlv/templates/binding.cpp.j2 | 10 +++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c11c87a..d345b79 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ $ dlv build counter.v --clock clk -o out/ ## Requirements +- Linux only (the extension is built with `g++`; macOS/Windows are not supported yet) - Python ≥ 3.10 - `verilator` ≥ 5.022 in `PATH` (ports are read with `verilator --json-only`) - `g++` (C++17) in `PATH` @@ -85,9 +86,9 @@ The module name is the Verilog module name. `Model()` creates an independent sim | `cycle_ris(n=1)` / `cycle_fal(n=1)` | `n` more clock periods | | `get()` | `{output: int}` for all outputs | | `step(n, inputs={})` | `n` rising-edge clock periods in a C++ loop. `inputs` maps names to array-likes of length `n` (or length 1 = constant). Returns `{output: numpy array}` (uint8/16/32/64 by width), sampled after each period. | -| `trace_open(path)` / `trace_close()` | Only with `--trace`: write an FST waveform. Call `trace_close()` to flush. | +| `trace_open(path)` / `trace_close()` | Only with `--trace`: write an FST waveform. The default instance's trace is closed automatically at exit; call `trace_close()` on your own `Model()` instances. | -Ports up to 64 bits are Python `int`s. The clock cannot be set via `inputs`. Don't mix `_ris` and `_fal` calls on the same instance unless you accept an extra clock edge when switching. +Ports up to 64 bits are Python `int`s. Values are always unsigned, also for `signed` ports (convert yourself, e.g. two's complement). The clock cannot be set via `inputs`. Don't mix `_ris` and `_fal` calls on the same instance unless you accept an extra clock edge when switching. ## Shell completion diff --git a/pyproject.toml b/pyproject.toml index 0db47f0..cdd8758 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,8 +10,24 @@ readme = "README.md" license = "MIT" license-files = ["LICENSE"] requires-python = ">=3.10" +authors = [{ name = "Thomas Kirchner", email = "thomas.kirchner5@web.de" }] +keywords = ["verilog", "verilator", "nanobind", "simulation", "hdl", "fpga"] +classifiers = [ + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Intended Audience :: Science/Research", + "Operating System :: POSIX :: Linux", + "Programming Language :: Python :: 3", + "Programming Language :: C++", + "Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)", +] dependencies = ["nanobind", "jinja2", "argcomplete", "rich", "numpy"] +[project.urls] +Homepage = "https://github.com/pythagorasDesaster/dlv" +Source = "https://git.cloud.servinpythagoras.online/thomas/dlv" +Issues = "https://github.com/pythagorasDesaster/dlv/issues" + [project.scripts] dlv = "dlv.cli:main" diff --git a/src/dlv/templates/binding.cpp.j2 b/src/dlv/templates/binding.cpp.j2 index b80d7c1..9e3becf 100644 --- a/src/dlv/templates/binding.cpp.j2 +++ b/src/dlv/templates/binding.cpp.j2 @@ -151,9 +151,10 @@ struct Model { }; // Default instance behind the module-level functions, created on first use. +Model* g_dflt = nullptr; Model& dflt() { - static Model* m = new Model(); - return *m; + if (!g_dflt) g_dflt = new Model(); + return *g_dflt; } } // namespace @@ -179,5 +180,8 @@ NB_MODULE({{ top }}, m) { m.def("get", [] { return dflt().get(); }); m.def("step", [](size_t n, nb::dict d) { return dflt().step(n, d); }, "n"_a, "inputs"_a = nb::dict());{% if trace %} m.def("trace_open", [](const std::string& p) { dflt().trace_open(p); }, "path"_a); - m.def("trace_close", [] { dflt().trace_close(); });{% endif %} + m.def("trace_close", [] { dflt().trace_close(); }); + // Flush the default instance's FST at interpreter exit. + m.def("_atexit", [] { if (g_dflt) g_dflt->trace_close(); }); + nb::module_::import_("atexit").attr("register")(m.attr("_atexit"));{% endif %} }