Skip to content

Commit 53b0285

Browse files
author
Mauko Quiroga
committed
Simplify make rules
1 parent 84bdb68 commit 53b0285

1 file changed

Lines changed: 33 additions & 40 deletions

File tree

Makefile

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
OK := "$$(tput setaf 2)$$(tput sgr0)"
2-
PASS := "$$(tput setaf 3)$$(tput sgr0)"
3-
WORKING := "$$(tput setaf 5)[⚙] $$(tput sgr0)"
4-
OPTIONS := "$$(tput setaf 6)[ℹ] $$(tput sgr0)"
1+
OK := "$$(tput setaf 2) [✓] $$(tput sgr0)"
2+
KO := "$$(tput setaf 1) [!] $$(tput sgr0)"
3+
PASS := "$$(tput setaf 3) [~] $$(tput sgr0)"
4+
WORKING := "$$(tput setaf 5)[⚙]$$(tput sgr0)"
5+
OPTIONS := "$$(tput setaf 6)[ℹ]$$(tput sgr0)"
56
COUNTRY_TEMPLATE := openfisca_country_template
67
EXTENSION_TEMPLATE := openfisca_extension_template
7-
PYTHON_PACKAGES_PATH := $(shell python -c "import sysconfig; print(sysconfig.get_paths()[\"purelib\"])")
8+
PYTHON_PACKAGES_PATH := $$(python -c "import sysconfig; print(sysconfig.get_paths()[\"purelib\"])")
89
COUNTRY_TEMPLATE_TESTS := ${PYTHON_PACKAGES_PATH}/${COUNTRY_TEMPLATE}/tests
910
EXTENSION_TEMPLATE_TESTS := ${PYTHON_PACKAGES_PATH}/${EXTENSION_TEMPLATE}/tests
1011

@@ -49,38 +50,35 @@ help:
4950

5051
## Uninstall project dependencies.
5152
uninstall:
52-
@printf ${WORKING}
53-
@echo "Uninstalling dependencies..."
53+
@echo "${WORKING} Uninstalling dependencies..."
5454
@pip freeze | grep -v "^-e" | xargs pip uninstall -y
5555

5656
## Install project dependencies.
5757
install:
58-
@printf ${WORKING}
59-
@echo "Installing dependencies..."
58+
@echo "${WORKING} Installing dependencies..."
6059
@pip install --upgrade pip twine wheel
6160
@pip install --editable .[dev] --upgrade --use-deprecated=legacy-resolver
6261

6362
## Delete builds and compiled python files.
6463
clean:: ;
6564

6665
clean:: $(shell find . -name "*.pyc")
67-
@printf ${WORKING}
68-
@printf "Deleting compiled files..."
66+
@printf "${WORKING} Deleting compiled files..."
6967
@[ ! -z "$?" ] \
70-
&& { rm -f $? && echo ${OK} ; } \
68+
&& rm -f $? \
69+
&& echo ${OK} \
7170
|| echo ${PASS}
7271

7372
clean:: $(shell ls -d * | grep "build\|dist")
74-
@printf ${WORKING}
75-
@printf "Deleting builds..."
73+
@printf "${WORKING} Deleting builds..."
7674
@[ ! -z "$?" ] \
77-
&& { rm -rf $? && echo ${OK} ; } \
75+
&& rm -rf $? \
76+
&& echo ${OK} \
7877
|| echo ${PASS}
7978

8079
## Compile python files to check for syntax errors.
8180
check-syntax-errors:
82-
@printf ${WORKING}
83-
@printf "Compiling python files..."
81+
@printf "${WORKING} Compiling python files..."
8482
@python -m compileall -q .
8583
@echo ${OK}
8684

@@ -89,29 +87,28 @@ check-style: $(shell git ls-files | grep "\.py$$")
8987
@## Do not analyse .gitignored files.
9088
@## `make` needs `$$` to output `$`.
9189
@## See http://stackoverflow.com/questions/2382764.
92-
@printf ${WORKING}
93-
@printf "Running linters..."
90+
@printf "${WORKING} Running linters..."
9491
@flake8 $? &> /tmp/result; echo $$? > /tmp/status;
9592
@[ $$(</tmp/status) -eq 0 ] \
9693
&& echo ${OK} \
97-
|| { echo "\n$$(cat /tmp/result)" && exit $$(</tmp/status) ; }
94+
|| echo "${KO}\n$$(</tmp/result)" \
95+
&& exit $$(</tmp/status)
9896

9997
## Run static type checkers for type errors.
10098
check-types: $(shell ls -d * | grep "openfisca_")
101-
@printf ${WORKING}
102-
@printf "Running static type checkers..."
99+
@printf "${WORKING} Running static type checkers..."
103100
@mypy $? &> /tmp/result; echo $$? > /tmp/status;
104101
@[ $$(</tmp/status) -eq 0 ] \
105102
&& echo ${OK} \
106-
|| { echo "\n$$(cat /tmp/result)" && exit $$(</tmp/status) ; }
103+
|| echo "${KO}\n$$(</tmp/result)" \
104+
&& exit $$(</tmp/status)
107105

