diff --git a/src/web/Ligare/web/scaffolding/templates/base/Makefile.j2 b/src/web/Ligare/web/scaffolding/templates/base/Makefile.j2 new file mode 100644 index 0000000..334475f --- /dev/null +++ b/src/web/Ligare/web/scaffolding/templates/base/Makefile.j2 @@ -0,0 +1,91 @@ +# The name of the scaffolded application +APPLICATION_NAME = {{application.module_name}} + +# Install an "editable" package with `pip install -e` +INSTALL_EDITABLE ?= true + +# Install development packages like `pytest` +INSTALL_EXTRAS ?= true + +# The default Python venv directory +VENV ?= .venv + +# The default Python version +PYTHON_VERSION ?= 3.10 + +# The path to Ligare on the local filesystem. Optional. +LIGARE_PATH ?= + +# The location of the installed scaffolded application +APPLICATION_INSTALL_PATH = $(VENV)/lib/python$(PYTHON_VERSION)/site-packages/$(APPLICATION_NAME)-*dist-info* + +# The command to activate the Python venv +ACTIVATE_VENV := . '$(VENV)/bin/activate' + +# The venv install target +$(VENV) : + test -d '$(VENV)' || env python$(PYTHON_VERSION) -m venv '$(VENV)' + $(ACTIVATE_VENV) && \ + pip install -U pip + +# If `LIGARE_PATH` is set, this will alter the installed +# application's dependencies to use the local Ligare sources +# rather than the packages sources from PyPI. +ifneq ($(LIGARE_PATH),) + ifeq ($(realpath $(LIGARE_PATH)),) + $(error The repository path `$(LIGARE_PATH)` does not exist) + endif + LIGARE_INSTALL_PATH = $(VENV)/lib/python$(PYTHON_VERSION)/site-packages/Ligare +# The Ligare install target +$(LIGARE_INSTALL_PATH) : $(VENV) $(APPLICATION_INSTALL_PATH) + cd '$(LIGARE_INSTALL_PATH)' && \ + for d in */; do \ + rm -rf "$$d" && \ + ln -s "$(LIGARE_PATH)/src/$$d/Ligare/$$d"; \ + done +endif + +# The `pip install` command. Changes depending on +# the values of INSTALL_EDITABLE and INSTALL_EXTRAS. +# The ` #` at the end of the lines are intentional +# in order to add a space at the end of the variable's value. +PIP_INSTALL_COMMAND := pip install +ifeq ($(INSTALL_EDITABLE),true) + PIP_INSTALL_COMMAND += -e # +endif +ifeq ($(INSTALL_EXTRAS),true) + PIP_INSTALL_COMMAND += .[dev] # +else + PIP_INSTALL_COMMAND += . # +endif +# The application install target +$(APPLICATION_INSTALL_PATH) : $(VENV) + $(ACTIVATE_VENV) && \ + $(PIP_INSTALL_COMMAND); + + @echo '\n{{application.module_name}} is installed. Ativate your venv with `$(ACTIVATE_VENV)`'; + +.PHONY: run +run : + $(ACTIVATE_VENV) && \ + python -m {{application.module_name}} + +clean-build : + find . -type d \ + \( \ + -path ./$(VENV) \ + -o -path ./.git \ + \) -prune -false \ + -o \( \ + -name build \ + -o -name dist \ + -o -name __pycache__ \ + -o -name \*.egg-info \ + -o -name .pytest-cache \ + \) -prune -exec rm -rf {} + + +.PHONY: clean clean-build +clean : clean-build + rm -rf '$(VENV)'; + + @echo '\nDeactivate your venv with `deactivate`'; diff --git a/src/web/Ligare/web/scaffolding/templates/base/README.md.j2 b/src/web/Ligare/web/scaffolding/templates/base/README.md.j2 index de361f1..1636a06 100644 --- a/src/web/Ligare/web/scaffolding/templates/base/README.md.j2 +++ b/src/web/Ligare/web/scaffolding/templates/base/README.md.j2 @@ -2,6 +2,18 @@ ## Usage +### Get started automatically + +1. Run `make` in the project root + +Optionally, you can define the following envvars: + +* `INSTALL_EDITABLE` - defaults to `true` - if `true`, install an editable package with `pip install -e` +* `INSTALL_EXTRAS` - defaults to `true` - if `true`, install development tools like `pytest` +* `LIGARE_PATH` set this to the path of your local Ligare sources in order to use those instead of the sources from PyPI + +### Get started manually + 1. Create a virtual environment `python3 -m venv .venv` 2. Activate the virtual environment `. .venv/bin/activate` 3. Install dependencies `pip install .`