-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
110 lines (85 loc) · 3 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
# Run the linter and tests suite of this repo.
# `make use_venv=0` will use the default `python` otherwise uses the one in `.venv/`
use_venv=1
ifeq ($(use_venv),0)
BIN?=
else
BIN=venv/bin/
endif
CODE=submitit_oar
all: integration
which:
which $(BIN)python
$(BIN)python --version
test:
$(BIN)pytest $(CODE)
test_coverage:
$(BIN)pytest \
-v \
--cov=submitit_oar --cov-report=html --cov-report=term \
--durations=10 \
--junitxml=test_results/pytest/results.xml \
$(CODE)
format:
$(BIN)python -m pre_commit
$(BIN)isort $(CODE)
$(BIN)black $(CODE)
check_format:
# also formats docs
$(BIN)isort --check --diff $(CODE)
$(BIN)black --check --diff $(CODE)
mypy:
$(BIN)mypy --version
$(BIN)mypy --junit-xml=test_results/pytest/results.xml $(CODE)
pylint:
$(BIN)pylint --version
$(BIN)pylint $(CODE)
lint: mypy pylint
venv: venv/pyproject.toml
venv/pyproject.toml: pyproject.toml
python3 -m venv venv
venv/bin/pip install --progress-bar off --upgrade pip
venv/bin/pip install --progress-bar off -U -e .[dev]
cp $^ $@
installable: installable_local installable_wheel
installable_local: venv
(. ./venv/bin/activate ; cd /tmp ; python -c "import submitit_oar")
USER_VENV=/tmp/submitit_oar_user_venv/
CURRENT_VERSION=`grep -e '__version__' ./submitit_oar/__init__.py | sed 's/__version__ = //' | sed 's/"//g'`
TEST_PYPI=--index-url 'https://test.pypi.org/simple/' --no-cache-dir --no-deps --progress-bar off
installable_wheel:
[ ! -d dist ] || rm -r dist
grep -e '__version__' ./submitit_oar/__init__.py | sed 's/__version__ = //' | sed 's/"//g'
$(BIN)python -m flit build --setup-py
git checkout HEAD -- ./submitit_oar/__init__.py
[ ! -d $(USER_VENV) ] || rm -r $(USER_VENV)
python3 -m venv $(USER_VENV)
$(USER_VENV)/bin/pip install --progress-bar off dist/submitit_oar-*any.whl
# Check that importing works
$(USER_VENV)/bin/python -c "import submitit_oar"
clean:
rm -r venv
clean_cache:
# Invalidates `make venv` and therefore trigger a new `pip install --upgrade`.
rm venv/pyproject.toml
pre_commit: format lint
register_pre_commit: venv
(grep -e "^make pre_commit$$" .git/hooks/pre-commit) || (echo "make pre_commit" >> .git/hooks/pre-commit)
chmod +x .git/hooks/pre-commit
integration: clean_cache venv check_format lint installable test_coverage
# Runs the same tests than on CI.
# clean_cache will make sure we download the last versions of linters.
# Use `make -k integration` to run all checks even if previous fails.
release: integration
echo "Releasing submitit_oar $(CURRENT_VERSION)"
[ ! -d dist ] || rm -r dist
# Make sure the repo is in a clean state
git diff --exit-code
# --setup-py generates a setup.py file to allow user with old
# versions of pip to install it without flit.
git tag $(CURRENT_VERSION)
# To have a reproducible build we use the timestamp of the last commit:
# https://flit.pypa.io/en/latest/reproducible.html
SOURCE_DATE_EPOCH=`git log -n1 --format=%cd --date=unix` $(BIN)python -m flit publish --setup-py
git checkout HEAD -- README.md
git push origin $(CURRENT_VERSION)