-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
227 lines (176 loc) · 6.04 KB
/
Makefile
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
SHELL:=/bin/bash
VENV = venv_snlp
VENV_PYTHON = $(VENV)/bin/python
SYSTEM_PYTHON = $(or $(shell which python3), $(shell which python))
# If virtualenv exists, use it. If not, find python using PATH
PYTHON = $(or $(wildcard $(VENV_PYTHON)), $(SYSTEM_PYTHON))
PYTHON_VERSION = 3.10
REQUIREMENTS = gh
REQUIREMENTS += git
REQUIREMENTS += virtualenv
SRC = cnlp
TEST_DIR = tests
# W,E (ignore warning end errors). W (only warnings)
CODE_IGNORE_LEVEL = ""
INSTALL_DIR = requirements
# with '-e' enable install in edit mode
INSTALL_FLG =
DOCS_DIR = docs
# --html, --pdf or blank for markdown
DOCS_FORMAT = "--html"
DOCS_LATEX = True
DOCSTRINGS_FORMAT = numpydoc
LINT_FORMAT = pylint
.PHONY: tests docs build
all:
@echo "social-network-link-prediction Makefile guide."
@echo ""
@echo "Install commands:"
@echo " make install : Install library in the system."
@echo ""
@echo " make install-dev : Create dev environment (virtualenv) and"
@echo " install dev requirements."
@echo ""
@echo " make install-doc : Insitall requirement to generate documentation."
@echo " Needs the environment installed (run make install-dev)"
@echo ""
@echo " make install-test : Install requirements for the testing."
@echo " Needs the environment installed (run make install-dev)"
@echo ""
@echo "Clean commands:"
@echo " make clean-env : Removes all environment files."
@echo " make clean-build : Remove all build files."
@echo " make clean-docstrings : Remove all docstrings (.patch) files."
@echo " make clean-docs : Remove all documentation files."
@echo " make clean : Runs all clean commands."
@echo ""
@echo "Auto-generation commands:"
@echo " code:"
@echo " make code-format : Format all python files (using yapf)."
@echo " make code-check : Checks for warnings and errors. (using pylama linter)."
@echo " make code : Runs -format and -check."
@echo ""
@echo " documentation:"
@echo " make docstrings : Generate docstring for all python files (need to manually apply patches)."
@echo " make documentation : Generate documentation from python docstrings."
@echo ""
@echo " make build : Runs the build project process"
@echo " make tests : Runs the unit tests"
@echo ""
@echo "Publish commands:"
@echo " make publish-release : Publish the library into the Pypi's release repo "
@echo " make publish-testing : Publish the library into the Pypi's testing repo"
# -- Requirements Check --
check:
@echo "🟡 Check Requirements ..."
@for f in $(REQUIREMENTS); do \
type $$f 2> /dev/null 1> /dev/null || { echo "$$f is missing ❌"; exit -1; }; \
done
@echo "Requirements Check Passed ✅"
@echo ""
# -- Install Section --
install:
@echo "🟡 Installing library ..."
$(SYSTEM_PYTHON) -m pip install $(INSTALL_FLG) .
@echo "Library installed ✅"
@echo ""
install-dev: check
@echo "🟡 Installing dev dependencies ..."
virtualenv -p $(PYTHON_VERSION) $(VENV)
@echo "Created env '$(VENV)' ✅"
@echo ""
$(VENV_PYTHON) -m pip install -r $(INSTALL_DIR)/requirements.txt
@echo "dev dependencies installed ✅"
@echo ""
$(VENV_PYTHON) -m pip install -e .
@echo "installed library in edit mode ✅"
@echo ""
install-doc:
@echo "🟡 Installing doc dependencies ... "
$(VENV_PYTHON) -m pip install -r $(INSTALL_DIR)/requirements-doc.txt
@echo "doc dependencies installed ✅"
@echo ""
install-test:
@echo "🟡 Installing testing dependencies ..."
$(VENV_PYTHON) -m pip install -r $(INSTALL_DIR)/requirements-test.txt
@echo "test dependencies installed ✅"
@echo ""
# -- Clean Section --
clean-docs: $(DOCS_DIR)/
@echo "🟡 Cleaning documentation files ..."
rm -rf $(DOCS_DIR)/*
@echo "Documentation files cleaned ✅"
clean-build:
@echo "🟡 Cleaning build files ..."
find . -iname "__pycache__" |xargs rm -rf
find . -iname "*.egg-info" |xargs rm -rf
rm -rf build/ dist/
@echo "Buildfiles cleaned ✅"
clean-env: $(VENV)
@echo "🟡 Cleaning env files ..."
rm -rf $(VENV)
@echo "Removed env $(VENV) ✅"
clean-docstrings: *.patch
@echo "🟡 Cleaning docstrings (.patch) files ..."
rm -rf $^
@echo "docstrings files cleaned ✅"
# clean all !
clean: clean-env clean-build clean-docs clean-docstrings
# -- Runs Section
tests:
@echo "🟡 Running unit tests..."
$(VENV_PYTHON) -m unittest discover -v -s $(TEST_DIR) -t .
# Code cheking & autoformatting
# NOTA:
# per cambiare la variabile CODE_IGNORE_LEVEL
# anteporre questo al target dove si vuole cambiare
# target: CODE_IGNORE_LEVEL="W"
code-check:
@echo "🟡 Checking errors and warnings ..."
pylama -f $(LINT_FORMAT) -i $(CODE_IGNORE_LEVEL) $(SRC)
@echo "No problems found ✅"
code-format:
@echo "🟡 Refactoring code ..."
yapf --recursive -i $(SRC)
@echo "Done ✅"
code: code-format code-check
# Documentation
# TODO: una gestione interattiva di quale parte della patch
# applicare ?
docstrings:
@echo "🟡 Generating docstrings ..."
pyment -o $(DOCSTRINGS_FORMAT) $(SRC)
@echo "Done ✅"
@echo ""
@echo "You have to manually apply patches."
@echo "Try with:"
@echo " git apply filename.py.patch"
@echo "or with:"
@echo " patch -p1 < filename.py.patch"
# docstrings: $(shell pyment -o numpydoc $(SRC))
# for p in $(shell ls *.patch) ; do \
# editdiff $$p && git apply $$p; \
# done;
# rm *.patch
docs:
@echo "🟡 Generating docs from code ..."
@$(MAKE) clean-docs
mkdir -p $(DOCS_DIR)
pdoc $(DOCS_FORMAT) -c latex_math=$(DOCS_LATEX) -o $(DOCS_DIR) $(SRC)
cd $(DOCS_DIR)/ && mv $(SRC)/* ./ && rm -rf $(SRC)
@echo "Done ✅"
build:
@echo "🟡 Building progect ..."
$(VENV_PYTHON) setup.py sdist
@echo "Done ✅"
# -- Publish Section --
publish-release: dist/
# TODO
@echo "🟡 Pushing build to production ..."
twine upload dist/*
@echo "Done ✅"
publish-testing: dist/
# TODO
@echo "🟡 Pushing build to testing ..."
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
@echo "Done ✅"