Skip to content

Commit

Permalink
Merge pull request #136 from uclahs-cds/aholmes-add-makefile-to-scaff…
Browse files Browse the repository at this point in the history
…older

Add `Makefile` to scaffolded applications
  • Loading branch information
aholmes authored Oct 17, 2024
2 parents 4cf2a40 + 4459d67 commit 447018c
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
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

0 comments on commit 447018c

Please sign in to comment.