|
1 |
| -POETRY_HOME := $(CURDIR)/.poetry |
2 |
| -POETRY := $(POETRY_HOME)/bin/poetry |
3 |
| - |
4 |
| -MIN_PYTHON_VERSION := 3.10 |
5 |
| - |
6 |
| -PYTHON_VERSIONS := 3.11 3.10 |
7 |
| - |
8 |
| -PYTHON := $(shell \ |
9 |
| - for ver in $(PYTHON_VERSIONS); do \ |
10 |
| - if command -v python$$ver >/dev/null 2>&1; then echo python$$ver; exit 0; fi; \ |
11 |
| - done \ |
12 |
| -) |
13 |
| - |
14 |
| -ifndef PYTHON |
15 |
| -$(error "Python version $(MIN_PYTHON_VERSION) or higher is required but not found.") |
16 |
| -endif |
17 |
| - |
18 |
| -.PHONY: pre-install |
19 |
| -pre-install: |
20 |
| - @echo "🐍 Using Python interpreter: $(PYTHON)" |
21 |
| - @echo "🐍 Checking if Python is installed" |
22 |
| - @command -v $(PYTHON) >/dev/null 2>&1 || { echo >&2 "$(PYTHON) is not installed. Aborting."; exit 1; } |
23 |
| - @echo "🐍 Checking Python version" |
24 |
| - @$(PYTHON) --version | grep -E "Python 3\.(1[0-9]|[2-9][0-9])" >/dev/null 2>&1 || { echo >&2 "Python $(MIN_PYTHON_VERSION) or higher is required. Aborting."; exit 1; } |
25 |
| - @echo "📦 Checking if Poetry is installed" |
26 |
| - @if ! command -v poetry >/dev/null 2>&1 || [ ! -d "$(POETRY_HOME)" ]; then \ |
27 |
| - echo "Poetry is not installed or POETRY_HOME does not exist. Installing Poetry."; \ |
28 |
| - curl -sSL https://install.python-poetry.org | POETRY_HOME=$(POETRY_HOME) $(PYTHON) -; \ |
29 |
| - fi |
30 |
| - @echo "📦 Configuring Poetry" |
31 |
| - @if [ -z "$$CONDA_PREFIX" ] && [ -z "$$VIRTUAL_ENV" ]; then \ |
32 |
| - echo "Configuring Poetry to create a virtual environment."; \ |
33 |
| - $(POETRY) config virtualenvs.in-project true; \ |
| 1 | +UV := uv |
| 2 | +PYTHON_VERSION := 3.11 |
| 3 | +UV_INSTALL_SCRIPT := https://astral.sh/uv/install.sh |
| 4 | + |
| 5 | +command_exists = $(shell command -v $(1) >/dev/null 2>&1 && echo true || echo false) |
| 6 | + |
| 7 | +define install_uv |
| 8 | + @echo "📦 uv is not installed. Installing uv..." |
| 9 | + @curl -LsSf $(UV_INSTALL_SCRIPT) | sh |
| 10 | +endef |
| 11 | + |
| 12 | +.PHONY: check-uv |
| 13 | +check-uv: ## Check and install uv if necessary |
| 14 | + @if command -v $(UV) >/dev/null 2>&1; then \ |
| 15 | + echo "📦 uv is already installed."; \ |
34 | 16 | else \
|
35 |
| - echo "Configuring Poetry to use the existing environment."; \ |
36 |
| - $(POETRY) config virtualenvs.create false; \ |
| 17 | + echo "📦 uv is not installed. Installing uv..."; \ |
| 18 | + curl -LsSf $(UV_INSTALL_SCRIPT) | sh; \ |
37 | 19 | fi
|
38 |
| - @echo "📦 Setting Poetry to use $(PYTHON)" |
39 |
| - @$(POETRY) env use $(PYTHON) || { echo "Failed to set Python version for Poetry. Aborting."; exit 1; } |
| 20 | + |
| 21 | +.PHONY: install-python |
| 22 | +install-python: check-uv ## Install Python with uv |
| 23 | + @echo "🐍 Installing Python $(PYTHON_VERSION) with uv" |
| 24 | + @$(UV) python install $(PYTHON_VERSION) |
| 25 | + @echo "🔧 Configuring Python $(PYTHON_VERSION) as the default Python version" |
| 26 | + @$(UV) python pin $(PYTHON_VERSION) |
40 | 27 |
|
41 | 28 | .PHONY: install
|
42 |
| -install: pre-install ## Install the poetry environment and install the pre-commit hooks |
43 |
| - @echo "📦 Installing dependencies with Poetry" |
44 |
| - @PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring $(POETRY) install --with core |
| 29 | +install: install-python ## Install core dependencies |
| 30 | + @echo "📦 Installing core dependencies with uv" |
| 31 | + @$(UV) sync --group core |
45 | 32 | @echo "🔧 Installing pre-commit hooks"
|
46 |
| - @$(POETRY) run pre-commit install |
| 33 | + @$(UV) run pre-commit install |
| 34 | + @echo "" |
| 35 | + @echo "🐳 Building nebula-frontend docker image. Do you want to continue? (y/n)" |
| 36 | + @read ans && [ $${ans:-N} = y ] || { echo "Build cancelled."; exit 1; } |
| 37 | + @docker build -t nebula-frontend -f nebula/frontend/Dockerfile . |
| 38 | + @echo "" |
| 39 | + @echo "🐳 Building nebula-core docker image. Do you want to continue? (y/n)" |
| 40 | + @read ans && [ $${ans:-N} = y ] || { echo "Build cancelled."; exit 1; } |
| 41 | + @docker build -t nebula-core . |
| 42 | + @echo "" |
47 | 43 | @$(MAKE) shell
|
48 | 44 |
|
49 | 45 | .PHONY: full-install
|
50 |
| -full-install: pre-install ## Install the poetry environment and install the pre-commit hooks |
51 |
| - @echo "📦 Installing dependencies with Poetry" |
52 |
| - @PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring $(POETRY) install --with core,docs,dev |
| 46 | +full-install: install-python ## Install all dependencies (core, docs) |
| 47 | + @echo "📦 Installing all dependencies with uv" |
| 48 | + @$(UV) sync --group core --group docs |
53 | 49 | @echo "🔧 Installing pre-commit hooks"
|
54 |
| - @$(POETRY) run pre-commit install |
| 50 | + @$(UV) run pre-commit install |
55 | 51 | @$(MAKE) shell
|
56 | 52 |
|
57 | 53 | .PHONY: shell
|
58 |
| -shell: ## Start a shell in the poetry environment |
59 |
| - @if [ -z "$$CONDA_PREFIX" ] && [ -z "$$VIRTUAL_ENV" ]; then \ |
60 |
| - echo "🐚 Activating virtual environment"; \ |
61 |
| - $(POETRY) shell; \ |
| 54 | +shell: ## Start a shell in the uv environment |
| 55 | + @echo "🐚 Starting a shell in the uv environment" |
| 56 | + @if [ -n "$$VIRTUAL_ENV" ]; then \ |
| 57 | + echo "🐚 Already in a virtual environment: $$VIRTUAL_ENV"; \ |
| 58 | + elif [ ! -d ".venv" ]; then \ |
| 59 | + echo "❌ .venv directory not found. Running 'make install' to create it..."; \ |
| 60 | + $(MAKE) install; \ |
62 | 61 | else \
|
63 |
| - echo "🐚 Conda or virtual environment detected, skipping Poetry shell activation"; \ |
| 62 | + echo "🐚 Run the following command to activate the virtual environment:"; \ |
| 63 | + echo ""; \ |
| 64 | + echo '[Linux/MacOS] \033[1;32msource .venv/bin/activate\033[0m'; \ |
| 65 | + echo '[Windows] \033[1;32m.venv\\bin\\activate\033[0m'; \ |
| 66 | + echo ""; \ |
| 67 | + echo "🚀 NEBULA is ready to use!"; \ |
| 68 | + echo "🚀 Created by \033[1;34mEnrique Tomás Martínez Beltrán\033[0m <\033[1;[email protected]\033[0m>"; \ |
64 | 69 | fi
|
65 | 70 |
|
66 |
| -.PHONY: sync |
67 |
| -sync: ## Sync the lock file |
68 |
| - @echo "📦 Syncing the lock file" |
69 |
| - @PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring $(POETRY) lock |
| 71 | +.PHONY: lock |
| 72 | +lock: ## Update the lock file |
| 73 | + @echo "🔒 This will update the lock file. Do you want to continue? (y/n)" |
| 74 | + @read ans && [ $${ans:-N} = y ] || { echo "Lock cancelled."; exit 1; } |
| 75 | + @echo "🔒 Locking dependencies..." |
| 76 | + @$(UV) lock |
70 | 77 |
|
71 | 78 | .PHONY: update-libs
|
72 |
| -update-libs: ## Update libraries to the latest version |
73 |
| - @echo "🔧 This will override the version of current libraries. Do you want to continue? (y/n)" |
| 79 | +update-libs: ## Update libraries to the latest version |
| 80 | + @echo "🔧 This will override the versions of current libraries. Do you want to continue? (y/n)" |
74 | 81 | @read ans && [ $${ans:-N} = y ] || { echo "Update cancelled."; exit 1; }
|
75 | 82 | @echo "📦 Updating libraries..."
|
76 |
| - @PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring $(POETRY) update |
| 83 | + @$(UV) update |
77 | 84 |
|
78 | 85 | .PHONY: check
|
79 |
| -check: ## Run code quality tools. |
| 86 | +check: ## Run code quality tools |
80 | 87 | @echo "🛠️ Running code quality checks"
|
81 |
| - @echo "🔍 Checking Poetry lock file consistency" |
82 |
| - @$(POETRY) check --lock |
| 88 | + @echo "🔍 Checking uv lock file consistency" |
| 89 | + @$(UV) sync |
83 | 90 | @echo "🚨 Linting code with pre-commit"
|
84 |
| - @$(POETRY) run pre-commit run -a |
| 91 | + @$(UV) run pre-commit run -a |
85 | 92 |
|
86 | 93 | .PHONY: check-plus
|
87 |
| -check-plus: check ## Run additional code quality tools. |
88 |
| - @echo "🔍 Checking code formatting with black |
89 |
| - @$(POETRY) run black --check ." |
| 94 | +check-plus: check ## Run additional code quality tools |
| 95 | + @echo "🔍 Checking code formatting with black" |
| 96 | + @$(UV) run black --check . |
90 | 97 | @echo "⚙️ Static type checking with mypy"
|
91 |
| - @$(POETRY) run mypy |
| 98 | + @$(UV) run mypy |
92 | 99 | @echo "🔎 Checking for obsolete dependencies"
|
93 |
| - @$(POETRY) run deptry . |
| 100 | + @$(UV) run deptry . |
94 | 101 |
|
95 | 102 | .PHONY: build
|
96 |
| -build: clean-build ## Build wheel file using poetry |
| 103 | +build: clean-build ## Build the wheel file |
97 | 104 | @echo "🚀 Creating wheel file"
|
98 |
| - @$(POETRY) build |
| 105 | + @$(UV) build |
99 | 106 |
|
100 | 107 | .PHONY: clean-build
|
101 |
| -clean-build: ## clean build artifacts |
| 108 | +clean-build: ## Clean build artifacts |
102 | 109 | @rm -rf dist
|
103 | 110 |
|
104 | 111 | .PHONY: publish
|
105 |
| -publish: ## publish a release to pypi. |
106 |
| - @echo "🚀 Publishing: Dry run." |
107 |
| - @$(POETRY) config pypi-token.pypi $(PYPI_TOKEN) |
108 |
| - @$(POETRY) publish --dry-run |
109 |
| - @echo "🚀 Publishing." |
110 |
| - @$(POETRY) publish |
| 112 | +publish: ## Publish a release to PyPI |
| 113 | + @echo "🚀 Publishing..."" |
| 114 | + @$(UV) publish --token $(PYPI_TOKEN) |
111 | 115 |
|
112 | 116 | .PHONY: build-and-publish
|
113 |
| -build-and-publish: build publish ## Build and publish. |
| 117 | +build-and-publish: build publish ## Build and publish the package |
114 | 118 |
|
115 | 119 | .PHONY: doc-test
|
116 |
| -doc-test: ## Test if documentation can be built without warnings or errors |
117 |
| - @$(POETRY) run mkdocs build -f docs/mkdocs.yml -d _build -s |
| 120 | +doc-test: ## Test if documentation can be built without errors |
| 121 | + @$(UV) run mkdocs build -f docs/mkdocs.yml -d _build -s |
118 | 122 |
|
119 | 123 | .PHONY: doc-build
|
120 |
| -doc-build: ## Build the documentation |
121 |
| - @$(POETRY) run mkdocs build -f docs/mkdocs.yml -d _build |
| 124 | +doc-build: ## Build the documentation |
| 125 | + @$(UV) run mkdocs build -f docs/mkdocs.yml -d _build |
122 | 126 |
|
123 | 127 | .PHONY: doc-serve
|
124 |
| -doc-serve: ## Build and serve the documentation |
125 |
| - @$(POETRY) run mkdocs serve -f docs/mkdocs.yml |
| 128 | +doc-serve: ## Serve the documentation locally |
| 129 | + @$(UV) run mkdocs serve -f docs/mkdocs.yml |
126 | 130 |
|
127 | 131 | .PHONY: format
|
128 |
| -format: ## Format code with black and isort |
| 132 | +format: ## Format code with black and isort |
129 | 133 | @echo "🎨 Formatting code"
|
130 |
| - @$(POETRY) run black . |
131 |
| - @$(POETRY) run isort . |
| 134 | + @$(UV) run black . |
| 135 | + @$(UV) run isort . |
132 | 136 |
|
133 | 137 | .PHONY: clean
|
134 |
| -clean: clean-build ## Clean up build artifacts and cache files |
| 138 | +clean: clean-build ## Clean up build artifacts and caches |
135 | 139 | @echo "🧹 Cleaning up build artifacts and caches"
|
136 | 140 | @rm -rf __pycache__ */__pycache__ .mypy_cache
|
137 | 141 |
|
138 | 142 | .PHONY: help
|
139 |
| -help: |
| 143 | +help: ## Display available commands |
140 | 144 | @echo "Available commands:"
|
141 | 145 | @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "💡 \033[36m%-20s\033[0m %s\n", $$1, $$2}'
|
142 | 146 |
|
|
0 commit comments