108106
## Run code formatters to correct style errors.
109107
format-style: $(shell git ls-files | grep "\.py$$")
110108
@## Do not analyse .gitignored files.
111109
@## `make` needs `$$` to output `$`.
112110
@## See http://stackoverflow.com/questions/2382764.
113-
@printf ${WORKING}
114-
@printf "Running code formatters..."
111+
@printf "${WORKING} Running code formatters..."
115112
@autopep8 $?
116113
@echo ${OK}
117114

@@ -129,23 +126,20 @@ test:: clean check-syntax-errors check-style check-types
129126
@## make test pytest_args="--exitfirst" openfisca_args="--performance"
130127

131128
test::
132-
@printf ${WORKING}
133-
@echo "Running openfisca-core tests..."
134-
@[ ! -z "${pytest_args}" ] && printf ${OPTIONS} && echo "pytest arguments: ${pytest_args}" ; :
129+
@echo "${WORKING} Running openfisca-core tests..."
130+
@[ ! -z "${pytest_args}" ] && echo "${OPTIONS} pytest arguments: ${pytest_args}" ; :
135131
@PYTEST_ADDOPTS="$$PYTEST_ADDOPTS ${pytest_args}" pytest
136132

137133
test::
138-
@printf ${WORKING}
139-
@echo "Running country-template tests..."
140-
@[ ! -z "${pytest_args}" ] && printf ${OPTIONS} && echo "pytest arguments: ${pytest_args}" ; :
141-
@[ ! -z "${openfisca_args}" ] && printf ${OPTIONS} && echo "openfisca arguments: ${openfisca_args}" ; :
134+
@echo "${WORKING} Running country-template tests..."
135+
@[ ! -z "${pytest_args}" ] && echo "${OPTIONS} pytest arguments: ${pytest_args}" ; :
136+
@[ ! -z "${openfisca_args}" ] && echo "${OPTIONS} openfisca arguments: ${openfisca_args}" ; :
142137
@PYTEST_ADDOPTS="$$PYTEST_ADDOPTS ${pytest_args}" openfisca test ${COUNTRY_TEMPLATE_TESTS} --country-package ${COUNTRY_TEMPLATE} ${openfisca_args}
143138

144139
test::
145-
@printf ${WORKING}
146-
@echo "Running extension-template tests..."
147-
@[ ! -z "${pytest_args}" ] && printf ${OPTIONS} && echo "pytest arguments: ${pytest_args}" ; :
148-
@[ ! -z "${openfisca_args}" ] && printf ${OPTIONS} && echo "openfisca arguments: ${openfisca_args}" ; :
140+
@echo "${WORKING} Running extension-template tests..."
141+
@[ ! -z "${pytest_args}" ] && echo "${OPTIONS} pytest arguments: ${pytest_args}" ; :
142+
@[ ! -z "${openfisca_args}" ] && echo "${OPTIONS} openfisca arguments: ${openfisca_args}" ; :
149143
@PYTEST_ADDOPTS="$$PYTEST_ADDOPTS ${pytest_args}" openfisca test ${EXTENSION_TEMPLATE_TESTS} --country-package ${COUNTRY_TEMPLATE} --extensions ${EXTENSION_TEMPLATE} ${openfisca_args}
150144

151145
## Serve the OpenFisca Web API.
@@ -160,10 +154,9 @@ serve::
160154
@## make serve gunicorn_args="--workers 1"
161155
@## make serve openfisca_args="--welcome-message 'Hola :)'"
162156
@## make serve gunicorn_args="--workers 1" openfisca_args="--welcome-message 'Hola :)'"
163-
@printf ${WORKING}
164-
@echo "Serving the OpenFisca Web API..."
165-
@[ ! -z "${gunicorn_args}" ] && printf ${OPTIONS} && echo "gunicorn arguments: ${gunicorn_args}" ; :
166-
@[ ! -z "${openfisca_args}" ] && printf ${OPTIONS} && echo "openfisca arguments: ${openfisca_args}" ; :
157+
@echo "${WORKING} Serving the OpenFisca Web API..."
158+
@[ ! -z "${gunicorn_args}" ] && echo "${OPTIONS} gunicorn arguments: ${gunicorn_args}" ; :
159+
@[ ! -z "${openfisca_args}" ] && echo "${OPTIONS} openfisca arguments: ${openfisca_args}" ; :
167160
@openfisca serve --country-package ${COUNTRY_TEMPLATE} --extensions ${EXTENSION_TEMPLATE} ${gunicorn_args} ${openfisca_args}
168161

169162
api: serve

0 commit comments

Comments
 (0)