Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3c6a087
Prototype Python objects owned by VHDL
ru551n Oct 8, 2026
fbf7e39
Generate the call and eval overloads of python_object_t
ru551n Oct 8, 2026
049f600
Say that python_object_pkg.vhd is generated
ru551n Oct 8, 2026
5e8f1d1
Rename object_or_new to get
ru551n Oct 8, 2026
2db5d93
Document Python objects and report objects that cannot be created
ru551n Oct 8, 2026
1e5efaf
Name the constructor new_python_object and enumerate anonymous objects
ru551n Oct 8, 2026
5d71165
Add exec and get_logger for objects and report objects on VHPI
ru551n Oct 8, 2026
b28b315
Show Python objects as backends in the embedded_python example
ru551n Oct 8, 2026
c6f71a3
Show how a model class is made importable, fix the class example
ru551n Oct 8, 2026
189d04d
Polish python_object_pkg
ru551n Oct 8, 2026
ce644c0
Cover create and get_session of objects
ru551n Oct 8, 2026
a6072b7
Lay out the instantiations like standard ones
ru551n Oct 8, 2026
ef23772
Address the review of Python objects
ru551n Oct 8, 2026
4b2fb27
Say plainly when Python code is not found without setup
ru551n Oct 8, 2026
4759d62
Simplify python_object_pkg and the runtime
ru551n Oct 8, 2026
d7065fe
Find classes of objects more clearly and report a failed object on ev…
ru551n Oct 13, 2026
aa79b92
Fail early on objects that cannot work and name the call in its errors
ru551n Oct 13, 2026
685cba9
Merge where Python code is found into File paths and update the objects
ru551n Oct 13, 2026
5dcdf91
Apply the learnings of trying objects in a real project
ru551n Oct 13, 2026
0d40102
Pair new_python_object with create_python_object
ru551n Oct 13, 2026
cba4524
Give Python objects a page of their own in the documentation
ru551n Oct 14, 2026
daf8068
Address review: drop the simulator check of objects, new docs example
ru551n Oct 14, 2026
caf74f9
Get Python objects by identity or full name
ru551n Oct 15, 2026
8f74cbb
Bind a Python object to obj instead of self in its session
ru551n Oct 15, 2026
1a9e3d9
Name a Python object made without an id after its class
ru551n Oct 15, 2026
53ec570
Return null_python_object for an identity without an object
ru551n Oct 15, 2026
f75c5dc
Give verification components a constructor per use case
ru551n Oct 15, 2026
ff4ceb9
Give path_counter_vc a handle instead of several generics
ru551n Oct 15, 2026
becea54
Use the named eval and call forms, adding the alias call_integer
ru551n Oct 15, 2026
3ee8342
Add function forms of the vector results sized like to_unsigned
ru551n Oct 15, 2026
cd9b417
Leave the result of a failed sized function out of the docs
ru551n Oct 15, 2026
6ffcc52
Align the docs and comments of Python objects with the latest changes
ru551n Oct 15, 2026
ef3139d
Use the model of a handle directly and drop a python_pkg caveat
ru551n Oct 15, 2026
65b48cc
Make the release notes news fragments
ru551n Oct 15, 2026
9fdcc1e
Shorten the news fragment of Python objects, drop the call_integer one
ru551n Oct 15, 2026
526d295
Name objects without an id python_object:<class>:<n>
ru551n Oct 16, 2026
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: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ the selected simulator by a foreign language interface the package builds itself
called through VHPIDIRECT (NVC, GHDL) or the FLI (Questa/ModelSim), or a VHPI application built with
the simulator's own compiler driver (Riviera-PRO/Active-HDL). Values cross the interface with their
VHDL types: `integer`, `real`, `string`, `boolean`, `std_ulogic`, `unsigned`/`signed`, the vector
types, and `integer_array_t` as a NumPy array.
types, and `integer_array_t` as a NumPy array. A `python_object_t` is an instance of a Python class
owned by VHDL, for example the backend of a verification component, with a namespace of its own for
every instance.

