Skip to content

Commit afc31ea

Browse files
committed
feat(Makefile): install clang-format and clang-tidy from PyPI
1 parent 6d1191a commit afc31ea

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

.github/workflows/lint.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,6 @@ jobs:
9898
9999
- name: clang-format
100100
run: |
101-
(
102-
source /etc/os-release
103-
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
104-
sudo add-apt-repository "deb http://apt.llvm.org/${UBUNTU_CODENAME} llvm-toolchain-${UBUNTU_CODENAME} main" --yes
105-
)
106-
sudo apt-get update && sudo apt-get install clang-format --yes
107101
make clang-format
108102
109103
- name: addlicense

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ FROM builder AS devel-builder
4848

4949
# Install extra dependencies
5050
RUN sudo apt-get update && \
51-
sudo apt-get install -y golang clang-format clang-tidy && \
51+
sudo apt-get install -y golang && \
5252
sudo chown -R "$(whoami):$(whoami)" "$(realpath /usr/lib/go)" && \
5353
sudo rm -rf /var/lib/apt/lists/*
5454

Makefile

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
print-% : ; @echo $* = $($*)
1+
print-%: ; @echo $* = $($*)
22
PROJECT_NAME = torchopt
33
COPYRIGHT = "MetaOPT Team. All Rights Reserved."
44
PROJECT_PATH = $(PROJECT_NAME)
@@ -10,7 +10,6 @@ CUDA_FILES = $(shell find $(SOURCE_FOLDERS) -type f -name "*.cuh" -o -name "
1010
COMMIT_HASH = $(shell git log -1 --format=%h)
1111
PATH := $(HOME)/go/bin:$(PATH)
1212
PYTHON ?= $(shell command -v python3 || command -v python)
13-
CLANG_FORMAT ?= $(shell command -v clang-format-17 || command -v clang-format)
1413
PYTESTOPTS ?=
1514

1615
.PHONY: default
@@ -22,7 +21,7 @@ install:
2221
install-editable:
2322
$(PYTHON) -m pip install --upgrade pip
2423
$(PYTHON) -m pip install --upgrade setuptools wheel
25-
$(PYTHON) -m pip install torch numpy pybind11
24+
$(PYTHON) -m pip install torch numpy pybind11 cmake
2625
USE_FP16=ON TORCH_CUDA_ARCH_LIST=Auto $(PYTHON) -m pip install -vvv --no-build-isolation --editable .
2726

2827
install-e: install-editable # alias
@@ -95,12 +94,10 @@ cpplint-install:
9594
$(call check_pip_install,cpplint)
9695

9796
clang-format-install:
98-
command -v clang-format-17 || command -v clang-format || \
99-
sudo apt-get install -y clang-format-17 || \
100-
sudo apt-get install -y clang-format
97+
$(call check_pip_install,clang-format)
10198

10299
clang-tidy-install:
103-
command -v clang-tidy || sudo apt-get install -y clang-tidy
100+
$(call check_pip_install,clang-tidy)
104101

105102
go-install:
106103
# requires go >= 1.16
@@ -112,6 +109,7 @@ addlicense-install: go-install
112109
# Tests
113110

114111
pytest: test-install
112+
$(PYTHON) -m pytest --version
115113
cd tests && $(PYTHON) -c 'import $(PROJECT_PATH)' && \
116114
$(PYTHON) -m pytest --verbose --color=yes --durations=0 \
117115
--cov="$(PROJECT_PATH)" --cov-config=.coveragerc --cov-report=xml --cov-report=term-missing \
@@ -122,30 +120,39 @@ test: pytest
122120
# Python linters
123121

124122
pylint: pylint-install
123+
$(PYTHON) -m pylint --version
125124
$(PYTHON) -m pylint $(PROJECT_PATH)
126125

127126
flake8: flake8-install
127+
$(PYTHON) -m flake8 --version
128128
$(PYTHON) -m flake8 --count --show-source --statistics
129129

130130
py-format: py-format-install
131+
$(PYTHON) -m isort --version
132+
$(PYTHON) -m black --version
131133
$(PYTHON) -m isort --project $(PROJECT_PATH) --check $(PYTHON_FILES) && \
132134
$(PYTHON) -m black --check $(PYTHON_FILES) tutorials
133135

134136
ruff: ruff-install
137+
$(PYTHON) -m ruff --version
135138
$(PYTHON) -m ruff check .
136139

137140
ruff-fix: ruff-install
141+
$(PYTHON) -m ruff --version
138142
$(PYTHON) -m ruff check . --fix --exit-non-zero-on-fix
139143

140144
mypy: mypy-install
145+
$(PYTHON) -m mypy --version
141146
$(PYTHON) -m mypy $(PROJECT_PATH) --install-types --non-interactive
142147

143148
pre-commit: pre-commit-install
149+
$(PYTHON) -m pre_commit --version
144150
$(PYTHON) -m pre_commit run --all-files
145151

146152
# C++ linters
147153

148154
cmake-configure: cmake-install
155+
cmake --version
149156
cmake -S . -B cmake-build-debug \
150157
-DCMAKE_BUILD_TYPE=Debug \
151158
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
@@ -157,12 +164,15 @@ cmake-build: cmake-configure
157164
cmake: cmake-build
158165

159166
cpplint: cpplint-install
167+
$(PYTHON) -m cpplint --version
160168
$(PYTHON) -m cpplint $(CXX_FILES) $(CUDA_FILES)
161169

162170
clang-format: clang-format-install
163-
$(CLANG_FORMAT) --style=file -i $(CXX_FILES) $(CUDA_FILES) -n --Werror
171+
clang-format --version
172+
clang-format --style=file -i $(CXX_FILES) $(CUDA_FILES) -n --Werror
164173

165174
clang-tidy: clang-tidy-install cmake-configure
175+
clang-tidy --version
166176
clang-tidy -p=cmake-build-debug $(CXX_FILES)
167177

168178
# Documentation

tests/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ doc8
2525
pydocstyle[toml]
2626
pyenchant
2727
cpplint
28+
clang-format
29+
clang-tidy
2830
pre-commit

0 commit comments

Comments
 (0)