Skip to content

Commit a86591b

Browse files
authored
Simplify GNU Make setup (#69)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 815d0dd commit a86591b

File tree

81 files changed

+121
-154
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+121
-154
lines changed

Makefile

Lines changed: 6 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
.DEFAULT_GOAL := all
2+
13
JSONSCHEMA ?= jsonschema
24
SHELLCHECK ?= shellcheck
3-
JQ ?= jq
4-
PYTHON ?= python3
5-
CURL ?= curl
65
TAR ?= tar
76
ZIP ?= zip
87
UNZIP ?= unzip
@@ -14,91 +13,15 @@ RMRF ?= rm -rf
1413
SCHEMAS = $(shell find schemas/ -type f -name '*.json')
1514
TESTS = $(shell find test/ -type f -name '*.json')
1615

16+
# TODO: Add a version property to `jsonschema.json`
1717
VERSION = $(shell tr -d '\n\r' < VERSION)
1818

19-
GENERATED = \
20-
schemas/iso/currency/2015/alpha-code.json \
21-
schemas/iso/currency/2015/alpha-currency.json \
22-
schemas/iso/currency/2015/alpha-fund.json \
23-
schemas/iso/currency/2015/alpha-precious-metal.json \
24-
schemas/iso/currency/2015/alpha-test.json \
25-
schemas/iso/currency/2015/alpha-unknown.json \
26-
schemas/iso/currency/2015/numeric-code-additional.json \
27-
schemas/iso/currency/2015/numeric-code.json \
28-
schemas/iso/currency/2015/numeric-currency.json \
29-
schemas/iso/currency/2015/numeric-fund.json \
30-
schemas/iso/currency/2015/numeric-precious-metal.json \
31-
schemas/iso/currency/2015/numeric-test.json \
32-
schemas/iso/currency/2015/numeric-unknown.json \
33-
schemas/iso/currency/2015/historical/alpha-code.json \
34-
schemas/iso/currency/2015/historical/alpha-currency.json \
35-
schemas/iso/currency/2015/historical/numeric-code.json \
36-
schemas/iso/currency/2015/historical/numeric-currency.json \
37-
schemas/xbrl/utr/area-item-type-normative.json \
38-
schemas/xbrl/utr/area-item-type.json \
39-
schemas/xbrl/utr/duration-item-type-normative.json \
40-
schemas/xbrl/utr/duration-item-type.json \
41-
schemas/xbrl/utr/electric-charge-item-type-normative.json \
42-
schemas/xbrl/utr/electric-charge-item-type.json \
43-
schemas/xbrl/utr/electric-current-item-type-normative.json \
44-
schemas/xbrl/utr/electric-current-item-type.json \
45-
schemas/xbrl/utr/energy-item-type-normative.json \
46-
schemas/xbrl/utr/energy-item-type.json \
47-
schemas/xbrl/utr/energy-per-monetary-item-type-normative.json \
48-
schemas/xbrl/utr/energy-per-monetary-item-type.json \
49-
schemas/xbrl/utr/flow-item-type-normative.json \
50-
schemas/xbrl/utr/flow-item-type.json \
51-
schemas/xbrl/utr/force-item-type-normative.json \
52-
schemas/xbrl/utr/force-item-type.json \
53-
schemas/xbrl/utr/frequency-item-type-normative.json \
54-
schemas/xbrl/utr/frequency-item-type.json \
55-
schemas/xbrl/utr/ghg-emissions-item-type-normative.json \
56-
schemas/xbrl/utr/ghg-emissions-item-type.json \
57-
schemas/xbrl/utr/ghg-emissions-per-monetary-item-type-normative.json \
58-
schemas/xbrl/utr/ghg-emissions-per-monetary-item-type.json \
59-
schemas/xbrl/utr/length-item-type-normative.json \
60-
schemas/xbrl/utr/length-item-type.json \
61-
schemas/xbrl/utr/mass-item-type-normative.json \
62-
schemas/xbrl/utr/mass-item-type.json \
63-
schemas/xbrl/utr/memory-item-type-normative.json \
64-
schemas/xbrl/utr/memory-item-type.json \
65-
schemas/xbrl/utr/monetary-item-type-normative.json \
66-
schemas/xbrl/utr/monetary-item-type.json \
67-
schemas/xbrl/utr/per-share-item-type-normative.json \
68-
schemas/xbrl/utr/per-share-item-type.json \
69-
schemas/xbrl/utr/per-unit-item-type-normative.json \
70-
schemas/xbrl/utr/per-unit-item-type.json \
71-
schemas/xbrl/utr/plane-angle-item-type-normative.json \
72-
schemas/xbrl/utr/plane-angle-item-type.json \
73-
schemas/xbrl/utr/power-item-type-normative.json \
74-
schemas/xbrl/utr/power-item-type.json \
75-
schemas/xbrl/utr/pressure-item-type-normative.json \
76-
schemas/xbrl/utr/pressure-item-type.json \
77-
schemas/xbrl/utr/pure-item-type-normative.json \
78-
schemas/xbrl/utr/pure-item-type.json \
79-
schemas/xbrl/utr/shares-item-type-normative.json \
80-
schemas/xbrl/utr/shares-item-type.json \
81-
schemas/xbrl/utr/temperature-item-type-normative.json \
82-
schemas/xbrl/utr/temperature-item-type.json \
83-
schemas/xbrl/utr/voltage-item-type-normative.json \
84-
schemas/xbrl/utr/voltage-item-type.json \
85-
schemas/xbrl/utr/volume-item-type-normative.json \
86-
schemas/xbrl/utr/volume-item-type.json \
87-
schemas/xbrl/utr/volume-per-monetary-item-type-normative.json \
88-
schemas/xbrl/utr/volume-per-monetary-item-type.json \
89-
schemas/iso/country/2020/alpha-2.json \
90-
schemas/iso/country/2020/alpha-3.json \
91-
schemas/iso/country/2020/numeric.json \
92-
schemas/iso/language/2023/set-1.json \
93-
schemas/iso/language/2023/set-2-bibliographic.json \
94-
schemas/iso/language/2023/set-2-terminologic.json \
95-
schemas/iso/language/2023/set-3.json \
96-
schemas/iso/language/2023/set-5.json
19+
include generated.mk
9720

9821
# TODO: Make `jsonschema fmt` automatically detect test files
9922
all: common test
100-
$(JSONSCHEMA) fmt schemas meta --verbose
101-
$(JSONSCHEMA) fmt test --verbose --default-dialect "https://json-schema.org/draft/2020-12/schema"
23+
$(JSONSCHEMA) fmt schemas meta
24+
$(JSONSCHEMA) fmt test --default-dialect "https://json-schema.org/draft/2020-12/schema"
10225

10326
.PHONY: common
10427
common: $(GENERATED)
@@ -121,76 +44,6 @@ lint: common
12144
test:
12245
$(JSONSCHEMA) test ./test
12346

124-
build/iso/currency/list-%.json: \
125-
scripts/xml2json.py \
126-
vendor/data/iso/currency/list-%.xml
127-
$(PYTHON) $< $(word 2,$^) $@
128-
schemas/iso/currency/2015/historical/alpha-code.json: \
129-
build/iso/currency/list-three.json \
130-
templates/iso/currency/2015/historical/alpha-code.jq
131-
$(MKDIRP) $(dir $@)
132-
$(JQ) --from-file $(word 2,$^) $< > $@
133-
$(JSONSCHEMA) fmt $@
134-
schemas/iso/currency/2015/historical/alpha-currency.json: \
135-
build/iso/currency/list-three.json \
136-
templates/iso/currency/2015/historical/alpha-currency.jq
137-
$(MKDIRP) $(dir $@)
138-
$(JQ) --from-file $(word 2,$^) $< > $@
139-
$(JSONSCHEMA) fmt $@
140-
schemas/iso/currency/2015/historical/numeric-code.json: \
141-
build/iso/currency/list-three.json \
142-
templates/iso/currency/2015/historical/numeric-code.jq
143-
$(MKDIRP) $(dir $@)
144-
$(JQ) --from-file $(word 2,$^) $< > $@
145-
$(JSONSCHEMA) fmt $@
146-
schemas/iso/currency/2015/historical/numeric-currency.json: \
147-
build/iso/currency/list-three.json \
148-
templates/iso/currency/2015/historical/numeric-currency.jq
149-
$(MKDIRP) $(dir $@)
150-
$(JQ) --from-file $(word 2,$^) $< > $@
151-
$(JSONSCHEMA) fmt $@
152-
schemas/iso/currency/2015/%.json: \
153-
build/iso/currency/list-one.json \
154-
templates/iso/currency/2015/%.jq
155-
$(MKDIRP) $(dir $@)
156-
$(JQ) --from-file $(word 2,$^) $< > $@
157-
$(JSONSCHEMA) fmt $@
158-
159-
build/xbrl/utr/%.json: scripts/xml2json.py vendor/data/xbrl/utr/%.xml
160-
$(PYTHON) $< $(word 2,$^) $@
161-
schemas/xbrl/utr/%.json: build/xbrl/utr/utr.json templates/xbrl/utr/%.jq
162-
$(MKDIRP) $(dir $@)
163-
$(JQ) --from-file $(word 2,$^) $< > $@
164-
$(JSONSCHEMA) fmt $@
165-
166-
schemas/iso/country/2020/%.json: \
167-
vendor/iso3166/all/all.json \
168-
templates/iso/country/2020/%.jq
169-
$(MKDIRP) $(dir $@)
170-
$(JQ) --from-file $(word 2,$^) $< > $@
171-
$(JSONSCHEMA) fmt $@
172-
173-
build/iso/language/iso-639-2.json: \
174-
vendor/data/iso/language/ISO-639-2_utf-8.txt \
175-
scripts/csv2json.py
176-
$(PYTHON) $(word 2,$^) --delimiter '|' --encoding utf-8-sig --no-header \
177-
--field-names "part2b,part2t,part1,name,name_french" $< $@
178-
build/iso/language/iso-639-3.json: \
179-
vendor/data/iso/language/iso-639-3_Code_Tables/iso-639-3_Code_Tables_20251015/iso-639-3.tab \
180-
scripts/csv2json.py
181-
$(PYTHON) $(word 2,$^) --tab $< $@
182-
build/iso/language/enriched.json: \
183-
build/iso/language/iso-639-2.json \
184-
build/iso/language/iso-639-3.json \
185-
scripts/iso-language-enrich.jq
186-
$(JQ) --slurpfile iso2 $< --slurpfile iso3 $(word 2,$^) -n -f $(word 3,$^) > $@
187-
schemas/iso/language/2023/%.json: \
188-
build/iso/language/enriched.json \
189-
templates/iso/language/2023/%.jq
190-
$(MKDIRP) $(dir $@)
191-
$(JQ) --from-file $(word 2,$^) $< > $@
192-
$(JSONSCHEMA) fmt $@
193-
19447
# TODO: Add a `jsonschema pkg` command instead
19548
.PHONY: dist
19649
dist:

generated.mk

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
PYTHON ?= python3
2+
JQ ?= jq
3+
4+
define MAKE_SCHEMA
5+
schemas/$1.json: templates/schemas/$1.jq $2.json
6+
$(MKDIRP) $$(dir $$@)
7+
$(JQ) --from-file $$< $$(word 2,$$^) > $$@
8+
$(JSONSCHEMA) fmt $$@
9+
GENERATED += schemas/$1.json
10+
endef
11+
12+
build/iso/currency/list-%.json: \
13+
scripts/xml2json.py \
14+
vendor/data/iso/currency/list-%.xml
15+
$(PYTHON) $< $(word 2,$^) $@
16+
17+
$(eval $(call MAKE_SCHEMA,iso/currency/2015/historical/alpha-code,build/iso/currency/list-three))
18+
$(eval $(call MAKE_SCHEMA,iso/currency/2015/historical/alpha-currency,build/iso/currency/list-three))
19+
$(eval $(call MAKE_SCHEMA,iso/currency/2015/historical/numeric-code,build/iso/currency/list-three))
20+
$(eval $(call MAKE_SCHEMA,iso/currency/2015/historical/numeric-currency,build/iso/currency/list-three))
21+
$(eval $(call MAKE_SCHEMA,iso/currency/2015/alpha-code,build/iso/currency/list-one))
22+
$(eval $(call MAKE_SCHEMA,iso/currency/2015/alpha-currency,build/iso/currency/list-one))
23+
$(eval $(call MAKE_SCHEMA,iso/currency/2015/alpha-fund,build/iso/currency/list-one))
24+
$(eval $(call MAKE_SCHEMA,iso/currency/2015/alpha-precious-metal,build/iso/currency/list-one))
25+
$(eval $(call MAKE_SCHEMA,iso/currency/2015/alpha-test,build/iso/currency/list-one))
26+
$(eval $(call MAKE_SCHEMA,iso/currency/2015/alpha-unknown,build/iso/currency/list-one))
27+
$(eval $(call MAKE_SCHEMA,iso/currency/2015/numeric-code-additional,build/iso/currency/list-one))
28+
$(eval $(call MAKE_SCHEMA,iso/currency/2015/numeric-code,build/iso/currency/list-one))
29+
$(eval $(call MAKE_SCHEMA,iso/currency/2015/numeric-currency,build/iso/currency/list-one))
30+
$(eval $(call MAKE_SCHEMA,iso/currency/2015/numeric-fund,build/iso/currency/list-one))
31+
$(eval $(call MAKE_SCHEMA,iso/currency/2015/numeric-precious-metal,build/iso/currency/list-one))
32+
$(eval $(call MAKE_SCHEMA,iso/currency/2015/numeric-test,build/iso/currency/list-one))
33+
$(eval $(call MAKE_SCHEMA,iso/currency/2015/numeric-unknown,build/iso/currency/list-one))
34+
35+
build/xbrl/utr/%.json: scripts/xml2json.py vendor/data/xbrl/utr/%.xml
36+
$(PYTHON) $< $(word 2,$^) $@
37+
38+
$(eval $(call MAKE_SCHEMA,xbrl/utr/area-item-type-normative,build/xbrl/utr/utr))
39+
$(eval $(call MAKE_SCHEMA,xbrl/utr/area-item-type,build/xbrl/utr/utr))
40+
$(eval $(call MAKE_SCHEMA,xbrl/utr/duration-item-type-normative,build/xbrl/utr/utr))
41+
$(eval $(call MAKE_SCHEMA,xbrl/utr/duration-item-type,build/xbrl/utr/utr))
42+
$(eval $(call MAKE_SCHEMA,xbrl/utr/electric-charge-item-type-normative,build/xbrl/utr/utr))
43+
$(eval $(call MAKE_SCHEMA,xbrl/utr/electric-charge-item-type,build/xbrl/utr/utr))
44+
$(eval $(call MAKE_SCHEMA,xbrl/utr/electric-current-item-type-normative,build/xbrl/utr/utr))
45+
$(eval $(call MAKE_SCHEMA,xbrl/utr/electric-current-item-type,build/xbrl/utr/utr))
46+
$(eval $(call MAKE_SCHEMA,xbrl/utr/energy-item-type-normative,build/xbrl/utr/utr))
47+
$(eval $(call MAKE_SCHEMA,xbrl/utr/energy-item-type,build/xbrl/utr/utr))
48+
$(eval $(call MAKE_SCHEMA,xbrl/utr/energy-per-monetary-item-type-normative,build/xbrl/utr/utr))
49+
$(eval $(call MAKE_SCHEMA,xbrl/utr/energy-per-monetary-item-type,build/xbrl/utr/utr))
50+
$(eval $(call MAKE_SCHEMA,xbrl/utr/flow-item-type-normative,build/xbrl/utr/utr))
51+
$(eval $(call MAKE_SCHEMA,xbrl/utr/flow-item-type,build/xbrl/utr/utr))
52+
$(eval $(call MAKE_SCHEMA,xbrl/utr/force-item-type-normative,build/xbrl/utr/utr))
53+
$(eval $(call MAKE_SCHEMA,xbrl/utr/force-item-type,build/xbrl/utr/utr))
54+
$(eval $(call MAKE_SCHEMA,xbrl/utr/frequency-item-type-normative,build/xbrl/utr/utr))
55+
$(eval $(call MAKE_SCHEMA,xbrl/utr/frequency-item-type,build/xbrl/utr/utr))
56+
$(eval $(call MAKE_SCHEMA,xbrl/utr/ghg-emissions-item-type-normative,build/xbrl/utr/utr))
57+
$(eval $(call MAKE_SCHEMA,xbrl/utr/ghg-emissions-item-type,build/xbrl/utr/utr))
58+
$(eval $(call MAKE_SCHEMA,xbrl/utr/ghg-emissions-per-monetary-item-type-normative,build/xbrl/utr/utr))
59+
$(eval $(call MAKE_SCHEMA,xbrl/utr/ghg-emissions-per-monetary-item-type,build/xbrl/utr/utr))
60+
$(eval $(call MAKE_SCHEMA,xbrl/utr/length-item-type-normative,build/xbrl/utr/utr))
61+
$(eval $(call MAKE_SCHEMA,xbrl/utr/length-item-type,build/xbrl/utr/utr))
62+
$(eval $(call MAKE_SCHEMA,xbrl/utr/mass-item-type-normative,build/xbrl/utr/utr))
63+
$(eval $(call MAKE_SCHEMA,xbrl/utr/mass-item-type,build/xbrl/utr/utr))
64+
$(eval $(call MAKE_SCHEMA,xbrl/utr/memory-item-type-normative,build/xbrl/utr/utr))
65+
$(eval $(call MAKE_SCHEMA,xbrl/utr/memory-item-type,build/xbrl/utr/utr))
66+
$(eval $(call MAKE_SCHEMA,xbrl/utr/monetary-item-type-normative,build/xbrl/utr/utr))
67+
$(eval $(call MAKE_SCHEMA,xbrl/utr/monetary-item-type,build/xbrl/utr/utr))
68+
$(eval $(call MAKE_SCHEMA,xbrl/utr/per-share-item-type-normative,build/xbrl/utr/utr))
69+
$(eval $(call MAKE_SCHEMA,xbrl/utr/per-share-item-type,build/xbrl/utr/utr))
70+
$(eval $(call MAKE_SCHEMA,xbrl/utr/per-unit-item-type-normative,build/xbrl/utr/utr))
71+
$(eval $(call MAKE_SCHEMA,xbrl/utr/per-unit-item-type,build/xbrl/utr/utr))
72+
$(eval $(call MAKE_SCHEMA,xbrl/utr/plane-angle-item-type-normative,build/xbrl/utr/utr))
73+
$(eval $(call MAKE_SCHEMA,xbrl/utr/plane-angle-item-type,build/xbrl/utr/utr))
74+
$(eval $(call MAKE_SCHEMA,xbrl/utr/power-item-type-normative,build/xbrl/utr/utr))
75+
$(eval $(call MAKE_SCHEMA,xbrl/utr/power-item-type,build/xbrl/utr/utr))
76+
$(eval $(call MAKE_SCHEMA,xbrl/utr/pressure-item-type-normative,build/xbrl/utr/utr))
77+
$(eval $(call MAKE_SCHEMA,xbrl/utr/pressure-item-type,build/xbrl/utr/utr))
78+
$(eval $(call MAKE_SCHEMA,xbrl/utr/pure-item-type-normative,build/xbrl/utr/utr))
79+
$(eval $(call MAKE_SCHEMA,xbrl/utr/pure-item-type,build/xbrl/utr/utr))
80+
$(eval $(call MAKE_SCHEMA,xbrl/utr/shares-item-type-normative,build/xbrl/utr/utr))
81+
$(eval $(call MAKE_SCHEMA,xbrl/utr/shares-item-type,build/xbrl/utr/utr))
82+
$(eval $(call MAKE_SCHEMA,xbrl/utr/temperature-item-type-normative,build/xbrl/utr/utr))
83+
$(eval $(call MAKE_SCHEMA,xbrl/utr/temperature-item-type,build/xbrl/utr/utr))
84+
$(eval $(call MAKE_SCHEMA,xbrl/utr/voltage-item-type-normative,build/xbrl/utr/utr))
85+
$(eval $(call MAKE_SCHEMA,xbrl/utr/voltage-item-type,build/xbrl/utr/utr))
86+
$(eval $(call MAKE_SCHEMA,xbrl/utr/volume-item-type-normative,build/xbrl/utr/utr))
87+
$(eval $(call MAKE_SCHEMA,xbrl/utr/volume-item-type,build/xbrl/utr/utr))
88+
$(eval $(call MAKE_SCHEMA,xbrl/utr/volume-per-monetary-item-type-normative,build/xbrl/utr/utr))
89+
$(eval $(call MAKE_SCHEMA,xbrl/utr/volume-per-monetary-item-type,build/xbrl/utr/utr))
90+
91+
$(eval $(call MAKE_SCHEMA,iso/country/2020/alpha-2,vendor/iso3166/all/all))
92+
$(eval $(call MAKE_SCHEMA,iso/country/2020/alpha-3,vendor/iso3166/all/all))
93+
$(eval $(call MAKE_SCHEMA,iso/country/2020/numeric,vendor/iso3166/all/all))
94+
95+
build/iso/language/iso-639-2.json: \
96+
vendor/data/iso/language/ISO-639-2_utf-8.txt \
97+
scripts/csv2json.py
98+
$(PYTHON) $(word 2,$^) --delimiter '|' --encoding utf-8-sig --no-header \
99+
--field-names "part2b,part2t,part1,name,name_french" $< $@
100+
build/iso/language/iso-639-3.json: \
101+
vendor/data/iso/language/iso-639-3_Code_Tables/iso-639-3_Code_Tables_20251015/iso-639-3.tab \
102+
scripts/csv2json.py
103+
$(PYTHON) $(word 2,$^) --tab $< $@
104+
build/iso/language/%.json: \
105+
build/iso/language/iso-639-2.json \
106+
build/iso/language/iso-639-3.json \
107+
templates/build/iso/language/%.jq
108+
$(JQ) --slurpfile iso2 $< --slurpfile iso3 $(word 2,$^) -n -f $(word 3,$^) > $@
109+
110+
$(eval $(call MAKE_SCHEMA,iso/language/2023/set-1,build/iso/language/enriched))
111+
$(eval $(call MAKE_SCHEMA,iso/language/2023/set-2-bibliographic,build/iso/language/enriched))
112+
$(eval $(call MAKE_SCHEMA,iso/language/2023/set-2-terminologic,build/iso/language/enriched))
113+
$(eval $(call MAKE_SCHEMA,iso/language/2023/set-3,build/iso/language/enriched))
114+
$(eval $(call MAKE_SCHEMA,iso/language/2023/set-5,build/iso/language/enriched))

scripts/quality-templates-xbrl-utr-mirror.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -o errexit
44
set -o nounset
55

66
UTR_DATA="$(pwd)/build/xbrl/utr/utr.json"
7-
TEMPLATES_DIR="$(pwd)/templates/xbrl/utr"
7+
TEMPLATES_DIR="$(pwd)/templates/schemas/xbrl/utr"
88
EXIT_CODE=0
99

1010
# Create temporary directory
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)