Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"No netlist" error when running a Python script on a netlist in commandline mode #590

Open
harnhua opened this issue Sep 23, 2024 · 2 comments

Comments

@harnhua
Copy link

harnhua commented Sep 23, 2024

Hi,
After successfully loading a netlist and executing the following lines of sample Python code in the Python widget, I saved the commands in a .py script.

from hal_plugins import graph_algorithm

graph = graph_algorithm.NetlistGraph.from_netlist(netlist)

However, when I tried to load the project and execute the same commands in a .py script, HAL says that the "netlist" object does not exist.

hal --project-dir <directory containing HAL project> --python-script test.py
Looking at the log messages, it seems like the Python script was executed before the netlist was loaded.

[gate_library_parser] [info] registered gate library parser 'Default HGL Parser' for file extension '.hgl'.
[core] [info] executing 'python_shell' with
[core] [info]   '--python-script': netlists/graphing.py
Traceback (most recent call last):
  File "<string>", line 3, in <module>
NameError: name 'netlist' is not defined. Did you mean: 'Netlist'?

Am I missing an argument or Python command?

Thanks!

@harnhua harnhua changed the title No "netlist" error when running a Python script on a netlist in commandline mode "No netlist" error when running a Python script on a netlist in commandline mode Sep 23, 2024
@harnhua
Copy link
Author

harnhua commented Sep 24, 2024

If I omit the --python-script argument, then the project seems to load without issue.
hal --project-dir <directory containing HAL project>

Is there a way to make the Python script execute after the project is loaded?
Or alternatively, is there a command to load the project from the Python script?

@RenWal
Copy link
Contributor

RenWal commented Oct 14, 2024

The old python_shell plugin wasn't updated in about 5 years and is therefore not really compatible with the current state of HAL. You do still get a Python shell, but don't have access to any of the project context, so it's not very useful.

The file that needs to be updated is https://github.com/emsec/hal/blob/c6f7150f5130549ffe62b8a95cc2decfa3af0c78/plugins/python_shell/src/plugin_python_shell.cpp . Pull requests are welcome. You can look at the way that the GUI initializes its Python interpreter, particularly the PythonContext::initializeScript invocation:

void PythonContext::initializeScript(py::dict *context)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants