-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
139 lines (108 loc) · 3.92 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# isort . && black . && bandit -r . && pylint && pre-commit run --all-files
# Get changed files
FILES := $(wildcard **/*.py)
# if you wrap everything in poetry run, it runs slower.
ifeq ($(origin VIRTUAL_ENV),undefined)
VENV := poetry run
else
VENV :=
endif
poetry.lock: pyproject.toml
@echo "Installing dependencies"
@poetry install --with dev
clean-pyc:
@echo "Removing compiled files"
@find ai_shell -name '*.pyc' -exec rm -f {} + || true
@find ai_shell -name '*.pyo' -exec rm -f {} + || true
@find ai_shell -name '__pycache__' -exec rm -fr {} + || true
clean-test:
@echo "Removing coverage data"
@rm -f .coverage || true
@rm -f .coverage.* || true
clean: clean-pyc clean-test
# tests can't be expected to pass if dependencies aren't installed.
# tests are often slow and linting is fast, so run tests on linted code.
test: clean .build_history/pylint .build_history/bandit poetry.lock
@echo "Running unit tests"
$(VENV) pytest --doctest-modules ai_shell ai_todo
# $(VENV) python -m unittest discover
$(VENV) py.test tests --cov=ai_shell --cov-report=html --cov-fail-under 50
.build_history:
@mkdir -p .build_history
.build_history/isort: .build_history $(FILES)
@echo "Formatting imports"
$(VENV) isort .
@touch .build_history/isort
.PHONY: isort
isort: .build_history/isort
.build_history/black: .build_history .build_history/isort $(FILES)
@echo "Formatting code"
$(VENV) black ai_shell --exclude .venv
$(VENV) black tests --exclude .venv
# $(VENV) black scripts --exclude .venv
@touch .build_history/black
.PHONY: black
black: .build_history/black
.build_history/pre-commit: .build_history .build_history/isort .build_history/black
@echo "Pre-commit checks"
$(VENV) pre-commit run --all-files
@touch .build_history/pre-commit
.PHONY: pre-commit
pre-commit: .build_history/pre-commit
.build_history/bandit: .build_history $(FILES)
@echo "Security checks"
$(VENV) bandit ai_shell -r
@touch .build_history/bandit
.PHONY: bandit
bandit: .build_history/bandit
.PHONY: pylint
.build_history/pylint: .build_history .build_history/isort .build_history/black $(FILES)
@echo "Linting with pylint"
$(VENV) ruff check --fix
$(VENV) pylint ai_shell --fail-under 9.7
@touch .build_history/pylint
# for when using -j (jobs, run in parallel)
.NOTPARALLEL: .build_history/isort .build_history/black
check: mypy test pylint bandit pre-commit
.PHONY: publish_test
publish_test:
rm -rf dist && poetry version minor && poetry build && twine upload -r testpypi dist/*
.PHONY: publish
publish: test
rm -rf dist && poetry build
.PHONY: mypy
mypy:
$(VENV) mypy ai_shell --ignore-missing-imports --check-untyped-defs
.PHONY:
docker:
docker build -t ai_shell -f Dockerfile .
#check_docs:
# interrogate ai_shell
# pydoctest --config .pydoctest.json | grep -v "__init__" | grep -v "ToolKit" | grep -v "__main__" | grep -v "Unable to parse"
#
#make_docs:
# pdoc ai_shell ai_todo --html -o docs --force
.PHONY: gen_code
gen_code:
echo "Should check mypy and docstrings first."
cd ai_shell && cd code_generate && python generate_schema.py
cd ai_shell && cd code_generate && python generate_cli.py
cd ai_shell && cd code_generate && python generate_toolkit.py
pwd
check_docs:
$(VENV) interrogate ai_shell --verbose
$(VENV) pydoctest --config .pydoctest.json | grep -v "__init__" | grep -v "__main__" | grep -v "Unable to parse" | grep -v "openai_toolkit"
make_docs:
pdoc ai_shell --html -o docs --force
check_md:
$(VENV) mdformat README.md docs/*.md
# $(VENV) linkcheckMarkdown README.md # it is attempting to validate ssl certs
$(VENV) markdownlint README.md --config .markdownlintrc
check_spelling:
$(VENV) pylint ai_shell --enable C0402 --rcfile=.pylintrc_spell
$(VENV) codespell README.md --ignore-words=private_dictionary.txt
$(VENV) codespell ai_shell --ignore-words=private_dictionary.txt
check_changelog:
# pipx install keepachangelog-manager
$(VENV) changelogmanager validate
check_all: check_docs check_md check_spelling check_changelog