Update readme and scripts for setting the new PYTHONPATH

Add scripts for generating .env and update instructions in README.
pull/260/head
Yi Zhang 2021-07-28 12:52:13 -04:00
parent ec611c1e6f
commit 6fbf94f0b2
2 changed files with 37 additions and 7 deletions

View File

@ -60,10 +60,15 @@ The cmake configuration populates symlinks in the `build/python` directory
mirroring the source layout. This allows edit-run without rebuilding (unless mirroring the source layout. This allows edit-run without rebuilding (unless
if files are added/removed). if files are added/removed).
Configuring the `PYTHONPATH` as above should be sufficient to run any For using with any interactive tooling (`python3`, Jupyter/Colab, etc) it should be
interactive tooling (`python3`, Jupyter/Colab, etc). sufficient to add `python_packages/npcomp_torch/` and `python_packages/npcomp_core/`
directories under `build` directory to `PYTHONPATH`
Note that running the `cmake_configure.sh` script will also output a `.env` ```shell
export PYTHONPATH=$(cd build && pwd)/python_packages/npcomp_torch:$(cd build && pwd)/python_packages/npcomp_core
```
Note that running the `build_tools/write_env_file.sh` script will output a `.env`
file in the workspace folder with the correct PYTHONPATH set. This allows file in the workspace folder with the correct PYTHONPATH set. This allows
tools like VSCode to work by default for debugging. tools like VSCode to work by default for debugging.
@ -101,6 +106,10 @@ LLVM_VERSION=10
export CC=clang-$LLVM_VERSION export CC=clang-$LLVM_VERSION
export CXX=clang++-$LLVM_VERSION export CXX=clang++-$LLVM_VERSION
export LDFLAGS=-fuse-ld=$(which ld.lld-$LLVM_VERSION) export LDFLAGS=-fuse-ld=$(which ld.lld-$LLVM_VERSION)
# run write_env_file.sh to emit a .env file with needed
# PYTHONPATH setup.
./build_tools/write_env_file.sh
``` ```
### Vanilla - numpy-only, no pytorch ### Vanilla - numpy-only, no pytorch
@ -119,10 +128,6 @@ cmake -GNinja -Bbuild -DCMAKE_BUILD_TYPE=Release .
cd build cd build
ninja ninja
ninja check-npcomp ninja check-npcomp
# cmake_configure.sh should emit a .env file with needed
# PYTHONPATH setup.
source .env
``` ```
### With PyTorch integration ### With PyTorch integration

View File

@ -0,0 +1,25 @@
#!/bin/bash
# generate the .env file with default options.
#
# For arbitrary build/install directories, set the env variables:
# - NPCOMP_BUILD_DIR
portable_realpath() {
# Create the directory if needed so that the `cd` doesn't fail.
mkdir -p $1 && cd $1 && pwd
}
td="$(portable_realpath $(dirname $0)/..)"
build_dir="$(portable_realpath "${NPCOMP_BUILD_DIR:-$td/build}")"
python_packages_dir="$build_dir/python_packages"
write_env_file() {
echo "Updating $build_dir/.env file"
echo "PYTHONPATH=\"$(portable_realpath "$python_packages_dir/npcomp_core"):$(portable_realpath "$python_packages_dir/npcomp_torch")\"" > "$build_dir/.env"
echo "NUMPY_EXPERIMENTAL_ARRAY_FUNCTION=1" >> "$build_dir/.env"
if ! cp "$build_dir/.env" "$td/.env"; then
echo "WARNING: Failed to write $td/.env"
fi
}
write_env_file