diff --git a/.gitignore b/.gitignore index 46b0a397e..7f8667ed0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .vscode +.env build build-mlir diff --git a/README.md b/README.md index 36f060a38..6a682a986 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,10 @@ export PYTHONPATH="$(realpath build/python):$(realpath build/python_native)" The `run_tests.py` script is special in that it sets up the PYTHONPATH correctly when run. +Note that running the `cmake_configure.sh` script will also output a `.env` +file in the workspace folder with the correct PYTHONPATH set. This allows +tools like VSCode to work by default for debugging. + ### Things to look at: * `python/npcomp/tracing/mlir_trace_test.py` : Simple test case of tracing a function to an MLIR module. diff --git a/python/npcomp/exporter.py b/python/npcomp/exporter.py index b0ad01513..ba08cff41 100644 --- a/python/npcomp/exporter.py +++ b/python/npcomp/exporter.py @@ -6,7 +6,7 @@ import inspect import numpy as np from typing import Optional -from .types import * +from npcomp.types import * __all__ = [ "Exporter", diff --git a/python/npcomp/tracing/mlir_trace.py b/python/npcomp/tracing/mlir_trace.py index f77bce642..a37347a06 100644 --- a/python/npcomp/tracing/mlir_trace.py +++ b/python/npcomp/tracing/mlir_trace.py @@ -8,11 +8,11 @@ import numpy as np from _npcomp.mlir import ir -from ..dialect import Numpy -from .context import * -from .emitters import * -from ..exporter import * -from ..types import * +from npcomp.dialect import Numpy +from npcomp.exporter import * +from npcomp.types import * +from npcomp.tracing.context import * +from npcomp.tracing.emitters import * class ModuleBuilder: diff --git a/python/npcomp/tracing/mlir_trace_test.py b/python/npcomp/tracing/mlir_trace_test.py index 6ad348a3f..3accb73ea 100644 --- a/python/npcomp/tracing/mlir_trace_test.py +++ b/python/npcomp/tracing/mlir_trace_test.py @@ -2,10 +2,10 @@ # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -from ..types import * -from ..exporter import * -from .mlir_trace import * -from ..utils import test_utils +from npcomp.types import * +from npcomp.exporter import * +from npcomp.tracing.mlir_trace import * +from npcomp.utils import test_utils test_utils.start_filecheck_test() diff --git a/tools/cmake_configure.sh b/tools/cmake_configure.sh index b2c7c2d94..f81408dd8 100755 --- a/tools/cmake_configure.sh +++ b/tools/cmake_configure.sh @@ -22,6 +22,10 @@ if [ -z "$python_exe" ]; then exit 1 fi +# Write a .env file for python tooling. +echo "Updating $td/.env file" +echo "PYTHONPATH=\"$(realpath "$build_dir/python_native"):$(realpath "$build_dir/python")\"" > "$td/.env" + set -x cmake -GNinja \ "-H$td" \ diff --git a/tools/show_python_info.py b/tools/show_python_info.py new file mode 100644 index 000000000..1450e9197 --- /dev/null +++ b/tools/show_python_info.py @@ -0,0 +1,23 @@ +#!/usr/bin/python3 +# Simple script to run and verify python path and ability to find +# modules. Run/debug this from your terminal or IDE to make sure things +# are setup correctly. + +import sys +print("PYTHONPATH =", sys.path) +print("SYS VERSION =", sys.version) +print("PYTHON EXE =", sys.executable) + +try: + import npcomp + print("Loaded npcomp module") +except ImportError: + print("ERROR: Could not load the npcomp module.", + "Ensure that build/python is on your PYTHONPATH") + +try: + import _npcomp + print("Loaded (native) _npcomp module") +except ImportError: + print("ERROR: Could not load the _npcomp native module.", + "Ensure that build/python_native is on your PYTHONPATH")