Skip to content

Commit

Permalink
use python shell in just
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Turcan committed Oct 30, 2024
1 parent fd1f4f3 commit b18ba0a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 93 deletions.
45 changes: 9 additions & 36 deletions docker/containers.just
Original file line number Diff line number Diff line change
@@ -1,58 +1,31 @@
set shell := ["python3", "-c"]

[private]
default:
@just -l containers
@__import__('os').system("just -l containers")

[private]
[no-cd]
check:
# If the system is Linux or macOS, execute the check with bash.
@if [[ {{os()}} == "linux" ]] || [[ {{os()}} == "macos" ]]; then \
if ! docker ps | grep -q "examples"; then \
echo "Docker environment is not running. Starting environment..."; \
just containers start; \
else \
echo "Docker environment is already running."; \
fi; \
else \
powershell -Command "if (!(docker ps | Select-String -Quiet 'examples')) { Write-Host 'Docker environment is not running. Starting environment...'; just containers start } else { Write-Host 'Docker environment is already running.' }"; \
fi
@import os, sys; from subprocess import call; result = call("docker ps | grep -q 'examples'", shell=True); \
print("Docker environment is already running.") if result == 0 else (print("Docker environment is not running. Starting environment...") or os.system("just containers start"))

# Builds the Docker containers using Docker Compose
[no-cd]
build:
@if [[ {{os()}} == "linux" ]] || [[ {{os()}} == "macos" ]]; then \
echo "Building Docker containers..."; \
python ./docker/nexusctl.py create; \
else \
powershell -Command "Write-Host 'Building Docker containers...'; python ./docker/nexusctl.py create"; \
fi
@print("Building Docker containers..."); __import__('os').system("python3 ./docker/nexusctl.py create")

# Starts the Docker containers using Docker Compose
[no-cd]
start:
@if [[ {{os()}} == "linux" ]] || [[ {{os()}} == "macos" ]]; then \
echo "Starting Docker containers..."; \
python ./docker/nexusctl.py start; \
else \
powershell -Command "Write-Host 'Starting Docker containers...'; python ./docker/nexusctl.py start"; \
fi
@print("Starting Docker containers..."); __import__('os').system("python3 ./docker/nexusctl.py start")

# Stops the Docker containers using Docker Compose
[no-cd]
stop:
@if [[ {{os()}} == "linux" ]] || [[ {{os()}} == "macos" ]]; then \
echo "Stopping Docker containers..."; \
python ./docker/nexusctl.py stop; \
else \
powershell -Command "Write-Host 'Stopping Docker containers...'; python ./docker/nexusctl.py stop"; \
fi
@print("Stopping Docker containers..."); __import__('os').system("python3 ./docker/nexusctl.py stop")

# Deletes all Docker volumes related to the project using Docker Compose
[no-cd]
clean:
@if [[ {{os()}} == "linux" ]] || [[ {{os()}} == "macos" ]]; then \
echo "Deleting Docker volumes..."; \
python ./docker/nexusctl.py delete; \
else \
powershell -Command "Write-Host 'Deleting Docker volumes...'; python ./docker/nexusctl.py delete"; \
fi
@print("Deleting Docker volumes..."); __import__('os').system("python3 ./docker/nexusctl.py delete")
39 changes: 13 additions & 26 deletions examples/example.just
Original file line number Diff line number Diff line change
@@ -1,39 +1,26 @@
set shell := [ "python3", "-c"]

[private]
default: version-check
@__import__('os').system("just -l example")

[private]
default:
@just -l example
version-check:
@import sys; major, minor = sys.version_info[:2]; \
assert (major, minor) >= (3, 7), "This script requires at least Python 3.7. Please link \"python3\" to Python 3.7 or higher and try again."


# Runs an example that prompts the user for a description of their post.
[no-cd]
ig-post-planner:
@if [[ {{os()}} == "linux" ]] || [[ {{os()}} == "macos" ]]; then \
just containers check && \
docker exec -it examples /bin/bash -c "source .venv/bin/activate && python examples/main.py ig_post_planner"; \
else \
powershell -Command "just containers check"; \
powershell -Command "docker exec -it examples /bin/bash -c 'source .venv/bin/activate && python examples/main.py ig_post_planner'"; \
fi
@__import__('os').system("just containers check && docker exec -it examples /bin/bash -c 'source .venv/bin/activate && python examples/main.py ig_post_planner'")

