Skip to content

Commit 2f05aff

Browse files
committed
DEVELOPMENT EXPERIMENT: Add justfile as another build system.
1 parent 6f3dc85 commit 2f05aff

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

justfile

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# =============================================================================
2+
# justfile: A makefile-like build script -- parse_type
3+
# =============================================================================
4+
# REQUIRES: cargo install just
5+
# PLATFORMS: Windows, Linux, macOS, ...
6+
# USAGE:
7+
# just --list
8+
# just <TARGET>
9+
# just <TARGET> <PARAM_VALUE>
10+
#
11+
# SEE ALSO:
12+
# * https://github.com/casey/just
13+
# =============================================================================
14+
15+
# -- OPTION: Load environment-variables from "$HERE/.env" file (if exists)
16+
set dotenv-load
17+
18+
# -----------------------------------------------------------------------------
19+
# CONFIG:
20+
# -----------------------------------------------------------------------------
21+
HERE := justfile_directory()
22+
PIP_INSTALL_OPTIONS := env_var_or_default("PIP_INSTALL_OPTIONS", "--quiet")
23+
PYTEST_OPTIONS := env_var_or_default("PYTEST_OPTIONS", "")
24+
25+
26+
# -----------------------------------------------------------------------------
27+
# BUILD RECIPES / TARGETS:
28+
# -----------------------------------------------------------------------------
29+
30+
# DEFAULT-TARGET: Ensure that packages are installed and runs tests.
31+
default: (_ensure-install-packages "testing") test
32+
33+
# PART=all, testing, ...
34+
install-packages PART="all":
35+
@echo "INSTALL-PACKAGES: {{PART}} ..."
36+
pip install {{PIP_INSTALL_OPTIONS}} -r py.requirements/{{PART}}.txt
37+
@touch "{{HERE}}/.done.install-packages.{{PART}}"
38+
39+
# ENSURE: Python packages are installed.
40+
_ensure-install-packages PART="all":
41+
#!/usr/bin/env python3
42+
from subprocess import run
43+
from os import path
44+
if not path.exists("{{HERE}}/.done.install-packages.{{PART}}"):
45+
run("just install-packages {{PART}}", shell=True)
46+
47+
# -- SIMILAR: This solution requires a Bourne-like shell (may not work on: Windows).
48+
# _ensure-install-packages PART="testing":
49+
# @test -e "{{HERE}}/.done.install-packages.{{PART}}" || just install-packages {{PART}}
50+
51+
# Run tests.
52+
test *TESTS:
53+
python -m pytest {{PYTEST_OPTIONS}} {{TESTS}}
54+
55+
# Determine test coverage by running the tests.
56+
coverage:
57+
coverage run -m pytest
58+
coverage combine
59+
coverage report
60+
coverage html
61+
62+
# Cleanup most parts (but leave PRECIOUS parts).
63+
cleanup: (_ensure-install-packages "all")
64+
invoke cleanup
65+
66+
# Cleanup everything.
67+
cleanup-all:
68+
invoke cleanup.all

0 commit comments

Comments
 (0)