Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
77 lines (59 loc) · 2.88 KB
/
Copy pathMakefile
File metadata and controls
77 lines (59 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
.SILENT: ; # No need for @
.ONESHELL: ; # Single shell for a target (required to properly use all of our local variables)
.EXPORT_ALL_VARIABLES: ; # Send all vars to shell
.DEFAULT: help # Running Make without target will run the help target
.PHONY: help init clean all import export diff dump reload-data tables .create-db wheel
# Run commands via `uv run`, which sets up the virtual environment
# and dependencies on demand, so `uv sync` can be skipped.
PYTHON = uv run
# SQLite database file used for all operations.
# Override on the make command line: make <target> DB=my.db
DB = pp.db
# $(DATA) is simply the database file ($(DB)): reload-data removes it
# first so that `make all` recreates it and re-imports everything
# from scratch.
DATA = $(DB)
# Source Portfolio Performance XML file (the "XML with 'id'
# attributes" variant, as produced by PP >= 0.70.3). export writes to $(XML).out.
# Override on the make command line: make <target> XML=my.xml
XML = kommer.xml
# Output XML file produced by the `export` target.
OUT = $(XML).out
help: ## Show Help
grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
echo
echo "Configurable files (override on the command line or as env vars, e.g. 'make import DB=my.db XML=my.xml')"
echo " DB database file (default: $(DB))"
echo " XML source PP XML file (default: $(XML)); export writes to $(XML).out"
all: init import ## Create the database and import the XML data
init: tables ## Create an empty database with all the needed tables ($(DB))
# Alias for init.
tables: .create-db
reload-data: ## Recreate the database ($(DATA)) and re-import the XML data
rm -f $(DATA)
make all
import: ## Import $(XML) into the database ($(DB))
$(PYTHON) ppdb_import.py $(XML) $(DB)
export: ## Export the database ($(DB)) to a new XML file ($(OUT))
$(PYTHON) ppdb_export.py $(DB) $(OUT)
diff: ## Verify round-trip: diff original XML ($(XML)) vs exported ($(OUT))
diff -u $(XML) $(OUT)
# Build a Python wheel in dist/ for easy distribution and install.
# (Note: `uv build` runs in an isolated build environment, so it is
# called directly instead of via `$(PYTHON)`.)
wheel: ## Build a Python wheel (dist/ppdb-*.whl)
uv build --wheel
# Prerequisite of init: actually runs the schema creation,
# guarded by the .create-db stamp file.
.create-db:
$(PYTHON) ppdb_init.py --recreate $(DB)
touch $@
clean: ## Remove the database ($(DB)), the build stamp and build artifacts
-rm -f .create-db $(DB)
-rm -rf dist build ppdb.egg-info ppxml2db.egg-info
# It appears that sqlite3 dump CSV by default with CRLF line
# endings. Use ".separator" directive to override that.
dump: ## Dump all tables of $(DB) to CSV files (<table>.csv)
for db in `echo ".tables" | sqlite3 $(DB)`; do \
echo -e ".mode csv\n.separator , \\\n\n select * from $$db;" | sqlite3 $(DB) >$$db.csv; \
done