-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
158 lines (127 loc) · 4.55 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
# Copyright 2021 BlackRock, Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
ONPY=hola/ tests/ benchmarks/ analysis/
ONNB=notebooks/
ONSH=*.sh
ONYML=.azuredevops .github *.yaml
BLACK_FLAGS=--config pyproject.toml
ISORT_FLAGS=--settings-path pyproject.toml
DOCFORMATTER_FLAGS=--wrap-summaries=120 --wrap-descriptions=120
AUTOFLAKE_FLAGS=--remove-all-unused-imports
MYPY_FLAGS=--config-file mypy.ini
BANDIT_FLAGS=--configfile pyproject.toml
YAMLLINT_FLAGS=--config-file yamllint.yaml
PYTEST_FLAGS=-c pyproject.toml
#FLAKE8_NB_FLAGS=--config .flake8_nb
fmt: fmt-py # fmt-nb # fmt-sh
fmt-py: black isort docformatter autoflake flynt
fmt-nb: nbstripout black-nb
#fmt-sh: shfmt
lint: lint-sh lint-yml lint-py # lint-nb
lint-py: docformatter-check isort-check black-check autoflake-check flake8 bandit mypy pylint
lint-nb: black-nb-check flake8-nb
lint-sh: shellcheck # shfmt-check
lint-yml: yamllint
ifneq ($(shell command -v gfind),) # is MacOS (mostly)
gnu_find=gfind
else
gnu_find=find
endif
ifneq ($(shell command -v gxargs),) # is MacOS (mostly)
gnu_xargs=gxargs
else
gnu_xargs=xargs
endif
# FORMAT ---------------------------------------------------------------------------------------------------------------
.PHONY: black
black:
python -m black $(BLACK_FLAGS) $(ONPY)
.PHONY: isort
isort:
python -m isort $(ISORT_FLAGS) $(ONPY)
.PHONY: docformatter
docformatter:
python -m docformatter --in-place $(DOCFORMATTER_FLAGS) -r $(ONPY)
.PHONY: autoflake
autoflake:
python -m autoflake --in-place $(AUTOFLAKE_FLAGS) -r $(ONPY)
.PHONY: flynt
flynt:
python -m flynt $(ONPY)
.PHONY: nbstripout
nbstripout:
$(gnu_find) $(ONNB) -type f -name "*.ipynb" -print | $(gnu_xargs) python -m nbstripout --strip-empty-cells
.PHONY: black-nb
black-nb:
python -m black $(BLACK_FLAGS) $(ONNB)
.PHONY: shfmt
shfmt:
shfmt -w $(SHFMT_FLAGS) $(ONSH)
# LINT -----------------------------------------------------------------------------------------------------------------
.PHONY: black-check
black-check:
python -m black --check $(BLACK_FLAGS) $(ONPY)
.PHONY: docformatter-check
docformatter-check:
python -m docformatter $(DOCFORMATTER_FLAGS) -r $(ONPY) && \
python -m docformatter --check $(DOCFORMATTER_FLAGS) -r $(ONPY)
.PHONY: isort-check
isort-check:
python -m isort --diff --color --check-only $(ISORT_FLAGS) $(ONPY)
.PHONY: autoflake-check
autoflake-check:
python -m autoflake --in-place $(AUTOFLAKE_FLAGS) -r $(ONNB)
.PHONY: flake8
flake8:
python -m flake8 $(FLAKE8_FLAGS) $(ONPY)
.PHONY: pylint
pylint:
python -m pylint $(PYLINT_FLAGS) $(ONPY)
.PHONY: bandit
bandit:
python -m bandit $(BANDIT_FLAGS) -r $(ONPY)
.PHONY: black-nb-check
black-nb-check:
python -m black --check $(BLACK_FLAGS) $(ONNB)
.PHONY: flake8-nb
flake8-nb:
$(gnu_find) $(ONNB) -type f -iname "*.ipynb" | $(gnu_xargs) python -m flake8_nb $(FLAKE8_NB_FLAGS)
.PHONY: shfmt-check
shfmt-check:
shfmt -d $(SHFMT_FLAGS) $(ONSH)
.PHONY: shellcheck
shellcheck:
$(gnu_find) $(ONSH) -type f -iname "*.sh" | $(gnu_xargs) shellcheck $(SHELLCHECK_FLAGS)
.PHONY: yamllint
yamllint:
python -m yamllint $(YAMLLINT_FLAGS) $(ONYML)
# TYPE CHECK -----------------------------------------------------------------------------------------------------------
.PHONY: mypy
mypy:
python -m mypy $(MYPY_FLAGS) $(ONPY)
# TEST -----------------------------------------------------------------------------------------------------------------
.PHONY: test
test:
python -m pytest $(PYTEST_FLAGS) $(ONPY)
# CLEAN ----------------------------------------------------------------------------------------------------------------
.PHONY: clean-pyc
clean-pyc:
$(gnu_find) . -name *.pyc | $(gnu_xargs) rm -f && $(gnu_find) . -name *.pyo | $(gnu_xargs) rm -f;
.PHONY: clean-build
clean-build:
rm -rf build/
rm -rf dist/
rm -rf *.egg-info
# ENV -----------------------------------------------------------------------------------------------------------------
.PHONY: env
env:
python -m pip install --upgrade pip setuptools $(extra_pip_flags)
python -m pip install --upgrade -r requirements.txt -r requirements-dev.txt -r requirements-mypy.txt -r requirements-research.txt $(extra_pip_flags)