Update all python imports to be absolute and use a .env file to set the path correctly.

This makes things just work for debugging in VSCode.
pull/1/head
Stella Laurenzo 2020-05-06 23:25:04 -07:00
parent 3611958b11
commit 0092b912ab
7 changed files with 42 additions and 10 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
.vscode .vscode
.env
build build
build-mlir build-mlir

View File

@ -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 The `run_tests.py` script is special in that it sets up the PYTHONPATH
correctly when run. 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: ### Things to look at:
* `python/npcomp/tracing/mlir_trace_test.py` : Simple test case of tracing a function to an MLIR module. * `python/npcomp/tracing/mlir_trace_test.py` : Simple test case of tracing a function to an MLIR module.

View File

@ -6,7 +6,7 @@ import inspect
import numpy as np import numpy as np
from typing import Optional from typing import Optional
from .types import * from npcomp.types import *
__all__ = [ __all__ = [
"Exporter", "Exporter",

View File

@ -8,11 +8,11 @@ import numpy as np
from _npcomp.mlir import ir from _npcomp.mlir import ir
from ..dialect import Numpy from npcomp.dialect import Numpy
from .context import * from npcomp.exporter import *
from .emitters import * from npcomp.types import *
from ..exporter import * from npcomp.tracing.context import *
from ..types import * from npcomp.tracing.emitters import *
class ModuleBuilder: class ModuleBuilder:

View File

@ -2,10 +2,10 @@
# See https://llvm.org/LICENSE.txt for license information. # See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
from ..types import * from npcomp.types import *
from ..exporter import * from npcomp.exporter import *
from .mlir_trace import * from npcomp.tracing.mlir_trace import *
from ..utils import test_utils from npcomp.utils import test_utils
test_utils.start_filecheck_test() test_utils.start_filecheck_test()

View File

@ -22,6 +22,10 @@ if [ -z "$python_exe" ]; then
exit 1 exit 1
fi 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 set -x
cmake -GNinja \ cmake -GNinja \
"-H$td" \ "-H$td" \

View File

@ -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")