Skip to content

Commit eef7022

Browse files
author
Mauko Quiroga
committed
Split Makefile
1 parent a8db22d commit eef7022

6 files changed

Lines changed: 144 additions & 145 deletions

File tree

Makefile

Lines changed: 8 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,12 @@
1+
include openfisca_make/build.mk
2+
include openfisca_make/install.mk
3+
include openfisca_make/lint.mk
4+
include openfisca_make/test.mk
5+
include openfisca_make/serve.mk
6+
17
help = sed -n "/^$1/ { x ; p ; } ; s/\#\#/[⚙]/ ; s/\./.../ ; x" ${MAKEFILE_LIST}
2-
repo = https://github.com/openfisca/openfisca-doc
3-
branch = $(shell git branch --show-current)
4-
python_packages = $(shell python -c "import sysconfig; print(sysconfig.get_paths()[\"purelib\"])")
8+
9+
.DEFAULT_GOAL := all
510

611
## Same as `make test`.
712
all: test
8-
9-
## Install project dependencies.
10-
install:
11-
@$(call help,$@:)
12-
@pip install --upgrade pip twine wheel
13-
@pip install --editable .[dev] --upgrade --use-deprecated=legacy-resolver
14-
15-
## Install openfisca-core for deployment and publishing.
16-
build: setup.py
17-
@## This allows us to be sure tests are run against the packaged version
18-
@## of openfisca-core, the same we put in the hands of users and reusers.
19-
@$(call help,$@:)
20-
@python $? bdist_wheel
21-
@find dist -name "*.whl" -exec pip install --force-reinstall {}[dev] \;
22-
23-
## Uninstall project dependencies.
24-
uninstall:
25-
@$(call help,$@:)
26-
@pip freeze | grep -v "^-e" | sed "s/@.*//" | xargs pip uninstall -y
27-
28-
## Delete builds and compiled python files.
29-
clean: \
30-
$(shell ls -d * | grep "build\|dist") \
31-
$(shell find . -name "*.pyc")
32-
@$(call help,$@:)
33-
@rm -rf $?
34-
35-
## Compile python files to check for syntax errors.
36-
check-syntax-errors: .
37-
@$(call help,$@:)
38-
@python -m compileall -q $?
39-
40-
## Run linters to check for syntax and style errors.
41-
check-style: $(shell git ls-files "*.py")
42-
@$(call help,$@:)
43-
@flake8 $?
44-
45-
## Run code formatters to correct style errors.
46-
format-style: $(shell git ls-files "*.py")
47-
@$(call help,$@:)
48-
@autopep8 $?
49-
50-
## Run static type checkers for type errors.
51-
check-types: openfisca_core openfisca_web_api
52-
@$(call help,$@:)
53-
@mypy $?
54-
55-
## Run openfisca-core & country/extension template tests.
56-
test: clean check-syntax-errors check-style check-types
57-
@## Usage:
58-
@##
59-
@## make test [pytest_args="--ARG"] [openfisca_args="--ARG"]
60-
@##
61-
@## Examples:
62-
@##
63-
@## make test
64-
@## make test pytest_args="--exitfirst"
65-
@## make test openfisca_args="--performance"
66-
@## make test pytest_args="--exitfirst" openfisca_args="--performance"
67-
@##
68-
@$(call help,$@:)
69-
@${MAKE} test-core
70-
@${MAKE} test-country
71-
@${MAKE} test-extension
72-
73-
# Run openfisca-core tests.
74-
test-core: $(shell git ls-files "tests/*.py")
75-
@$(call help,$@:)
76-
@PYTEST_ADDOPTS="${PYTEST_ADDOPTS} --cov=openfisca_core ${pytest_args}" openfisca test $? ${openfisca_args}
77-
78-
# Run country-template tests.
79-
test-country: ${python_packages}/openfisca_country_template/tests
80-
@$(call help,$@:)
81-
@PYTEST_ADDOPTS="${PYTEST_ADDOPTS} ${pytest_args}" openfisca test $? --country-package openfisca_country_template ${openfisca_args}
82-
83-
# Run extension-template tests.
84-
test-extension: ${python_packages}/openfisca_extension_template/tests
85-
@$(call help,$@:)
86-
@PYTEST_ADDOPTS="${PYTEST_ADDOPTS} ${pytest_args}" openfisca test $? --country-package openfisca_country_template --extensions openfisca_extension_template ${openfisca_args}
87-
88-
## Check that the current changes do not break the doc.
89-
test-doc:
90-
@## Usage:
91-
@##
92-
@## make test-doc [branch=BRANCH]
93-
@##
94-
@## Examples:
95-
@##
96-
@## # Will check the current branch in openfisca-doc.
97-
@## make test-doc
98-
@##
99-
@## # Will check "test-doc" in openfisca-doc.
100-
@## make test-doc branch=test-doc
101-
@##
102-
@## # Will check "master" if "asdf1234" does not exist.
103-
@## make test-doc branch=asdf1234
104-
@##
105-
@$(call help,$@:)
106-
@${MAKE} test-doc-checkout
107-
@${MAKE} test-doc-install
108-
@${MAKE} test-doc-build
109-
110-
## Update the local copy of the doc.
111-
test-doc-checkout:
112-
@$(call help,$@:)
113-
@[ ! -d doc ] && git clone ${repo} doc || :
114-
@cd doc && { \
115-
git reset --hard ; \
116-
git fetch --all ; \
117-
[ "$$(git branch --show-current)" != "master" ] && git checkout master || : ; \
118-
[ "${branch}" != "master" ] \
119-
&& { \
120-
{ \
121-
git branch -D ${branch} 2> /dev/null ; \
122-
git checkout ${branch} ; \
123-
} \
124-
&& git pull --ff-only origin ${branch} \
125-
|| { \
126-
>&2 echo "[!] The branch '${branch}' doesn't exist, checking out 'master' instead..." ; \
127-
git pull --ff-only origin master ; \
128-
} \
129-
} \
130-
|| git pull --ff-only origin master ; \
131-
} 1> /dev/null
132-
133-
## Install doc dependencies.
134-
test-doc-install:
135-
@$(call help,$@:)
136-
@pip install --requirement doc/requirements.txt 1> /dev/null
137-
@pip install --editable .[dev] --upgrade 1> /dev/null
138-
139-
## Dry-build the doc.
140-
test-doc-build:
141-
@$(call help,$@:)
142-
@sphinx-build -M dummy doc/source doc/build -n -q -W
143-
144-
## Serve the openfisca Web API.
145-
api:
146-
@$(call help,$@:)
147-
@openfisca serve \
148-
--country-package openfisca_country_template \
149-
--extensions openfisca_extension_template