# Runs an example that prompts the user for description of their trip.
[no-cd]
trip-planner:
if [[ {{os()}} == "linux" ]] || [[ {{os()}} == "macos" ]]; then \
just containers check && \
docker exec -it examples /bin/bash -c "source .venv/bin/activate && python examples/main.py trip_planner"; \
else \
powershell -Command "just containers check"; \
powershell -Command "docker exec -it examples /bin/bash -c 'source .venv/bin/activate && python examples/main.py trip_planner'"; \
fi

@__import__('os').system("just containers check && docker exec -it examples /bin/bash -c 'source .venv/bin/activate && python examples/main.py trip_planner'")

# Runs an example that prompts the user for description of their cluster.
[no-cd]
cli-cluster:
@if [[ {{os()}} == "linux" ]] || [[ {{os()}} == "macos" ]]; then \
just containers check && \
docker exec -it examples /bin/bash -c "source .venv/bin/activate && python examples/main.py cli_cluster"; \
else \
powershell -Command "docker exec -it examples /bin/bash -c 'source .venv/bin/activate && python examples/main.py cli_cluster'"; \
fi

check-os:
@echo "{{os()}}"
@__import__('os').system("just containers check && docker exec -it examples /bin/bash -c 'source .venv/bin/activate && python examples/main.py cli_cluster'")
45 changes: 14 additions & 31 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,42 +1,25 @@
# Variables for versioning and configurations
python_version := "3.10"
llama_version := "llama3.2:1b"

set shell := [ "python3", "-c"]

[private]
default:
@just -l
default: version-check
@__import__('os').system("just -l")

[private]
version-check:
@import sys; major, minor = sys.version_info[:2]; \
assert (major, minor) >= (3, 7), "This script requires at least Python 3.7. Please link \"python3\" to Python 3.7 or higher and try again."

# Commands for running examples
mod example 'examples/example.just'

# Build, Start, Stop or Clean Up docker containers
# Build, Start, Stop, or Clean Up docker containers
mod containers 'docker/containers.just'

# Opens a Python shell inside the Docker container
interactive-shell:
if [[ {{os()}} == "linux" ]] || [[ {{os()}} == "macos" ]]; then \
echo "Opening an interactive Python shell in the Docker container..."; \
docker exec -it examples /bin/bash -c "source .venv/bin/activate && ptpython"; \
else \
powershell -Command "docker exec -it examples /bin/bash -c 'source .venv/bin/activate && ptpython'"; \
fi

# Builds and starts the entire environment
environment-up:
if [[ {{os()}} == "linux" ]] || [[ {{os()}} == "macos" ]]; then \
echo "Building and starting the entire environment..."; \
python ./docker/nexusctl.py create; \
python ./docker/nexusctl.py start; \
else \
powershell -Command "Write-Host 'Building and starting the entire environment...'; python ./docker/nexusctl.py create; python ./docker/nexusctl.py start"; \
fi
infra-up: version-check
@print("Building and starting the entire environment..."); __import__('os').system("just containers build"); __import__('os').system("just containers start")

# Shuts down and cleans up the environment
environment-down:
if [[ {{os()}} == "linux" ]] || [[ {{os()}} == "macos" ]]; then \
echo "Stopping and cleaning up the entire environment..."; \
python ./docker/nexusctl.py stop; \
python ./docker/nexusctl.py delete; \
else \
powershell -Command "Write-Host 'Stopping and cleaning up the entire environment...'; python ./docker/nexusctl.py stop; python ./docker/nexusctl.py delete"; \
fi
infra-down: version-check
@print("Stopping and cleaning up the entire environment..."); __import__('os').system("just containers stop"); __import__('os').system("just containers clean")

0 comments on commit b18ba0a

Please sign in to comment.