-
Notifications
You must be signed in to change notification settings - Fork 0
/
makerules.mk
170 lines (133 loc) · 4.55 KB
/
makerules.mk
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# deduce the repository
ifeq ($(REPOSITORY),)
REPOSITORY=$(shell basename -s .git `git config --get remote.origin.url`)
endif
ifeq ($(ENVIRONMENT),)
ENVIRONMENT=production
endif
ifeq ($(SOURCE_URL),)
SOURCE_URL=https://raw.githubusercontent.com/digital-land/
endif
ifeq ($(MAKERULES_URL),)
MAKERULES_URL=$(SOURCE_URL)makerules/main/
endif
ifeq ($(CONFIG_URL),)
CONFIG_URL=https://raw.githubusercontent.com/digital-land/config/main/
endif
ifeq ($(COLLECTION_NAME),)
COLLECTION_NAME=$(shell echo "$(REPOSITORY)"|sed 's/-collection$$//')
endif
ifeq ($(COLLECTION_DATASET_BUCKET_NAME),)
COLLECTION_DATASET_BUCKET_NAME=digital-land-$(ENVIRONMENT)-collection-dataset
endif
ifeq ($(HOISTED_COLLECTION_DATASET_BUCKET_NAME),)
HOISTED_COLLECTION_DATASET_BUCKET_NAME=digital-land-$(ENVIRONMENT)-collection-dataset-hoisted
endif
define dataset_url
'https://$(COLLECTION_DATASET_BUCKET_NAME).s3.eu-west-2.amazonaws.com/$(2)-collection/dataset/$(1).sqlite3'
endef
ifeq ($(VAR_DIR),)
VAR_DIR=var/
endif
ifeq ($(CACHE_DIR),)
CACHE_DIR=$(VAR_DIR)cache/
endif
.PHONY: \
makerules\
specification\
config\
init\
first-pass\
second-pass\
third-pass\
clobber\
clean\
commit-makerules\
prune
# keep intermediate files
.SECONDARY:
# don't keep targets build with an error
.DELETE_ON_ERROR:
# work in UTF-8
LANGUAGE := en_GB.UTF-8
LANG := C.UTF-8
# for consistent collation on different machines
LC_COLLATE := C.UTF-8
# current git branch
ifeq ($(BRANCH),)
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
endif
UNAME := $(shell uname)
# detect location of spatialite library, for linux add to path so python can pick up thhe files
ifndef SPATIALITE_EXTENSION
ifeq ($(UNAME), Linux)
SPATIALITE_EXTENSION="/usr/lib/x86_64-linux-gnu/mod_spatialite.so"
endif
ifeq ($(UNAME), Darwin)
SPATIALITE_EXTENSION="/usr/local/lib/mod_spatialite.dylib"
endif
endif
all:: first-pass second-pass third-pass
first-pass::
@:
# restart the make process to pick-up collected files
second-pass::
@:
third-pass::
@:
# initialise
init::
pip install --upgrade pip
ifneq (,$(wildcard requirements.txt))
pip3 install --upgrade -r requirements.txt
endif
ifneq (,$(wildcard setup.py))
pip install -e .$(PIP_INSTALL_PACKAGE)
endif
sqlite3 --version
submodules::
git submodule update --init --recursive --remote
# remove targets, force relink
clobber::
@:
# remove intermediate files
clean::
@:
# prune back to source code
prune::
rm -rf ./$(VAR_DIR) $(VALIDATION_DIR)
# update makerules from source
makerules::
curl -qfsL '$(MAKERULES_URL)makerules.mk' > makerules/makerules.mk
ifeq (,$(wildcard ./makerules/specification.mk))
# update local copies of specification files
specification::
@mkdir -p specification/
curl -qfsL '$(SOURCE_URL)/specification/main/specification/attribution.csv' > specification/attribution.csv
curl -qfsL '$(SOURCE_URL)/specification/main/specification/licence.csv' > specification/licence.csv
curl -qfsL '$(SOURCE_URL)/specification/main/specification/typology.csv' > specification/typology.csv
curl -qfsL '$(SOURCE_URL)/specification/main/specification/theme.csv' > specification/theme.csv
curl -qfsL '$(SOURCE_URL)/specification/main/specification/collection.csv' > specification/collection.csv
curl -qfsL '$(SOURCE_URL)/specification/main/specification/dataset.csv' > specification/dataset.csv
curl -qfsL '$(SOURCE_URL)/specification/main/specification/dataset-field.csv' > specification/dataset-field.csv
curl -qfsL '$(SOURCE_URL)/specification/main/specification/field.csv' > specification/field.csv
curl -qfsL '$(SOURCE_URL)/specification/main/specification/datatype.csv' > specification/datatype.csv
curl -qfsL '$(SOURCE_URL)/specification/main/specification/prefix.csv' > specification/prefix.csv
# deprecated ..
curl -qfsL '$(SOURCE_URL)/specification/main/specification/pipeline.csv' > specification/pipeline.csv
curl -qfsL '$(SOURCE_URL)/specification/main/specification/dataset-schema.csv' > specification/dataset-schema.csv
curl -qfsL '$(SOURCE_URL)/specification/main/specification/schema.csv' > specification/schema.csv
curl -qfsL '$(SOURCE_URL)/specification/main/specification/schema-field.csv' > specification/schema-field.csv
init:: specification
endif
# local copy of organsiation datapackage
$(CACHE_DIR)organisation.csv:
@mkdir -p $(CACHE_DIR)
curl -qfs "https://files.planning.data.gov.uk/organisation-collection/dataset/organisation.csv" > $(CACHE_DIR)organisation.csv
init:: config
config::;
commit-makerules::
git add makerules
git diff --quiet && git diff --staged --quiet || (git commit -m "Updated makerules $(shell date +%F)"; git push origin $(BRANCH))
commit-collection::
@: