Makefile 7.06 KB
Newer Older
M. Huang's avatar
M. Huang committed
1
2
3
4
include Makefile_tests.mk
include Makefile_docs.mk
include Makefile_docker.mk

5
PYEXE	= python3.8
M. Huang's avatar
M. Huang committed
6

7
info:
8
	$(PYEXE) -c "import sys, time; print('sys.hash_info.width', sys.hash_info.width, 'epoch', time.gmtime(0))"
9
10
11
####
TO_UPPER    = $(shell python -c "print('$(1)'.upper())")
TO_LOWER    = $(shell python -c "print('$(1)'.lower())")
12

13
PRODUCT = Product
14
B_PRODUCT = BaseProduct
15
PYDIR	:= fdi/dataset
16
RESDIR	:= $(PYDIR)/resources
17
18
P_PY	= $(call TO_LOWER,$(PRODUCT)).py
B_PY	= $(call TO_LOWER,$(B_PRODUCT)).py
19
B_INFO	= $(B_PY)
M. Huang's avatar
M. Huang committed
20
21
P_YAML	= $(RESDIR)/$(PRODUCT).yml
B_YAML	= $(RESDIR)/$(B_PRODUCT).yml
22
23
P_TEMPLATE	:= $(RESDIR)/$(PRODUCT).template
B_TEMPLATE	:= $(RESDIR)/$(B_PRODUCT).template
24
25
26
27
28
29
30
31
32
33

DSETS = ArrayDataset_DataModel TableDataset_DataModel UnstructuredDataset_DataModel MediaWrapper_DataModel
DSETS_PY	= $(addsuffix .py,$(call TO_LOWER,$(DSETS)))
DSETS_YAML	= $(foreach y,$(DSETS),$(RESDIR)/$(y).yml)
DSETS_TEMPL	= $(foreach y,$(DSETS),$(RESDIR)/$(y).template)
DSETSpy		= $(addprefix $(PYDIR)/,$(DSETS_PY))

# BaseProduct, Product and datasets
py: $(PYDIR)/$(B_PY) $(PYDIR)/$(P_PY) $(DSETSpy)

34
$(DSETSpy): $(PYDIR)/yaml2python.py $(DSETS_YAML) $(DSETS_TEMPL) $(PYDIR)/$(B_PY)
35
	$(PYEXE) -m fdi.dataset.yaml2python -y $(RESDIR) -t $(RESDIR) -o $(PYDIR) $(Y)
36

37
38
$(PYDIR)/$(P_PY): $(PYDIR)/yaml2python.py $(P_YAML) $(P_TEMPLATE) $(PYDIR)/$(B_PY)
	$(PYEXE) -m fdi.dataset.yaml2python -y $(RESDIR) -t $(RESDIR) -o $(PYDIR) $(Y)
39
40


41
42
$(PYDIR)/$(B_PY): $(PYDIR)/yaml2python.py $(B_YAML) $(B_TEMPLATE) 
	$(PYEXE) -m fdi.dataset.yaml2python -y $(RESDIR) -t $(RESDIR) -o $(PYDIR) $(Y)
43

M. Huang's avatar
M. Huang committed
44
yamlupgrade: 
M. Huang's avatar
M. Huang committed
45
	$(PYEXE) -m fdi.dataset.yaml2python -y $(RESDIR) -u
M. Huang's avatar
M. Huang committed
46
47


48
.PHONY: runserver runpoolserver reqs install uninstall vtag FORCE \
M. Huang's avatar
M. Huang committed
49
	test test1 test2 test3 test4 test5 test6\
50
	plots plotall plot_dataset plot_pal plot_pns \
51
52
	docs docs_api docs_plots docs_html \
	pipfile
M. Huang's avatar
M. Huang committed
53

M. Huang's avatar
M. Huang committed
54
55
# extra option for 'make runserver S=...'
S	=
M. Huang's avatar
M. Huang committed
56
# default username and password are in pnsconfig.py
57
runpnsserver:
M. Huang's avatar
M. Huang committed
58
	$(PYEXE) -m fdi.pns.runflaskserver $(S)
59
runpoolserver:
M. Huang's avatar
M. Huang committed
60
	$(PYEXE) httppool_app.py --server=httppool_server $(S)
61
62
63

initdb:
	flask --app fdi.httppool  init-db
M. Huang's avatar
M. Huang committed
64
65
wsgi:
	uwsgi --wsgi-file wsgi.py --http-buffer-size 65536 --master --enable-threads --http-socket :9885 $(S)
M. Huang's avatar
M. Huang committed
66

