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

Local annotations setup and minor dependency handling #750

Open
wants to merge 6 commits into
base: future
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ runtime/dgsh-tee
.vscode/*
.idea/*
.vs/*

#venv
venv/*
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
76 changes: 76 additions & 0 deletions docs/local-annotations-library-documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# 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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a typo?


To install local annotations:
```sh
./setup-local.sh
```

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
```

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't run the PaSh test suite with the local annotations, why do you mention it then?

```
For more details, check the test script here:
[PaSh Evaluation Tests](https://github.com/binpash/pash/blob/main/evaluation/tests/test_evaluation_scripts.sh)


1 change: 1 addition & 0 deletions local-annotations-path.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/divikchotani.linux/annotations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be git-ignored!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or completely removed since it is not used anymore

47 changes: 44 additions & 3 deletions pa.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,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}/python_pkgs/:${PYTHONPATH}"
export ANNOTATIONS_PATH=$([ -f "$PASH_TOP/local-annotations-path.txt" ] && tr -d '[:space:]' < "$PASH_TOP/local-annotations-path.txt")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see where you are going with this but it is very scary and a very big dependency for PaSh. I think the most appropriate way would be to modify PaSh's installation (scripts/setup_pash.sh) to copy the annotation repo in the right place. I could see two ways to do this:

  1. Either create a small installation script that replaces the annotation repo where pash looks for dependencies (https://github.com/binpash/pash/blob/future/scripts/setup-pash.sh#L37) and call it there (https://github.com/binpash/pash/blob/future/scripts/setup-pash.sh#L37). Then everytime the user modifies the annotation repo they will call this script and replace their local version of annotations. If we do that we also need to create a script that redownloads the latest normal annotations if needed.
  2. Properly add a new --local-annotations-dir option to PaSh (https://github.com/binpash/pash/blob/future/compiler/orchestrator_runtime/pash_init_setup.sh#L27) which could be used to update PYTHONPATH to point first to where the local annotation library is. I think this is the preferred solution if it works :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the changes in pa.sh now? I think we should delete all of them, I don't see why they are necessary.

#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

Expand All @@ -24,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"
Expand Down Expand Up @@ -52,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}"
Expand All @@ -73,4 +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")


1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ libdash
pash-annotations==0.2.2
shasta==0.1.0
sh-expand>=0.1.6

106 changes: 106 additions & 0 deletions setup-local.sh
Original file line number Diff line number Diff line change
@@ -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 <local|pypi> [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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we modify requirements here? Why is this useful?