2020-02-24 18:58:07 +01:00
|
|
|
SHELL := /bin/bash
|
|
|
|
|
2020-03-22 19:52:56 +01:00
|
|
|
ifndef SHELLFLAGS
|
|
|
|
SHELLFLAGS :=
|
|
|
|
endif
|
|
|
|
|
|
|
|
.SHELLFLAGS := -eu -o pipefail ${SHELLFLAGS} -c
|
2020-01-02 10:43:19 +01:00
|
|
|
MAKEFLAGS += --warn-undefined-variables
|
|
|
|
MAKEFLAGS += --no-builtin-rules
|
2020-03-22 19:52:56 +01:00
|
|
|
|
2020-03-25 02:49:49 +01:00
|
|
|
RUNARGS :=
|
2020-03-18 15:36:32 +01:00
|
|
|
MYPY_ARGS :=
|
2020-03-22 19:52:56 +01:00
|
|
|
FIND := $(if $(wildcard /bin/find),/bin/find,/usr/bin/find)
|
|
|
|
|
2020-03-17 05:11:49 +01:00
|
|
|
ifndef OS
|
|
|
|
OS := unknown
|
|
|
|
endif
|
|
|
|
|
|
|
|
# https://anki.tenderapp.com/discussions/beta-testing/1860-error-unused-type-ignore-comment
|
|
|
|
ifneq (${OS},Windows_NT)
|
2020-03-18 15:36:32 +01:00
|
|
|
MYPY_ARGS := --warn-unused-ignores
|
2020-03-17 05:11:49 +01:00
|
|
|
endif
|
2020-02-24 18:58:07 +01:00
|
|
|
|
2020-03-22 19:52:56 +01:00
|
|
|
.DELETE_ON_ERROR:
|
2020-01-02 10:43:19 +01:00
|
|
|
.SUFFIXES:
|
2020-02-23 03:21:12 +01:00
|
|
|
BLACKARGS := -t py36 anki tests setup.py tools/*.py --exclude='_pb2|buildinfo'
|
2020-01-06 06:27:59 +01:00
|
|
|
ISORTARGS := anki tests setup.py
|
2020-01-02 10:43:19 +01:00
|
|
|
|
2020-01-03 05:32:26 +01:00
|
|
|
$(shell mkdir -p .build ../dist)
|
2020-01-02 10:43:19 +01:00
|
|
|
|
|
|
|
PHONY: all
|
|
|
|
all: check
|
|
|
|
|
|
|
|
.build/run-deps: setup.py
|
2020-02-24 18:58:07 +01:00
|
|
|
python -m pip install -e .
|
2020-01-02 10:43:19 +01:00
|
|
|
@touch $@
|
|
|
|
|
|
|
|
.build/dev-deps: requirements.dev
|
2020-02-24 18:58:07 +01:00
|
|
|
python -m pip install -r requirements.dev
|
2020-01-02 10:43:19 +01:00
|
|
|
@touch $@
|
|
|
|
|
|
|
|
PROTODEPS := $(wildcard ../proto/*.proto)
|
|
|
|
|
|
|
|
.build/py-proto: .build/dev-deps $(PROTODEPS)
|
|
|
|
protoc --proto_path=../proto --python_out=anki --mypy_out=anki $(PROTODEPS)
|
2020-02-23 03:21:12 +01:00
|
|
|
perl -i'' -pe 's/from fluent_pb2/from anki.fluent_pb2/' anki/backend_pb2.pyi
|
|
|
|
perl -i'' -pe 's/import fluent_pb2/import anki.fluent_pb2/' anki/backend_pb2.py
|
2020-01-02 10:43:19 +01:00
|
|
|
@touch $@
|
|
|
|
|
2020-01-15 00:11:20 +01:00
|
|
|
.build/hooks: tools/genhooks.py tools/hookslib.py
|
2020-01-13 04:57:51 +01:00
|
|
|
python tools/genhooks.py
|
2020-03-16 19:53:10 +01:00
|
|
|
python -m black anki/hooks.py
|
2020-01-13 04:57:51 +01:00
|
|
|
@touch $@
|
|
|
|
|
2020-04-02 04:01:48 +02:00
|
|
|
BUILD_STEPS := .build/vernum .build/run-deps .build/dev-deps .build/py-proto anki/buildinfo.py .build/hooks
|
2020-01-02 10:43:19 +01:00
|
|
|
|
|
|
|
# Checking
|
|
|
|
######################
|
|
|
|
|
|
|
|
.PHONY: check
|
|
|
|
check: $(BUILD_STEPS) .build/mypy .build/test .build/fmt .build/imports .build/lint
|
|
|
|
|
|
|
|
.PHONY: fix
|
|
|
|
fix: $(BUILD_STEPS)
|
|
|
|
isort $(ISORTARGS)
|
2020-03-16 19:53:10 +01:00
|
|
|
python -m black $(BLACKARGS)
|
2020-01-02 10:43:19 +01:00
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
|
|
|
rm -rf .build anki.egg-info build dist
|
|
|
|
|
|
|
|
# Checking python
|
|
|
|
######################
|
|
|
|
|
2020-02-25 06:32:17 +01:00
|
|
|
CHECKDEPS := $(shell ${FIND} anki tests -name '*.py' | grep -v buildinfo.py)
|
2020-01-02 10:43:19 +01:00
|
|
|
|
|
|
|
.build/mypy: $(CHECKDEPS)
|
2020-03-18 15:36:32 +01:00
|
|
|
python -m mypy ${MYPY_ARGS} anki
|
2020-01-02 10:43:19 +01:00
|
|
|
@touch $@
|
|
|
|
|
|
|
|
.build/test: $(CHECKDEPS)
|
2020-01-08 06:52:51 +01:00
|
|
|
python -m pytest --durations=1 -s
|
2020-01-02 10:43:19 +01:00
|
|
|
@touch $@
|
|
|
|
|
|
|
|
.build/lint: $(CHECKDEPS)
|
2020-03-17 05:11:49 +01:00
|
|
|
python -m pylint -j 0 --rcfile=.pylintrc -f colorized \
|
|
|
|
--extension-pkg-whitelist=ankirspy anki tests setup.py
|
2020-01-02 10:43:19 +01:00
|
|
|
@touch $@
|
|
|
|
|
|
|
|
.build/imports: $(CHECKDEPS)
|
|
|
|
isort $(ISORTARGS) --check
|
|
|
|
@touch $@
|
|
|
|
|
|
|
|
.build/fmt: $(CHECKDEPS)
|
2020-03-16 19:53:10 +01:00
|
|
|
python -m black --check $(BLACKARGS)
|
2020-01-02 10:43:19 +01:00
|
|
|
@touch $@
|
|
|
|
|
|
|
|
# Building
|
|
|
|
######################
|
|
|
|
|
|
|
|
.PHONY: build
|
2020-04-07 02:56:41 +02:00
|
|
|
build: .build/build
|
|
|
|
|
|
|
|
.build/build: $(BUILD_STEPS) $(CHECKDEPS)
|
2020-01-15 01:07:39 +01:00
|
|
|
rm -rf dist build
|
2020-01-04 01:44:35 +01:00
|
|
|
python setup.py -q bdist_wheel
|
2020-01-03 05:32:26 +01:00
|
|
|
rsync -a dist/*.whl ../dist/
|
2020-04-07 02:56:41 +02:00
|
|
|
touch $@
|
2020-01-02 10:43:19 +01:00
|
|
|
|
|
|
|
# prepare code for running in place
|
|
|
|
.PHONY: develop
|
|
|
|
develop: $(BUILD_STEPS)
|
2020-01-03 06:15:18 +01:00
|
|
|
|
|
|
|
anki/buildinfo.py: ../meta/version ../meta/buildhash
|
|
|
|
echo "buildhash='$$(cat ../meta/buildhash)'" > $@
|
|
|
|
echo "version='$$(cat ../meta/version)'" >> $@
|
2020-04-02 04:01:48 +02:00
|
|
|
|
|
|
|
VER := $(shell cat ../meta/version)
|
|
|
|
.build/vernum: ../meta/version
|
|
|
|
sed -i.bak 's/.*automatically updated.*/ version="$(VER)", # automatically updated/' setup.py
|
|
|
|
rm setup.py.bak
|
|
|
|
@touch $@
|