openfisca_make/build.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Install openfisca-core for deployment and publishing.
2+
build: setup.py
3+
@## This allows us to be sure tests are run against the packaged version
4+
@## of openfisca-core, the same we put in the hands of users and reusers.
5+
@$(call help,$@:)
6+
@python $? bdist_wheel
7+
@find dist -name "*.whl" -exec pip install --force-reinstall {}[dev] \;

openfisca_make/install.mk

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Install project dependencies.
2+
install:
3+
@$(call help,$@:)
4+
@pip install --upgrade pip twine wheel
5+
@pip install --editable .[dev] --upgrade --use-deprecated=legacy-resolver
6+
7+
## Uninstall project dependencies.
8+
uninstall:
9+
@$(call help,$@:)
10+
@pip freeze | grep -v "^-e" | sed "s/@.*//" | xargs pip uninstall -y
11+
12+
## Delete builds and compiled python files.
13+
clean: \
14+
$(shell ls -d * | grep "build\|dist") \
15+
$(shell find . -name "*.pyc")
16+
@$(call help,$@:)
17+
@rm -rf $?

openfisca_make/lint.mk

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## Compile python files to check for syntax errors.
2+
check-syntax-errors: .
3+
@$(call help,$@:)
4+
@python -m compileall -q $?
5+
6+
## Run linters to check for syntax and style errors.
7+
check-style: $(shell git ls-files "*.py")
8+
@$(call help,$@:)
9+
@flake8 $?
10+
11+
## Run static type checkers for type errors.
12+
check-types: openfisca_core openfisca_web_api
13+
@$(call help,$@:)
14+
@mypy $?
15+
16+
## Run code formatters to correct style errors.
17+
format-style: $(shell git ls-files "*.py")
18+
@$(call help,$@:)
19+
@autopep8 $?