## Installation

Expand Down
37 changes: 31 additions & 6 deletions docs/file_paths.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@ How a file name is resolved
``pathlib.Path`` and so on
- The current working directory of Python, which is the working
directory of the simulator. See the warning below.
* - Python module imported by name, ``import model``
- ``sys.path``, which holds the directory of the run script first, like
``python run.py`` does, the directories of ``PYTHONPATH`` (the
simulator inherits the environment of VUnit, so a ``PYTHONPATH`` set
in the run script before ``vu.main()`` is seen), and, while
``exec_file`` executes a file, the directory of that file.
* - Python module imported by name, ``import model``, and the class of a
:ref:`Python object <python_bridge:objects>`
- ``sys.path``: see :ref:`python_bridge:finding_code` below.

.. warning::

Expand All @@ -53,6 +50,34 @@ How a file name is resolved
``Path(__file__).parent`` in the model, or pass an absolute name from VHDL,
built with ``base_path`` or ``tb_path``.

.. _python_bridge:finding_code:

Python modules
~~~~~~~~~~~~~~

The interpreter in the simulator imports modules the way Python started on the
run script does. Without any setup it finds:

* modules in the directory of the run script, the first entry of ``sys.path``.
This is also how ``import_run_script`` imports the run script;
* the packages of the Python environment VUnit runs in, for example an active
virtual environment, including packages installed with ``pip install -e``;
* while ``exec_file`` executes a file, the modules next to that file.

Python code anywhere else is found once its directory is on ``PYTHONPATH``,
set in the run script before ``vu.main()``: the simulations inherit the
environment of VUnit (see the recipes below). A verification component used by
many testbenches can so keep its model in a directory of its own and name its
class, for example ``"my_vc_model.Model"`` for a :ref:`Python object
<python_bridge:objects>`. Installing the model as a package, for example with
``pip install -e``, has the same effect without changing the run script.

There is one ``sys.path`` and one ``sys.modules`` per simulation, shared by all
:ref:`sessions <python_bridge:sessions>`. Two modules with the same name are
therefore the same module, so a package is best named after the component it
belongs to, and state kept at module level is shared by everything that
imports the module.

Recipes
~~~~~~~

Expand Down
4 changes: 4 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Key features
``boolean``, ``std_ulogic``, ``unsigned``/``signed``, the vector types, and ``integer_array_t``
as a NumPy array.
* :doc:`Sessions <sessions>` give models and component instances Python namespaces of their own.
* :doc:`Python objects <python_objects>` are instances of Python classes owned by VHDL, for example
the backends of verification components.
* :doc:`Python files and modules <python_files>`, including the run script itself, are executed or
imported from VHDL, with :doc:`file paths <file_paths>` that work for testbenches and
verification components alike.
Expand Down Expand Up @@ -111,6 +113,7 @@ become available through ``python_context``:
types
errors
sessions
python_objects
python_files
file_paths

Expand All @@ -121,6 +124,7 @@ become available through ``python_context``:
api/python_context
api/python_ffi_pkg
api/python_pkg
api/python_object_pkg

.. toctree::
:caption: Simulators
Expand Down
7 changes: 4 additions & 3 deletions docs/other_simulators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ arguments, a 20 register status dump, wide
``call``, Python files executed with ``exec_file`` or imported with
``import_module_from_file``, two models loaded into a session each, and a
Python model failing with the logger of the default session mocked. Its last
test case drives ``python_model``, a verification component whose behaviour is
the Python function in ``python_model.py`` rather than VHDL. The component finds
that file by joining its name to ``base_path``, the directory of the run script, which
test cases drive ``python_model``, a verification component whose behaviour is
the Python function in ``python_model.py`` rather than VHDL, and ``filter_vc``,
whose instances have Python objects as backends. ``python_model`` finds its file
by joining its name to ``base_path``, the directory of the run script, which
``run.py`` sets as the base directory, while the testbench gives the files it
loads itself relative to its own directory. See :ref:`python_bridge:file_paths`.
Loading
Loading