-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
64 lines (51 loc) · 1.93 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
SRC = twc
DOCS = docs
DIST = dist
ZIPAPP = .zipapp
.PHONY: docs
all: version format lint build zipapp docs
help:
@echo Targets:
@echo ' all run format, lint, build, zipapp, docs'
@echo ' version apply version from pyproject.toml to twc module'
@echo ' format run code formatter'
@echo ' format-dryrun run code formatter in dry-run mode'
@echo ' lint run code linter'
@echo ' build build twc-cli Python package'
@echo ' zipapp build twc-cli package in zipapp format'
@echo ' publish-pypi publish twc-cli Python package on PyPI'
@echo ' publish-testpypi publish twc-cli Python package on test PyPI'
@echo ' docs build markdown documentation'
@echo ' clean clean temporary files (including build artifacts)'
version:
VERSION=$$(awk '/^version/{print $$3}' pyproject.toml); \
sed "s/__version__ =.*/__version__ = $$VERSION/" -i $(SRC)/__version__.py;
format:
poetry run black $(SRC)
format-dryrun:
poetry run black --diff --color $(SRC)
lint:
poetry run pylint $(SRC)
build:
poetry build
docs:
poetry run python mkdocs > $(DOCS)/ru/CLI_REFERENCE.md
publish-testpypi:
poetry publish -r testpypi
publish-pypi:
poetry publish
clean:
[ -d .testenv/ ] && rm -rf .testenv/ || true
[ -d dist/ ] && rm -rf dist/ || true
find . -type d -name __pycache__ -exec rm -rf {} \; > /dev/null 2>&1 || true
zipapp:
mkdir -p $(DIST)
mkdir -p $(ZIPAPP)
python -m venv $(ZIPAPP)-env
cp -ar twc $(ZIPAPP)
poetry export --without-hashes -o $(ZIPAPP)/requirements.txt
. $(ZIPAPP)-env/bin/activate; pip install --target $(ZIPAPP) -r $(ZIPAPP)/requirements.txt > /dev/null
find $(ZIPAPP) -type d -name "*.dist-info" -exec rm -rf {} \; > /dev/null 2>&1 || true
version=$$(awk '/version/{print substr($$3, 2, 5)}' pyproject.toml); python -m zipapp -c -m twc.__main__:cli -p '/usr/bin/env python3' -o $(DIST)/twc_cli-$${version}.pyz $(ZIPAPP)
[ -d $(ZIPAPP) ] && rm -rf $(ZIPAPP) || true
[ -d $(ZIPAPP)-env ] && rm -rf $(ZIPAPP)-env || true