M. Huang's avatar
M. Huang committed
67
EXT	=
68
69
70
71
PKGS	= requests filelock ruamel.yaml tabulate paho-mqtt
PKGSDEV	=pytest pytest-cov aiohttp Flask Flask_HTTpAuth
PKGSDEP	= waitress twine sphinx_rtd_theme sphinx-copybutton

YuxinSHI's avatar
YuxinSHI committed
72
PIPOPT  = --disable-pip-version-check
M. Huang's avatar
M. Huang committed
73
install:
74
75
	$(PYEXE) -m pip install $(PIPOPT) -e .$(EXT) $(I)

M. Huang's avatar
M. Huang committed
76
uninstall:
M. Huang's avatar
M. Huang committed
77
78
79
80
81
82
	$(PYEXE) -m pip uninstall $(PIPOPT) fdi  $(I)

addsubmodule:
	git submodule add  --name leapseconds https://gist.github.com/92df922103ac9deb1a05 ext/leapseconds

update:
M. Huang's avatar
M. Huang committed
83
	git submodule update --init --recursive --remote
M. Huang's avatar
M. Huang committed
84

85
86
87
PNSDIR=~/pns
installpns:
	mkdir -p $(PNSDIR)
88
	$(MAKE) uninstallpns
89
90
91
	for i in init run config clean; do \
	  cp fdi/pns/resources/$${i}PTS.ori  $(PNSDIR); \
	  ln -s $(PNSDIR)/$${i}PTS.ori $(PNSDIR)/$${i}PTS; \
M. Huang's avatar
M. Huang committed
92
	done; \
M. Huang's avatar
M. Huang committed
93
	mkdir -p $(PNSDIR)/input $(PNSDIR)/output
94
	if id -u apache > /dev/null 2>&1; then \
