Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Makefile to scaffolded applications #136

Merged
merged 7 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
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
91 changes: 91 additions & 0 deletions src/web/Ligare/web/scaffolding/templates/base/Makefile.j2
Original file line number Diff line number Diff line change
@@ -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`';
12 changes: 12 additions & 0 deletions src/web/Ligare/web/scaffolding/templates/base/README.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 .`
Expand Down
Loading