Skip to content
Open
Changes from all 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
85 changes: 74 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,46 +1,109 @@
COMPOSE ?= $(shell \
if command -v docker >/dev/null 2>&1; then \
echo "docker compose"; \
elif command -v podman >/dev/null 2>&1; then \
echo "podman compose"; \
else \
echo "docker compose"; \
fi)
# Detect OS
ifeq ($(OS),Windows_NT)
# Windows specific commands
SEP = \
MKDIR = if not exist $(subst /,\,$(1)) mkdir $(subst /,\,$(1))
CP = copy /Y
RM = del /f /q
RMDIR = rmdir /s /q
DETECT_DOCKER = $(shell where docker 2>nul)
DETECT_PODMAN = $(shell where podman 2>nul)
else
SEP = /
MKDIR = mkdir -p
CP = cp
RM = rm -f
RMDIR = rm -rf
DETECT_DOCKER = $(shell command -v docker 2>/dev/null)
DETECT_PODMAN = $(shell command -v podman 2>/dev/null)
endif

# Helper function to create directory (Windows-friendly)
define make_dir
$(call MKDIR,$(1))
endef

# Determine compose backend
ifneq ($(DETECT_DOCKER),)
COMPOSE = docker compose
HAVE_COMPOSE = 1
else ifneq ($(DETECT_PODMAN),)
COMPOSE = podman compose
HAVE_COMPOSE = 1
else
COMPOSE = docker compose
HAVE_COMPOSE = 0
endif

# Local run command (fallback when no Docker/Podman)
LOCAL_RUN_CMD = python -m jupyter notebook --port=8888 --ip=0.0.0.0 --no-browser --notebook-dir=./notebooks

.PHONY: run run-build stop clean setup-local badges

run:
ifeq ($(HAVE_COMPOSE),1)
@echo "Using compose backend: $(COMPOSE)"
@echo "Pulling prebuilt image (if available)..."
@$(COMPOSE) pull || true
-@$(COMPOSE) pull
$(COMPOSE) up -d --no-build
@echo ""
@echo "🔥 TorchCode is running!"
@echo "🔥 TorchCode is running in containers!"
@echo " Open http://localhost:8888"
@echo ""
else
@echo "Docker/Podman not found, falling back to local mode."
@echo "Starting Jupyter Notebook locally..."
@echo "Make sure you have installed dependencies: pip install jupyter notebook"
@echo "If notebooks are not ready, run 'make setup-local' first."
@echo ""
$(LOCAL_RUN_CMD)
endif

run-build:
ifeq ($(HAVE_COMPOSE),1)
@echo "Using compose backend: $(COMPOSE)"
$(COMPOSE) up --build -d
@echo ""
@echo "🔥 TorchCode is running (local build)!"
@echo " Open http://localhost:8888"
@echo ""
else
@echo "Docker/Podman not found, falling back to local mode."
@echo "Starting Jupyter Notebook locally..."
@echo "Make sure you have installed dependencies: pip install jupyter notebook"
@echo "If notebooks are not ready, run 'make setup-local' first."
@echo ""
$(LOCAL_RUN_CMD)
endif

stop:
ifeq ($(HAVE_COMPOSE),1)
@echo "Using compose backend: $(COMPOSE)"
$(COMPOSE) down
else
@echo "No container backend detected. Nothing to stop."
@echo "If you have a local notebook running, press Ctrl+C in its terminal to stop it."
endif

clean:
ifeq ($(HAVE_COMPOSE),1)
@echo "Using compose backend: $(COMPOSE)"
$(COMPOSE) down -v
rm -f data/progress.json
endif
-$(RM) data/progress.json

setup-local:
ifeq ($(OS),Windows_NT)
@if not exist "notebooks\_original_templates" mkdir "notebooks\_original_templates"
@for %%f in (templates\*.ipynb) do copy /Y "%%f" "notebooks\_original_templates\"
@for %%f in (templates\*.ipynb) do copy /Y "%%f" "notebooks\"
@for %%f in (solutions\*.ipynb) do copy /Y "%%f" "notebooks\"
else
@mkdir -p notebooks/_original_templates
@cp templates/*.ipynb notebooks/_original_templates/
@cp templates/*.ipynb notebooks/
@cp solutions/*.ipynb notebooks/
endif
@echo "✅ Local notebooks ready in ./notebooks/"

badges:
Expand Down
Loading