From b18ba0aa5e5d335b280b18f81a8cbb90da6e090b Mon Sep 17 00:00:00 2001 From: Michal Turcan Date: Wed, 30 Oct 2024 12:52:42 +0100 Subject: [PATCH] use python shell in just --- docker/containers.just | 45 +++++++++--------------------------------- examples/example.just | 39 ++++++++++++------------------------ justfile | 45 +++++++++++++----------------------------- 3 files changed, 36 insertions(+), 93 deletions(-) diff --git a/docker/containers.just b/docker/containers.just index 2c7607a..790470e 100644 --- a/docker/containers.just +++ b/docker/containers.just @@ -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") diff --git a/examples/example.just b/examples/example.just index dd83d34..afcfb93 100644 --- a/examples/example.just +++ b/examples/example.just @@ -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()}}" \ No newline at end of file + @__import__('os').system("just containers check && docker exec -it examples /bin/bash -c 'source .venv/bin/activate && python examples/main.py cli_cluster'") diff --git a/justfile b/justfile index e3e2bb9..c181718 100644 --- a/justfile +++ b/justfile @@ -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")