M. Huang's avatar
M. Huang committed
95
96
	chown apache $(PNSDIR) $(PNSDIR)/*PTS.ori $(PNSDIR)/input $(PNSDIR)/output; \
	chgrp apache $(PNSDIR) $(PNSDIR)/*PTS* $(PNSDIR)/input $(PNSDIR)/output; \
97
	fi
M. Huang's avatar
M. Huang committed
98

99
uninstallpns:
100
101
	for i in init run config clean; do \
	  rm -f $(PNSDIR)/$${i}PTS* $(PNSDIR)/$${i}PTS.ori*; \
102
103
104
105
	done; \
	rm -f $(PNSDIR)/.lock $(PNSDIR)/hello.out || \
	sudo rm -f $(PNSDIR)/.lock $(PNSDIR)/hello.out

106
107
108
109
PYREPO	= pypi
INDURL	= 
#PYREPO	= testpypi
#INDURL	= --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/
110
111
LOCAL_INDURL	= $(CURDIR)/dist/*.whl --extra-index-url https://pypi.org/simple/
wheel:
M. Huang's avatar
M. Huang committed
112
	# git ls-tree -r HEAD | awk 'print $4' > MANIFEST
M. Huang's avatar
M. Huang committed
113
	rm -rf dist/* build *.egg-info
M. Huang's avatar
M. Huang committed
114
	$(PYEXE) setup.py sdist bdist_wheel
115
	twine check dist/*
116
	check-wheel-contents dist
117
upload:
M. Huang's avatar
M. Huang committed
118
	$(PYEXE) -m twine upload --repository $(PYREPO) dist/*
119

120
121
122
123
FDI_WHEEL_DIR	= ./dist #../wheel
wheel_install:
	$(PYEXE) -m pip install fdi $(I) --disable-pip-version-check --cache-dir ../../pipcache --no-index -f $(FDI_WHEEL_DIR)

124
virtest:
125
	rm -rf /tmp/fditestvirt
M. Huang's avatar
M. Huang committed
126
	virtualenv -p $(PYEXE) /tmp/fditestvirt
127
	. /tmp/fditestvirt/bin/activate && \
M. Huang's avatar
M. Huang committed
128
129
130
131
	$(PYEXE) -m pip uninstall -q -q -y fdi ;\
	$(PYEXE) -m pip cache remove -q -q -q fdi ;\
	$(PYEXE) -m pip install $(LOCAL_INDURL) "fdi" && \
	$(PYEXE) -m pip show fdi && \
132
	echo Testing newly installed fdi ... ; \
M. Huang's avatar
M. Huang committed
133
	$(PYEXE) -c 'import sys, fdi.dataset.arraydataset as f; a=f.ArrayDataset(data=[4,3]); sys.exit(0 if a[1] == 3 else a[1])' && \
M. Huang's avatar
M. Huang committed
134
	$(PYEXE) -c 'import sys, pkgutil as p; sys.stdout.buffer.write(p.get_data("fdi", "dataset/resources/Product.template")[:100])' && \
135
136
	deactivate

M. Huang's avatar
M. Huang committed
137
138
J_OPTS	= ${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties
J_OPTS	= ${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties
139
140
141
142
143
144
145
146
VERYOLD	=-t ../swagger-codegen/modules/swagger-codegen/src/main/resources/flaskConnexion
FCTEMPL	=../swagger-codegen-generators/src/main/resources/handlebars/pythonFlaskConnexion/
AGS	=  -vv
SWJAR	= ../swagger-codegen/swagger-codegen-cli-3.0.25.jar
# The one below is not working probably because mvn is not working
#SWJAR	= ../swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar

SCHEMA_DIR	=fdi/httppool/schema
147
# so that flsgger can understand.
148
de-ref:
149
	swagger-cli bundle  -t yaml ${SCHEMA_DIR}/pools.yml -o ${SCHEMA_DIR}/pools_resolved.yml
150

151
# make swagger server subs
M. Huang's avatar
M. Huang committed
152
api:
153
154
155
	rm -rf fdi/httppool/flaskConnexion/*
	java $(J_OPTS) -jar $(SWJAR) generate $(AGS) -i ./fdi/httppool/schema/pools.yml -l python-flask -o ./fdi/httppool/swagger -Dservice -DpackageName=fdi.httppool.swagger -DpackageVersion=2.0 -DserverPort=9000

156
# $ref: works, unlike swagger editor
157
158
watchapi:
	swagger-ui-watcher fdi/httppool/schema/pools.yml
M. Huang's avatar
M. Huang committed
159

160
161
swagger-editor:
	@echo browser open file:///d:/code/swagger-editor/index.html
162
163
164
reqs:
	pipreqs --ignore tmp --force --savepath requirements.txt.pipreqs

M. Huang's avatar
M. Huang committed
165
166
167
gitadd:
	git add LICENSE README.rst CHANGELOG.rst setup.py MANIFEST.in \
	.gitignore noxfile.py Makefile .gitmodules .gitlab-ci.yml \
M. Huang's avatar
M. Huang committed
168
	.readthedocs.yml .dockerignore CONTRIBUTORS stage-docker-fdi pytest.ini
M. Huang's avatar
M. Huang committed
169
170
171
172
173
	git add bin/reinstall bin/installpns bin/update
	git add resources
	git add fdi/*.py
	git add fdi/dataset/*.py fdi/dataset/resources
	git add fdi/pns/*.py fdi/pns/resources
M. Huang's avatar
M. Huang committed
174
	git add fdi/pal/*.py fdi/pal/resources/schema
M. Huang's avatar
M. Huang committed
175
	git add fdi/utils/*.py
176
	git add fdi/schemas
M. Huang's avatar
M. Huang committed
177
	git add httppool_app.py fdi/httppool
178
179
	git add Makefile_tests.mk tests/*.py tests/resources tests/serv/*.py tests/serv/resources
	git add Makefile_docs.mk docs/sphinx/index.rst docs/sphinx/usage docs/sphinx/api \
M. Huang's avatar
M. Huang committed
180
181
	docs/sphinx/conf.py docs/sphinx/Makefile \
	docs/sphinx/_static docs/sphinx/_templates
182
	git add Makefile_docker.mk dockerfile dockerfile_entrypoint.sh
M. Huang's avatar
version    
M. Huang committed
183
# update _version.py and tag based on setup.py
M. Huang's avatar
M. Huang committed
184
# VERSION	= $(shell $(PYEXE) -S -c "from setuptools_scm import get_version;print(get_version('.'))")
M. Huang's avatar
M. Huang committed
185
186
187
188
# @ echo update _version.py and tag to $(VERSION)


VERSIONFILE	= fdi/_version.py
M. Huang's avatar
M. Huang committed
189
VERSION	= $(shell $(PYEXE) -S -c "_l = {};f=open('$(VERSIONFILE)'); exec(f.read(), None, _l); f.close; print(_l['__version__'])")
M. Huang's avatar
M. Huang committed
190

M. Huang's avatar
M. Huang committed
191
vtag:
192
	@ echo  version = \"$(VERSION)\" in $(VERSIONFILE)
M. Huang's avatar
M. Huang committed
193
	git tag  $(VERSION)
194
	git push origin $(VERSION)
M. Huang's avatar
version    
M. Huang committed
195

196
197
FORCE:

M. Huang's avatar
M. Huang committed
198
########
M. Huang's avatar
M. Huang committed
199
200
# docker
########
201

202