openfisca_make/serve.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Serve the openfisca Web API.
2+
api:
3+
@$(call help,$@:)
4+
@openfisca serve \
5+
--country-package openfisca_country_template \
6+
--extensions openfisca_extension_template

openfisca_make/test.mk

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
repo = https://github.com/openfisca/openfisca-doc
2+
branch = $(shell git branch --show-current)
3+
python_packages = $(shell python -c "import sysconfig; print(sysconfig.get_paths()[\"purelib\"])")
4+
5+
## Run openfisca-core & country/extension template tests.
6+
test: clean check-syntax-errors check-style check-types test-core test-country test-extension
7+
@## Usage:
8+
@##
9+
@## make test [pytest_args="--ARG"] [openfisca_args="--ARG"]
10+
@##
11+
@## Examples:
12+
@##
13+
@## make test
14+
@## make test pytest_args="--exitfirst"
15+
@## make test openfisca_args="--performance"
16+
@## make test pytest_args="--exitfirst" openfisca_args="--performance"
17+
18+
## Run openfisca-core tests.
19+
test-core: $(shell git ls-files "tests/*.py")
20+
@$(call help,$@:)
21+
@PYTEST_ADDOPTS="${PYTEST_ADDOPTS} --cov=openfisca_core ${pytest_args}" openfisca test $? ${openfisca_args}
22+
23+
## Run country-template tests.
24+
test-country: ${python_packages}/openfisca_country_template/tests
25+
@$(call help,$@:)
26+
@PYTEST_ADDOPTS="${PYTEST_ADDOPTS} ${pytest_args}" openfisca test $? --country-package openfisca_country_template ${openfisca_args}
27+
28+
## Run extension-template tests.
29+
test-extension: ${python_packages}/openfisca_extension_template/tests
30+
@$(call help,$@:)
31+
@PYTEST_ADDOPTS="${PYTEST_ADDOPTS} ${pytest_args}" openfisca test $? --country-package openfisca_country_template --extensions openfisca_extension_template ${openfisca_args}
32+
33+
## Check that the current changes do not break the doc.
34+
test-doc:
35+
@## Usage:
36+
@##
37+
@## make test-doc [branch=BRANCH]
38+
@##
39+
@## Examples:
40+
@##
41+
@## # Will check the current branch in openfisca-doc.
42+
@## make test-doc
43+
@##
44+
@## # Will check "test-doc" in openfisca-doc.
45+
@## make test-doc branch=test-doc
46+
@##
47+
@## # Will check "master" if "asdf1234" does not exist.
48+
@## make test-doc branch=asdf1234
49+
@##
50+
@$(call help,$@:)
51+
@${MAKE} test-doc-checkout
52+
@${MAKE} test-doc-install
53+
@${MAKE} test-doc-build
54+
55+
## Update the local copy of the doc.
56+
test-doc-checkout:
57+
@$(call help,$@:)
58+
@[ ! -d doc ] && git clone ${repo} doc || :
59+
@cd doc && { \
60+
git reset --hard ; \
61+
git fetch --all ; \
62+
[ "$$(git branch --show-current)" != "master" ] && git checkout master || : ; \
63+
[ "${branch}" != "master" ] \
64+
&& { \
65+
{ \
66+
git branch -D ${branch} 2> /dev/null ; \
67+
git checkout ${branch} ; \
68+
} \
69+
&& git pull --ff-only origin ${branch} \
70+
|| { \
71+
>&2 echo "[!] The branch '${branch}' doesn't exist, checking out 'master' instead..." ; \
72+
git pull --ff-only origin master ; \
73+
} \
74+
} \
75+
|| git pull --ff-only origin master ; \
76+
} 1> /dev/null
77+
78+
## Install doc dependencies.
79+
test-doc-install:
80+
@$(call help,$@:)
81+
@pip install --requirement doc/requirements.txt 1> /dev/null
82+
@pip install --editable .[dev] --upgrade 1> /dev/null
83+
84+
## Dry-build the doc.
85+
test-doc-build:
86+
@$(call help,$@:)
87+
@sphinx-build -M dummy doc/source doc/build -n -q -W

0 commit comments

Comments
 (0)