From 94928fba0e050f71ed2def60bdbe134f87f060b5 Mon Sep 17 00:00:00 2001 From: Divik Chotani Date: Sun, 23 Feb 2025 17:43:06 -0800 Subject: [PATCH 1/5] Improve local annotations setup and dependency handling - Modified `pa.sh` for compatibility with local annotations - Added `local-annotations-library-documentation.md` with setup instructions - Introduced `local-or-pypi.sh` to configure package installation mode for local annotations Signed-off-by: Divik Chotani divikchotani@g.ucla.edu Signed-off-by: Divik Chotani --- .gitignore | 3 + local-annotations-library-documentation.md | 83 ++++++++++++++++++++++ local-or-pypi.sh | 58 +++++++++++++++ pa.sh | 4 ++ requirements.txt | 2 +- 5 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 local-annotations-library-documentation.md create mode 100755 local-or-pypi.sh diff --git a/.gitignore b/.gitignore index e3c9c8857..cee5eab49 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,6 @@ runtime/dgsh-tee .vscode/* .idea/* .vs/* + +#venv +venv/* diff --git a/local-annotations-library-documentation.md b/local-annotations-library-documentation.md new file mode 100644 index 000000000..477c2afd8 --- /dev/null +++ b/local-annotations-library-documentation.md @@ -0,0 +1,83 @@ +# PaSh Setup and Execution Guide + +This guide walks you through **setting up and running PaSh** in an isolated environment, including: +- Installing dependencies +- Setting up the virtual environment (`venv`) +- Running `setup-pash.sh` to install required tools +- Exporting `PASH_TOP` +- Running the custom `local-or-pypi.sh` script to configure package installation + +--- + +## **🔹 Step 1: Clone PaSh Repository (If Not Already Cloned)** +If you haven't already cloned PaSh, do so with: + +```sh +git clone https://github.com/binpash/pash.git ~/pash +cd ~/pash +``` + +## **🔹 Step 2: Set Up the Virtual Environment (venv)** +PaSh requires Python dependencies that should be installed inside a virtual environment. + +Create and activate a virtual environment: + +```sh +python3 -m venv venv +source venv/bin/activate +``` + + +## **🔹 Step 3: Run setup-pash.sh to Install Dependencies and Build Runtime Tools** +PaSh includes a setup script that installs necessary dependencies and compiles missing runtime binaries. + +Run: + +```sh +./scripts/setup-pash.sh +``` + + + +Do not forget to export before using pash: `export PASH_TOP=/home/your-username/pash` +To make this persistent across terminal sessions, add it to your shell configuration file: + +```sh +echo 'export PASH_TOP=/home/your-username/pash >> ~/.bashrc +source ~/.bashrc +``` + +## **🔹 Step 5: Run local-or-pypi.sh to Configure Package Installation** +PaSh provides a script to configure whether dependencies should be installed locally (using a cloned repository) or from PyPI. + +To use local dependencies: + +```sh +./local-or-pypi.sh local +``` + +This will: +- Check if `~/annotations` exists. +- If not, clone it from GitHub. +- Update `requirements.txt` to use the local `annotations` repo. + +To use PyPI dependencies: + +```sh +./local-or-pypi.sh pypi +``` + + +## **🔹 Step 6: Run PaSh** +Once everything is set up, test PaSh with: + +```sh +cd ~/pash/evaluation/intro +time $PASH_TOP/pa.sh $PASH_TOP/evaluation/intro/hello-world.sh +``` + +### **Expected Output:** + +```sh +3712 + diff --git a/local-or-pypi.sh b/local-or-pypi.sh new file mode 100755 index 000000000..7cc865cc2 --- /dev/null +++ b/local-or-pypi.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# Define the requirements file path +REQ_FILE="requirements.txt" +ANNOTATIONS_DIR="$HOME/annotations" + +# Check if an argument is provided +if [ $# -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +# If using local mode, ensure ~/annotations exists +if [ "$1" == "local" ]; then + if [ ! -d "$ANNOTATIONS_DIR" ]; then + echo "🔍 ~/annotations not found. Cloning annotations repository..." + git clone https://github.com/binpash/annotations.git "$ANNOTATIONS_DIR" + + # Check if cloning was successful + if [ $? -ne 0 ]; then + echo "❌ Failed to clone annotations repository." + exit 1 + fi + else + echo "✅ ~/annotations already exists. Skipping clone." + fi + + # Get the absolute path + ANNOTATIONS_PATH=$(realpath "$ANNOTATIONS_DIR") +fi + +# Write the correct `requirements.txt` +if [ "$1" == "pypi" ]; then + echo "📦 Writing PyPI requirements to $REQ_FILE..." + cat < "$REQ_FILE" +graphviz +libdash +pash-annotations==0.2.2 +shasta==0.1.0 +sh-expand>=0.1.6 +EOF +elif [ "$1" == "local" ]; then + echo "💻 Writing local development requirements to $REQ_FILE..." + cat < "$REQ_FILE" +graphviz +libdash +shasta==0.1.0 +sh-expand>=0.1.6 +-e $ANNOTATIONS_PATH +EOF +else + echo "❌ Invalid argument: $1" + echo "Usage: $0 " + exit 1 +fi + +echo "✅ Requirements file updated successfully." + diff --git a/pa.sh b/pa.sh index 609dad786..e873a8cab 100755 --- a/pa.sh +++ b/pa.sh @@ -3,7 +3,10 @@ export PASH_TOP=${PASH_TOP:-${BASH_SOURCE%/*}} export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib/" # point to the local downloaded folders +export PYTHONPATH=$PASH_TOP/venv/lib/python3.12/site-packages:$PYTHONPATH export PYTHONPATH="${PASH_TOP}/python_pkgs/:${PYTHONPATH}" +export PYTHONPATH=~/annotations:$PYTHONPATH + ## Register the signal handlers, we can add more signals here trap kill_all SIGTERM SIGINT @@ -74,3 +77,4 @@ if [ "$PASH_DEBUG_LEVEL" -eq 0 ]; then fi (exit "$pash_exit_code") + diff --git a/requirements.txt b/requirements.txt index 4fee3bebe..af7cdfc8d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ graphviz libdash -pash-annotations==0.2.2 shasta==0.1.0 sh-expand>=0.1.6 +-e /home/divikchotani.linux/annotations From cccca4e2ecfa1f9a1fc9bad9c8c1ff0614037219 Mon Sep 17 00:00:00 2001 From: Divik Chotani Date: Fri, 28 Feb 2025 00:47:25 -0800 Subject: [PATCH 2/5] Improve local annotations setup and dependency handling - Modified `pa.sh` for compatibility with local annotations - Added `local-annotations-library-documentation.md` with setup instructions - Introduced `setup-local.sh` to configure package installation mode for local annotations Signed-off-by: Divik Chotani --- README.md | 4 + ...local-annotations-library-documentation.md | 79 +++++++++++++ local-annotations-library-documentation.md | 83 -------------- local-annotations-path.txt | 1 + local-or-pypi.sh | 58 ---------- pa.sh | 49 +++++++- requirements.txt | 3 +- setup-local.sh | 106 ++++++++++++++++++ 8 files changed, 235 insertions(+), 148 deletions(-) create mode 100644 docs/local-annotations-library-documentation.md delete mode 100644 local-annotations-library-documentation.md create mode 100644 local-annotations-path.txt delete mode 100755 local-or-pypi.sh create mode 100755 setup-local.sh diff --git a/README.md b/README.md index 1f0a84478..0553249d5 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,10 @@ export PASH_TOP="$PWD/pash/" For more details, manual installation, or other platforms see [installation instructions](./docs/install). +## Running with a local annotations library + +To run with a local version of the library, please refer to the documentation [local annotations setup and usage](docs/local-annotations-library-documentation.md) + ## Repo Structure This repo hosts the core `pash` development. The structure is as follows: diff --git a/docs/local-annotations-library-documentation.md b/docs/local-annotations-library-documentation.md new file mode 100644 index 000000000..0b5b0655f --- /dev/null +++ b/docs/local-annotations-library-documentation.md @@ -0,0 +1,79 @@ +# PaSh Setup and Execution Guide + +This guide walks you through **setting up and running PaSh**, including: +- Installing dependencies +- Running `setup-pash.sh` to install required tools +- Exporting `PASH_TOP` +- Running the `setup-annotations.sh` script to configure package installation with an optional `--local-annotations` flag + +--- + +## **🔹 Step 1: Clone PaSh Repository (If Not Already Cloned)** +If you haven't already cloned PaSh, do so with: + +```sh +git clone https://github.com/binpash/pash.git +cd pash +``` + +## **🔹 Step 2: Run setup-pash.sh to Install Dependencies and Build Runtime Tools** +PaSh includes a setup script that installs necessary dependencies and compiles missing runtime binaries. + +Run: + +```sh +./scripts/setup-pash.sh +``` + +Before using PaSh, set the `PASH_TOP` environment variable to the directory where PaSh is stored: + +```sh +export PASH_TOP=/path/to/pash +``` + +To make this persistent across terminal sessions, add it to your shell configuration file: + +```sh +echo 'export PASH_TOP=/path/to/pash' >> ~/.bashrc +source ~/.bashrc +``` + +## **🔹 Step 3: Run setup-annotations.sh to Configure Package Installation** +PaSh provides a script to configure dependencies, including an option to install local annotations. + +To install dependencies normally: + +```sh +./setup-annotations.sh +``` + +To install local annotations: +```sh +./setup-local.sh +``` + +To install local annotations: +```sh +./pash.sh --local-annotations +``` + +This will: +- Clone the `annotations` repository as a **sibling** to `pash` (i.e., in the same parent directory), or in a specified path if provided. +- Update `requirements.txt` to add the local `annotations` repo. + +## **🔹 Step 4: Run PaSh** +Once everything is set up, test PaSh with: + +```sh +cd pash/evaluation/intro +time $PASH_TOP/pa.sh $PASH_TOP/evaluation/intro/hello-world.sh +``` + +You can also run the full PaSh test suite: +```sh +$PASH_TOP/evaluation/tests/test_evaluation_scripts.sh +``` +For more details, check the test script here: +[PaSh Evaluation Tests](https://github.com/binpash/pash/blob/main/evaluation/tests/test_evaluation_scripts.sh) + + diff --git a/local-annotations-library-documentation.md b/local-annotations-library-documentation.md deleted file mode 100644 index 477c2afd8..000000000 --- a/local-annotations-library-documentation.md +++ /dev/null @@ -1,83 +0,0 @@ -# PaSh Setup and Execution Guide - -This guide walks you through **setting up and running PaSh** in an isolated environment, including: -- Installing dependencies -- Setting up the virtual environment (`venv`) -- Running `setup-pash.sh` to install required tools -- Exporting `PASH_TOP` -- Running the custom `local-or-pypi.sh` script to configure package installation - ---- - -## **🔹 Step 1: Clone PaSh Repository (If Not Already Cloned)** -If you haven't already cloned PaSh, do so with: - -```sh -git clone https://github.com/binpash/pash.git ~/pash -cd ~/pash -``` - -## **🔹 Step 2: Set Up the Virtual Environment (venv)** -PaSh requires Python dependencies that should be installed inside a virtual environment. - -Create and activate a virtual environment: - -```sh -python3 -m venv venv -source venv/bin/activate -``` - - -## **🔹 Step 3: Run setup-pash.sh to Install Dependencies and Build Runtime Tools** -PaSh includes a setup script that installs necessary dependencies and compiles missing runtime binaries. - -Run: - -```sh -./scripts/setup-pash.sh -``` - - - -Do not forget to export before using pash: `export PASH_TOP=/home/your-username/pash` -To make this persistent across terminal sessions, add it to your shell configuration file: - -```sh -echo 'export PASH_TOP=/home/your-username/pash >> ~/.bashrc -source ~/.bashrc -``` - -## **🔹 Step 5: Run local-or-pypi.sh to Configure Package Installation** -PaSh provides a script to configure whether dependencies should be installed locally (using a cloned repository) or from PyPI. - -To use local dependencies: - -```sh -./local-or-pypi.sh local -``` - -This will: -- Check if `~/annotations` exists. -- If not, clone it from GitHub. -- Update `requirements.txt` to use the local `annotations` repo. - -To use PyPI dependencies: - -```sh -./local-or-pypi.sh pypi -``` - - -## **🔹 Step 6: Run PaSh** -Once everything is set up, test PaSh with: - -```sh -cd ~/pash/evaluation/intro -time $PASH_TOP/pa.sh $PASH_TOP/evaluation/intro/hello-world.sh -``` - -### **Expected Output:** - -```sh -3712 - diff --git a/local-annotations-path.txt b/local-annotations-path.txt new file mode 100644 index 000000000..cd2fd8737 --- /dev/null +++ b/local-annotations-path.txt @@ -0,0 +1 @@ +/home/divikchotani.linux/annotations diff --git a/local-or-pypi.sh b/local-or-pypi.sh deleted file mode 100755 index 7cc865cc2..000000000 --- a/local-or-pypi.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash - -# Define the requirements file path -REQ_FILE="requirements.txt" -ANNOTATIONS_DIR="$HOME/annotations" - -# Check if an argument is provided -if [ $# -ne 1 ]; then - echo "Usage: $0 " - exit 1 -fi - -# If using local mode, ensure ~/annotations exists -if [ "$1" == "local" ]; then - if [ ! -d "$ANNOTATIONS_DIR" ]; then - echo "🔍 ~/annotations not found. Cloning annotations repository..." - git clone https://github.com/binpash/annotations.git "$ANNOTATIONS_DIR" - - # Check if cloning was successful - if [ $? -ne 0 ]; then - echo "❌ Failed to clone annotations repository." - exit 1 - fi - else - echo "✅ ~/annotations already exists. Skipping clone." - fi - - # Get the absolute path - ANNOTATIONS_PATH=$(realpath "$ANNOTATIONS_DIR") -fi - -# Write the correct `requirements.txt` -if [ "$1" == "pypi" ]; then - echo "📦 Writing PyPI requirements to $REQ_FILE..." - cat < "$REQ_FILE" -graphviz -libdash -pash-annotations==0.2.2 -shasta==0.1.0 -sh-expand>=0.1.6 -EOF -elif [ "$1" == "local" ]; then - echo "💻 Writing local development requirements to $REQ_FILE..." - cat < "$REQ_FILE" -graphviz -libdash -shasta==0.1.0 -sh-expand>=0.1.6 --e $ANNOTATIONS_PATH -EOF -else - echo "❌ Invalid argument: $1" - echo "Usage: $0 " - exit 1 -fi - -echo "✅ Requirements file updated successfully." - diff --git a/pa.sh b/pa.sh index e873a8cab..755e73f4a 100755 --- a/pa.sh +++ b/pa.sh @@ -3,9 +3,24 @@ export PASH_TOP=${PASH_TOP:-${BASH_SOURCE%/*}} export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib/" # point to the local downloaded folders -export PYTHONPATH=$PASH_TOP/venv/lib/python3.12/site-packages:$PYTHONPATH export PYTHONPATH="${PASH_TOP}/python_pkgs/:${PYTHONPATH}" -export PYTHONPATH=~/annotations:$PYTHONPATH +export ANNOTATIONS_PATH=$([ -f "$PASH_TOP/local-annotations-path.txt" ] && tr -d '[:space:]' < "$PASH_TOP/local-annotations-path.txt") +#export PYTHONPATH="$ANNOTATIONS_PATH:$PYTHONPATH" +trap cleanup EXIT + +## Function to restore `requirements.txt` on script exit +cleanup() { + if [ -f "$PASH_TOP/requirements_backup.txt" ]; then + mv "$PASH_TOP/requirements_backup.txt" "$PASH_TOP/requirements.txt" + fi + + if [ "$PASH_DEBUG_LEVEL" -eq 0 ]; then + rm -rf "${PASH_TMP_PREFIX}" + fi +} + +## Backup `requirements.txt` +cp "$PASH_TOP/requirements.txt" "$PASH_TOP/requirements_backup.txt" ## Register the signal handlers, we can add more signals here trap kill_all SIGTERM SIGINT @@ -27,7 +42,25 @@ if [ "$#" -eq 1 ] && [ "$1" = "--init" ]; then "$PASH_TOP"/compiler/superoptimize.sh exit fi - +parsed_args=() +skip_flag=0 + + +##This will check if use-local was passed in as a flag, and appropriately use the correct annotations library +for arg in "$@"; do + if [ "$arg" == "--local-annotations" ]; then + sed -i 's/^pash-annotations.*/#&/' $PASH_TOP/requirements.txt + skip_flag=1 + export PYTHONPATH="$ANNOTATIONS_PATH:$PYTHONPATH" + continue + fi + parsed_args+=("$arg") +done + +if [ "$skip_flag" -eq 0 ]; then + sed -i "s|-e $ANNOTATIONS_PATH|#-e $ANNOTATIONS_PATH|" $PASH_TOP/requirements.txt +fi +cat $PASH_TOP/requirements.txt if ! command -v python3 &> /dev/null then echo "Python >=3 could not be found" @@ -55,17 +88,17 @@ export DAEMON_SOCKET="${PASH_TMP_PREFIX}/daemon_socket" export DSPASH_SOCKET="${PASH_TMP_PREFIX}/dspash_socket" ## Initialize all things necessary for pash to execute (logging/functions/etc) -source "$PASH_TOP/compiler/orchestrator_runtime/pash_init_setup.sh" "$@" +source "$PASH_TOP/compiler/orchestrator_runtime/pash_init_setup.sh" "${parsed_args[@]}" ## This starts a different server depending on the configuration if [ "$show_version" -eq 0 ]; then ## Exports $daemon_pid - start_server "$@" + start_server "${parsed_args[@]}" fi ## Restore the umask before executing umask "$old_umask" -PASH_FROM_SH="pa.sh" python3 -S "$PASH_TOP/compiler/pash.py" "$@" +PASH_FROM_SH="pa.sh" python3 -S "$PASH_TOP/compiler/pash.py" "${parsed_args[@]}" pash_exit_code=$? if [ "$show_version" -eq 0 ]; then cleanup_server "${daemon_pid}" @@ -76,5 +109,9 @@ if [ "$PASH_DEBUG_LEVEL" -eq 0 ]; then rm -rf "${PASH_TMP_PREFIX}" fi +sed -i 's/^#\(pash-annotations.*\)$/\1/' "$PASH_TOP/requirements.txt" +sed -i "s|^#-e $ANNOTATIONS_PATH|-e $ANNOTATIONS_PATH|" "$PASH_TOP/requirements.txt" + (exit "$pash_exit_code") + diff --git a/requirements.txt b/requirements.txt index af7cdfc8d..31197a9f9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ graphviz libdash +pash-annotations==0.2.2 shasta==0.1.0 sh-expand>=0.1.6 --e /home/divikchotani.linux/annotations + diff --git a/setup-local.sh b/setup-local.sh new file mode 100755 index 000000000..21a660a9f --- /dev/null +++ b/setup-local.sh @@ -0,0 +1,106 @@ +# #!/bin/bash + +# # Define the requirements file path +# REQ_FILE="requirements.txt" + +# # Determine PaSh top directory +# PASH_TOP=$(dirname "$(realpath "$0")") + +# # Default annotations directory (sibling of PASH_TOP) +# DEFAULT_ANNOTATIONS_DIR="$(dirname "$PASH_TOP")/annotations" + +# # Use user-provided path if given, otherwise use default +# if [ -n "$2" ]; then +# ANNOTATIONS_DIR="$2" +# ANNOTATIONS_DIR=$(realpath "$ANNOTATIONS_DIR") +# else +# ANNOTATIONS_DIR="$DEFAULT_ANNOTATIONS_DIR" +# fi + +# echo "📂 Annotations directory set to: $ANNOTATIONS_DIR" + +# # Check if at least one argument is provided +# if [ $# -lt 1 ]; then +# echo "Usage: $0 [annotations_dir]" +# exit 1 +# fi + +# # Store the current version of pash-annotations only if using pypi mode or if it is for the first time +# if [ "$1" == "pypi" ] && [ ! -s pash-annotations.version ]; then +# grep 'pash-annotations' requirements.txt > pash-annotations.version +# fi + + +# # Ensure the annotations directory exists for local mode +# if [ "$1" == "local" ]; then +# if [ ! -d "$ANNOTATIONS_DIR" ]; then +# echo "🔍 $ANNOTATIONS_DIR not found. Cloning annotations repository..." +# git clone https://github.com/binpash/annotations.git "$ANNOTATIONS_DIR" + +# if [ $? -ne 0 ]; then +# echo "❌ Failed to clone annotations repository." +# exit 1 +# fi +# else +# echo "✅ $ANNOTATIONS_DIR already exists. Skipping clone." +# fi + +# # Get the absolute path +# ANNOTATIONS_PATH=$(realpath "$ANNOTATIONS_DIR") +# fi + +# # Generate `requirements.txt` dynamically +# echo "🔄 Generating $REQ_FILE..." + +# # Copy base requirements +# cp requirements.base.txt $REQ_FILE + +# # If local mode is selected, add the editable annotation repo +# if [ "$1" == "local" ]; then +# echo "-e $ANNOTATIONS_PATH" >> $REQ_FILE +# echo "✅ Local annotations added to $REQ_FILE" +# else +# # Ensure `pash-annotations` is only added once +# if ! grep -q 'pash-annotations' $REQ_FILE; then +# cat pash-annotations.version >> $REQ_FILE +# fi +# echo "✅ Using PyPI annotations: $(cat pash-annotations.version)" +# fi + +#!/bin/bash + +# Define the requirements file path +REQ_FILE="requirements.txt" + +# Determine PaSh top directory +PASH_TOP=$(dirname "$(realpath "$0")") + +# Default annotations directory (sibling of PASH_TOP) +DEFAULT_ANNOTATIONS_DIR="$(dirname "$PASH_TOP")/annotations" + +# Use user-provided path if given, otherwise use default +if [ -n "$1" ]; then + ANNOTATIONS_DIR="$1" + ANNOTATIONS_DIR=$(realpath "$ANNOTATIONS_DIR") +else + ANNOTATIONS_DIR="$DEFAULT_ANNOTATIONS_DIR" +fi + +echo "📂 Annotations directory set to: $ANNOTATIONS_DIR" + +# Always clone the repository to the specified or default location +echo "🔄 Downloading annotations repository..." +rm -rf "$ANNOTATIONS_DIR" +git clone https://github.com/binpash/annotations.git "$ANNOTATIONS_DIR" + +if [ $? -ne 0 ]; then + echo "❌ Failed to clone annotations repository." + exit 1 +fi + +# Get the absolute path +ANNOTATIONS_PATH=$(realpath "$ANNOTATIONS_DIR") +echo $ANNOTATIONS_PATH > local-annotations-path.txt +echo "✅ Annotations repository cloned to: $ANNOTATIONS_PATH" +grep -qxF "$ANNOTATIONS_PATH" requirements.txt || echo -e "\n-e $ANNOTATIONS_PATH" >> requirements.txt + From a606d7b070cc3ebc608103489ad0bf3948cb6eb0 Mon Sep 17 00:00:00 2001 From: Divik Chotani <108592052+DivikChotani@users.noreply.github.com> Date: Fri, 28 Feb 2025 02:44:01 -0800 Subject: [PATCH 3/5] Update local-annotations-library-documentation.md minor change to readme --- docs/local-annotations-library-documentation.md | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/docs/local-annotations-library-documentation.md b/docs/local-annotations-library-documentation.md index 0b5b0655f..4262a74bf 100644 --- a/docs/local-annotations-library-documentation.md +++ b/docs/local-annotations-library-documentation.md @@ -43,20 +43,11 @@ PaSh provides a script to configure dependencies, including an option to install To install dependencies normally: -```sh -./setup-annotations.sh -``` - To install local annotations: ```sh ./setup-local.sh ``` -To install local annotations: -```sh -./pash.sh --local-annotations -``` - This will: - Clone the `annotations` repository as a **sibling** to `pash` (i.e., in the same parent directory), or in a specified path if provided. - Update `requirements.txt` to add the local `annotations` repo. @@ -69,6 +60,12 @@ cd pash/evaluation/intro time $PASH_TOP/pa.sh $PASH_TOP/evaluation/intro/hello-world.sh ``` +To run it with local annotation: +```sh +cd pash/evaluation/intro +time $PASH_TOP/pa.sh $PASH_TOP/evaluation/intro/hello-world.sh --local-annotations +``` + You can also run the full PaSh test suite: ```sh $PASH_TOP/evaluation/tests/test_evaluation_scripts.sh From a5623cf4cae1241304bdce65bd42dc1698708f3f Mon Sep 17 00:00:00 2001 From: Divik Chotani Date: Fri, 28 Feb 2025 12:30:40 -0800 Subject: [PATCH 4/5] add --local-annotations-dir support for dynamic annotation loading - Implemented `--local-annotations-dir` to allow dynamic switching of annotation. - Updated `pash_init_setup.sh` to adjust `PYTHONPATH` based on user input. - Allowed `cli.py` to recognize and prioritize local annotations when provided. - Ensured clean handling of `requirements.txt`, avoiding unnecessary modifications. Signed-off-by: Divik Chotani divikchotani@g.ucla.edu Signed-off-by: Divik Chotani --- .gitignore | 3 + compiler/cli.py | 8 +++ .../orchestrator_runtime/pash_init_setup.sh | 22 ++++++ pa.sh | 14 ++-- setup-local.sh | 71 +------------------ 5 files changed, 43 insertions(+), 75 deletions(-) diff --git a/.gitignore b/.gitignore index cee5eab49..0d22043b4 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,6 @@ runtime/dgsh-tee #venv venv/* + +# Ignore local annotations path +local-annotations-path.txt \ No newline at end of file diff --git a/compiler/cli.py b/compiler/cli.py index bfab6c988..ed596494d 100644 --- a/compiler/cli.py +++ b/compiler/cli.py @@ -215,6 +215,14 @@ def __init__(self, *args, **kwargs): help=" output the preprocessed script", action="store_true", ) + self.add_argument( + "--local-annotations-dir", + help="Specify a local annotations directory instead of using the default one", + nargs="?", # <-- Makes it optional (accepts zero or one argument) + const="", # <-- Allows flag usage without an argument + type=str, + default=None, + ) self.add_argument( "--interactive", help="Executes the script using an interactive internal shell session (experimental)", diff --git a/compiler/orchestrator_runtime/pash_init_setup.sh b/compiler/orchestrator_runtime/pash_init_setup.sh index 966474a5c..6b61c6e6a 100644 --- a/compiler/orchestrator_runtime/pash_init_setup.sh +++ b/compiler/orchestrator_runtime/pash_init_setup.sh @@ -23,6 +23,7 @@ export pash_daemon_communicates_through_unix_pipes_flag=0 export pash_speculative_flag=0 export show_version=0 export distributed_exec=0 +export local_annotations=0 for item in "$@" do @@ -87,11 +88,27 @@ do if [ "--distributed_exec" == "$item" ]; then export distributed_exec=1 fi + + if [ "--local-annotations-dir" == "$item" ]; then + shift + export ANNOTATIONS_PATH=$(realpath "$2") + export local_annotations=1 + export PYTHONPATH="$ANNOTATIONS_PATH:$PYTHONPATH" + #echo "✅ Using local annotations directory: $ANNOTATIONS_PATH" + fi done ## `pash_redir_output` and `pash_redir_all_output` are strictly for logging. ## ## They do not execute their arguments if there is no debugging. +if [ "$local_annotations" -eq 1 ]; then + # Comment out the PyPI-installed `pash-annotations` + sed -i 's/^pash-annotations.*/#&/' "$PASH_TOP/requirements.txt" + + # Add the local annotations path only if not already in `requirements.txt` + grep -qxF "-e $ANNOTATIONS_PATH" "$PASH_TOP/requirements.txt" || echo "-e $ANNOTATIONS_PATH" >> "$PASH_TOP/requirements.txt" +fi + if [ "$PASH_DEBUG_LEVEL" -eq 0 ]; then pash_redir_output() { @@ -221,6 +238,11 @@ else { local daemon_pid=$1 ## Only wait for daemon if it lives (it might be dead, rip) + + ##bring back the pypi annotations and remove the local annotations library + sed -i 's/^#\(pash-annotations.*\)$/\1/' "$PASH_TOP/requirements.txt" + sed -i "\|^-e $ANNOTATIONS_PATH|d" "$PASH_TOP/requirements.txt" + if ps -p "$daemon_pid" > /dev/null then ## Send and receive from daemon diff --git a/pa.sh b/pa.sh index 755e73f4a..280681884 100755 --- a/pa.sh +++ b/pa.sh @@ -42,8 +42,6 @@ if [ "$#" -eq 1 ] && [ "$1" = "--init" ]; then "$PASH_TOP"/compiler/superoptimize.sh exit fi -parsed_args=() -skip_flag=0 ##This will check if use-local was passed in as a flag, and appropriately use the correct annotations library @@ -88,17 +86,23 @@ export DAEMON_SOCKET="${PASH_TMP_PREFIX}/daemon_socket" export DSPASH_SOCKET="${PASH_TMP_PREFIX}/dspash_socket" ## Initialize all things necessary for pash to execute (logging/functions/etc) -source "$PASH_TOP/compiler/orchestrator_runtime/pash_init_setup.sh" "${parsed_args[@]}" +source "$PASH_TOP/compiler/orchestrator_runtime/pash_init_setup.sh" "$@" + +# Read annotations path if set + +#echo $PYTHONPATH + +# Ensure the local annotations directory is in `PYTHONPATH` ## This starts a different server depending on the configuration if [ "$show_version" -eq 0 ]; then ## Exports $daemon_pid - start_server "${parsed_args[@]}" + start_server "$@" fi ## Restore the umask before executing umask "$old_umask" -PASH_FROM_SH="pa.sh" python3 -S "$PASH_TOP/compiler/pash.py" "${parsed_args[@]}" +PASH_FROM_SH="pa.sh" python3 -S "$PASH_TOP/compiler/pash.py" "$@" pash_exit_code=$? if [ "$show_version" -eq 0 ]; then cleanup_server "${daemon_pid}" diff --git a/setup-local.sh b/setup-local.sh index 21a660a9f..9ee37916b 100755 --- a/setup-local.sh +++ b/setup-local.sh @@ -1,72 +1,3 @@ -# #!/bin/bash - -# # Define the requirements file path -# REQ_FILE="requirements.txt" - -# # Determine PaSh top directory -# PASH_TOP=$(dirname "$(realpath "$0")") - -# # Default annotations directory (sibling of PASH_TOP) -# DEFAULT_ANNOTATIONS_DIR="$(dirname "$PASH_TOP")/annotations" - -# # Use user-provided path if given, otherwise use default -# if [ -n "$2" ]; then -# ANNOTATIONS_DIR="$2" -# ANNOTATIONS_DIR=$(realpath "$ANNOTATIONS_DIR") -# else -# ANNOTATIONS_DIR="$DEFAULT_ANNOTATIONS_DIR" -# fi - -# echo "📂 Annotations directory set to: $ANNOTATIONS_DIR" - -# # Check if at least one argument is provided -# if [ $# -lt 1 ]; then -# echo "Usage: $0 [annotations_dir]" -# exit 1 -# fi - -# # Store the current version of pash-annotations only if using pypi mode or if it is for the first time -# if [ "$1" == "pypi" ] && [ ! -s pash-annotations.version ]; then -# grep 'pash-annotations' requirements.txt > pash-annotations.version -# fi - - -# # Ensure the annotations directory exists for local mode -# if [ "$1" == "local" ]; then -# if [ ! -d "$ANNOTATIONS_DIR" ]; then -# echo "🔍 $ANNOTATIONS_DIR not found. Cloning annotations repository..." -# git clone https://github.com/binpash/annotations.git "$ANNOTATIONS_DIR" - -# if [ $? -ne 0 ]; then -# echo "❌ Failed to clone annotations repository." -# exit 1 -# fi -# else -# echo "✅ $ANNOTATIONS_DIR already exists. Skipping clone." -# fi - -# # Get the absolute path -# ANNOTATIONS_PATH=$(realpath "$ANNOTATIONS_DIR") -# fi - -# # Generate `requirements.txt` dynamically -# echo "🔄 Generating $REQ_FILE..." - -# # Copy base requirements -# cp requirements.base.txt $REQ_FILE - -# # If local mode is selected, add the editable annotation repo -# if [ "$1" == "local" ]; then -# echo "-e $ANNOTATIONS_PATH" >> $REQ_FILE -# echo "✅ Local annotations added to $REQ_FILE" -# else -# # Ensure `pash-annotations` is only added once -# if ! grep -q 'pash-annotations' $REQ_FILE; then -# cat pash-annotations.version >> $REQ_FILE -# fi -# echo "✅ Using PyPI annotations: $(cat pash-annotations.version)" -# fi - #!/bin/bash # Define the requirements file path @@ -91,7 +22,7 @@ echo "📂 Annotations directory set to: $ANNOTATIONS_DIR" # Always clone the repository to the specified or default location echo "🔄 Downloading annotations repository..." rm -rf "$ANNOTATIONS_DIR" -git clone https://github.com/binpash/annotations.git "$ANNOTATIONS_DIR" +git clone https://github.com/binpash/annotations.git "$ANNOTATIONS_DIR" if [ $? -ne 0 ]; then echo "❌ Failed to clone annotations repository." From a73ffa9a208b0045324e2cf9fd5002f0b18eddbe Mon Sep 17 00:00:00 2001 From: Divik Chotani Date: Fri, 28 Feb 2025 12:45:46 -0800 Subject: [PATCH 5/5] feat: add --local-annotations-dir support for dynamic annotation loading - Resolved merge conflicts between remote and local Signed-off-by: Divik Chotani divikchotani@g.ucla.edu Signed-off-by: Divik Chotani --- evaluation/intro/hello-world.sh | 2 +- pa.sh | 15 --------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/evaluation/intro/hello-world.sh b/evaluation/intro/hello-world.sh index 21498d3b2..b63e665fc 100755 --- a/evaluation/intro/hello-world.sh +++ b/evaluation/intro/hello-world.sh @@ -1,7 +1,7 @@ [ $(uname) = 'Darwin' ] && a=/usr/share/dict/web2 || a=/usr/share/dict/words if [ -f $a ]; then - cat $a $a $a $a $a $a $a $a | grep '\(.\).*\1\(.\).*\2\(.\).*\3\(.\).*\4' | wc -l + cat-wrapper $a $a $a $a $a $a $a $a | grep '\(.\).*\1\(.\).*\2\(.\).*\3\(.\).*\4' | wc -l else echo "Dictionary file $a not found.." fi diff --git a/pa.sh b/pa.sh index 280681884..ac40b5fca 100755 --- a/pa.sh +++ b/pa.sh @@ -44,21 +44,6 @@ if [ "$#" -eq 1 ] && [ "$1" = "--init" ]; then fi -##This will check if use-local was passed in as a flag, and appropriately use the correct annotations library -for arg in "$@"; do - if [ "$arg" == "--local-annotations" ]; then - sed -i 's/^pash-annotations.*/#&/' $PASH_TOP/requirements.txt - skip_flag=1 - export PYTHONPATH="$ANNOTATIONS_PATH:$PYTHONPATH" - continue - fi - parsed_args+=("$arg") -done - -if [ "$skip_flag" -eq 0 ]; then - sed -i "s|-e $ANNOTATIONS_PATH|#-e $ANNOTATIONS_PATH|" $PASH_TOP/requirements.txt -fi -cat $PASH_TOP/requirements.txt if ! command -v python3 &> /dev/null then echo "Python >=3 could not be found"