Skip to content

Commit 3042246

Browse files
feat(Makefile): add make format (#222)
1 parent 5b0bfc2 commit 3042246

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

Makefile

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
print-% : ; @echo $* = $($*)
2+
PROJECT_NAME = camel
3+
COPYRIGHT = "@ CAMEL-AI.org. All Rights Reserved."
4+
PROJECT_PATH = $(PROJECT_NAME)
5+
SHELL = /bin/bash
6+
SOURCE_FOLDERS = $(PROJECT_PATH) apps docs examples licenses test
7+
PYTHON_FILES = $(shell find $(SOURCE_FOLDERS) -type f -name "*.py" -o -name "*.pyi")
8+
COMMIT_HASH = $(shell git log -1 --format=%h)
9+
PATH := $(HOME)/go/bin:$(PATH)
10+
PYTHON ?= $(shell command -v python3 || command -v python)
11+
PYTESTOPTS ?=
12+
13+
.PHONY: default
14+
default: install
15+
16+
install:
17+
$(PYTHON) -m pip install -vvv .
18+
19+
install-editable:
20+
$(PYTHON) -m pip install --upgrade pip
21+
$(PYTHON) -m pip install -vvv --no-build-isolation --editable .
22+
23+
install-e: install-editable # alias
24+
25+
uninstall:
26+
$(PYTHON) -m pip uninstall -y $(PROJECT_NAME)
27+
28+
build:
29+
$(PYTHON) -m pip install --upgrade pip
30+
$(PYTHON) -m pip install --upgrade setuptools wheel build
31+
$(PYTHON) -m build
32+
33+
# Tools Installation
34+
35+
check_pip_install = $(PYTHON) -m pip show $(1) &>/dev/null || (cd && $(PYTHON) -m pip install $(1) --upgrade)
36+
check_pip_install_extra = $(PYTHON) -m pip show $(1) &>/dev/null || (cd && $(PYTHON) -m pip install $(2) --upgrade)
37+
38+
pylint-install:
39+
$(call check_pip_install_extra,pylint,pylint[spelling])
40+
$(call check_pip_install,pyenchant)
41+
42+
flake8-install:
43+
$(call check_pip_install,flake8)
44+
$(call check_pip_install,flake8-bugbear)
45+
$(call check_pip_install,flake8-comprehensions)
46+
$(call check_pip_install,flake8-docstrings)
47+
$(call check_pip_install,flake8-pyi)
48+
$(call check_pip_install,flake8-simplify)
49+
50+
py-format-install:
51+
$(call check_pip_install,isort)
52+
53+
ruff-install:
54+
$(call check_pip_install,ruff)
55+
56+
mypy-install:
57+
$(call check_pip_install,mypy)
58+
59+
pre-commit-install:
60+
$(call check_pip_install,pre-commit)
61+
$(PYTHON) -m pre_commit install --install-hooks
62+
63+
docs-install:
64+
$(call check_pip_install_extra,pydocstyle,pydocstyle[toml])
65+
$(call check_pip_install,doc8)
66+
$(call check_pip_install,sphinx)
67+
$(call check_pip_install,sphinx-rtd-theme)
68+
$(call check_pip_install,sphinx-autoapi)
69+
$(call check_pip_install,sphinx-autobuild)
70+
$(call check_pip_install,sphinx-copybutton)
71+
$(call check_pip_install,sphinxcontrib-katex)
72+
$(call check_pip_install,sphinxcontrib-bibtex)
73+
$(call check_pip_install,sphinx-autodoc-typehints)
74+
$(call check_pip_install,myst-nb)
75+
$(call check_pip_install_extra,sphinxcontrib-spelling,sphinxcontrib-spelling pyenchant)
76+
77+
pytest-install:
78+
$(call check_pip_install,pytest)
79+
$(call check_pip_install,pytest-cov)
80+
$(call check_pip_install,pytest-xdist)
81+
82+
test-install: pytest-install
83+
$(PYTHON) -m pip install --requirement tests/requirements.txt
84+
85+
# Python linters
86+
87+
pylint: pylint-install
88+
$(PYTHON) -m pylint $(PROJECT_PATH)
89+
90+
flake8: flake8-install
91+
$(PYTHON) -m flake8 --count --show-source --statistics
92+
93+
py-format: py-format-install
94+
$(PYTHON) -m isort --project $(PROJECT_PATH) --check $(PYTHON_FILES) && \
95+
$(PYTHON) -m yapf -dr $(PYTHON_FILES)
96+
97+
ruff: ruff-install
98+
$(PYTHON) -m ruff check .
99+
100+
ruff-fix: ruff-install
101+
$(PYTHON) -m ruff check . --fix --exit-non-zero-on-fix
102+
103+
mypy: mypy-install
104+
$(PYTHON) -m mypy $(PROJECT_PATH) --install-types --non-interactive --namespace-packages
105+
106+
pre-commit: pre-commit-install
107+
$(PYTHON) -m pre_commit run --all-files
108+
109+
# Utility functions
110+
111+
format: py-format-install
112+
$(PYTHON) -m yapf -ir $(PYTHON_FILES)
113+
$(PYTHON) -m isort --project $(PROJECT_PATH) $(PYTHON_FILES)
114+
$(PYTHON) -m ruff check . --fix --exit-zero
115+
116+
clean-py:
117+
find . -type f -name '*.py[co]' -delete
118+
find . -depth -type d -name "__pycache__" -exec rm -r "{}" +
119+
find . -depth -type d -name ".ruff_cache" -exec rm -r "{}" +
120+
find . -depth -type d -name ".mypy_cache" -exec rm -r "{}" +
121+
find . -depth -type d -name ".pytest_cache" -exec rm -r "{}" +
122+
rm tests/.coverage
123+
rm tests/coverage.xml
124+
125+
clean-build:
126+
rm -rf build/ dist/
127+
rm -rf *.egg-info .eggs
128+
129+
clean: clean-py clean-build clean-docs

0 commit comments

Comments
 (0)