Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(setup): rewrite packaging #24

Merged
merged 23 commits into from
Jul 10, 2022
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift click to select a range
a70220e
chore(setup): rewrite packaging
XuehaiPan Jul 7, 2022
0a1ccb8
chore: fix file modes
XuehaiPan Jul 7, 2022
01df51e
docs(README): update README
XuehaiPan Jul 7, 2022
c5d6b80
style: format code with yapf
XuehaiPan Jul 7, 2022
fbe3b12
style: reindent license
XuehaiPan Jul 7, 2022
fdf5077
chore(workflow): install CUDA Toolkit in GitHub Action
XuehaiPan Jul 7, 2022
857338a
feat(workflow): build PyPI wheels for Python 3.7 / 3.8 / 3.9 / 3.10
XuehaiPan Jul 7, 2022
b9f9ebe
refactor(setup): use pybind11 PyPI package rather than git submodule
XuehaiPan Jul 7, 2022
ca92f9f
chore(setup): add dependency `typing-extensions`
XuehaiPan Jul 7, 2022
294f7ed
chore(workflow): update workflow trigger
XuehaiPan Jul 7, 2022
bf14292
docs: use HTTPS URL for git clone
XuehaiPan Jul 7, 2022
2e80b67
fix(tests): update requirements.txt
XuehaiPan Jul 7, 2022
4ab4efa
chore(setup): remove deprecated dependency `distutils`
XuehaiPan Jul 7, 2022
9580a96
test: disable CUDA tests if no GPU available
XuehaiPan Jul 8, 2022
8640b81
chore(workflow): use Python 3.7 in tests
XuehaiPan Jul 8, 2022
9730748
refactor(Makefile): update Makefile
XuehaiPan Jul 8, 2022
3dcd29c
style: format CXX code
XuehaiPan Jul 8, 2022
2f4e44f
chore(tests): test with CUDA Toolkit 11.3
XuehaiPan Jul 8, 2022
ad069a4
feat(CMakeLists.txt): auto detect nvcc arch flags
XuehaiPan Jul 8, 2022
bce754b
chore(workflow): set timeout
XuehaiPan Jul 8, 2022
2dba710
docs: update sphinx docs
XuehaiPan Jul 8, 2022
de1bb87
chore: use CamelCased URL paths
XuehaiPan Jul 9, 2022
5597da7
chore: add conda recipe
XuehaiPan Jul 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(Makefile): update Makefile
  • Loading branch information
XuehaiPan committed Jul 10, 2022
commit 9730748c3ea58bd8690bbe05c8e39a20ebd6f899
128 changes: 74 additions & 54 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,33 1,51 @@
print-% : ; @echo $* = $($*)
SHELL = /bin/bash
PROJECT_NAME = torchopt
PROJECT_PATH = ${PROJECT_NAME}/
PROJECT_FOLDER = $(PROJECT_NAME) examples include src tests
PYTHON_FILES = $(shell find examples torchopt tests -type f -name "*.py" -o -name "*.pyi")
CPP_FILES = $(shell find . -type f -name "*.h" -o -name "*.cpp" -o -name "*.cuh" -o -name "*.cu")
COMMIT_HASH = $(shell git log -1 --format=%h)
COPYRIGHT = "MetaOPT Team. All Rights Reserved."
PROJECT_PATH = ${PROJECT_NAME}
SHELL = /bin/bash
SOURCE_FOLDERS = $(PROJECT_PATH) examples include src tests
PYTHON_FILES = $(shell find $(SOURCE_FOLDERS) -type f -name "*.py" -o -name "*.pyi")
CXX_FILES = $(shell find $(SOURCE_FOLDERS) -type f -name "*.h" -o -name "*.cpp" -o -name "*.cuh" -o -name "*.cu")
COMMIT_HASH = $(shell git log -1 --format=%h)
PATH := $(HOME)/go/bin:$(PATH)
PYTHON ?= $(shell command -v python3 || command -v python)

.PHONY: default
default: install

# installation
install:
$(PYTHON) -m pip install .

check_install = python3 -c "import $(1)" || (cd && pip3 install $(1) --upgrade && cd -)
check_install_extra = python3 -c "import $(1)" || (cd && pip3 install $(2) --upgrade && cd -)
# Tools Installation

check_pip_install = $(PYTHON) -m pip show $(1) &>/dev/null || (cd && $(PYTHON) -m pip install $(1) --upgrade)
check_pip_install_extra = $(PYTHON) -m pip show $(1) &>/dev/null || (cd && $(PYTHON) -m pip install $(2) --upgrade)

flake8-install:
$(call check_install, flake8)
$(call check_install_extra, bugbear, flake8_bugbear)
$(call check_pip_install,flake8)
$(call check_pip_install_extra,bugbear,flake8_bugbear)

py-format-install:
$(call check_install, isort)
$(call check_install, yapf)
$(call check_pip_install,isort)
$(call check_pip_install,yapf)

mypy-install:
$(call check_install, mypy)
$(call check_pip_install,mypy)

docs-install:
$(call check_pip_install,pydocstyle)
$(call check_pip_install,doc8)
$(call check_pip_install,sphinx)
$(call check_pip_install,sphinx_rtd_theme)
$(call check_pip_install_extra,sphinxcontrib.spelling,sphinxcontrib.spelling pyenchant)

pytest-install:
$(call check_pip_install,pytest)
$(call check_pip_install,pytest_cov)
$(call check_pip_install,pytest_xdist)

cpplint-install:
$(call check_install, cpplint)
$(call check_pip_install,cpplint)

clang-format-install:
command -v clang-format-11 || sudo apt-get install -y clang-format-11
Expand All @@ -42,65 60,67 @@ go-install:
addlicense-install: go-install
command -v addlicense || go install github.com/google/addlicense@latest

doc-install:
$(call check_install, pydocstyle)
$(call check_install, doc8)
$(call check_install, sphinx)
$(call check_install, sphinx_rtd_theme)
$(call check_install_extra, sphinxcontrib.spelling, sphinxcontrib.spelling pyenchant)

pytest-install:
$(call check_install, pytest)
$(call check_install, pytest_cov)
$(call check_install, pytest_xdist)


# test
# Tests

pytest: pytest-install
pytest tests --cov ${PROJECT_PATH} --durations 0 -v --cov-report term-missing --color=yes
cd tests && $(PYTHON) -m pytest unit --cov ${PROJECT_PATH} --durations 0 -v --cov-report term-missing --color=yes

test: pytest

# python linter
# Python linters

flake8: flake8-install
flake8 $(PYTHON_FILES) --count --select=E9,F63,F7,F82,E225,E251 --show-source --statistics
$(PYTHON) -m flake8 $(PYTHON_FILES) --count --select=E9,F63,F7,F82,E225,E251 --show-source --statistics

py-format: py-format-install
isort --project torchopt --check $(PYTHON_FILES) && \
yapf --in-place --recursive $(PYTHON_FILES)
$(PYTHON) -m isort --project torchopt --check $(PYTHON_FILES) && \
$(PYTHON) -m yapf --in-place --recursive $(PYTHON_FILES)

mypy: mypy-install
mypy $(PROJECT_NAME)
$(PYTHON) -m mypy $(PROJECT_NAME)

# c linter
# C linters

cpplint: cpplint-install
cpplint $(CPP_FILES)
$(PYTHON) -m cpplint $(CXX_FILES)

clang-format: clang-format-install
clang-format-11 --style=file -i $(CPP_FILES) -n --Werror
clang-format-11 --style=file -i $(CXX_FILES) -n --Werror

# documentation
# Documentation

addlicense: addlicense-install
addlicense -c $(COPYRIGHT) -l apache -y 2022 -check $(PROJECT_FOLDER)
addlicense -c $(COPYRIGHT) -l apache -y 2022 -check $(SOURCE_FOLDERS)

docstyle: docs-install
$(PYTHON) -m pydocstyle $(PROJECT_NAME) && doc8 docs && make -C docs html SPHINXOPTS="-W"

docs: docs-install
make -C docs html && cd _build/html && $(PYTHON) -m http.server

spelling: docs-install
make -C docs spelling SPHINXOPTS="-W"

clean-docs:
make -C docs clean

docstyle: doc-install
pydocstyle $(PROJECT_NAME) && doc8 docs && cd docs && make html SPHINXOPTS="-W"
# Utility functions

doc: doc-install
cd docs && make html && cd _build/html && python3 -m http.server
lint: flake8 py-format mypy clang-format cpplint addlicense

spelling: doc-install
cd docs && make spelling SPHINXOPTS="-W"
format: py-format-install clang-format-install addlicense-install
$(PYTHON) -m isort --project torchopt $(PYTHON_FILES)
$(PYTHON) -m yapf --in-place --recursive $(PYTHON_FILES)
clang-format-11 -style=file -i $(CXX_FILES)
addlicense -c $(COPYRIGHT) -l apache -y 2022 $(SOURCE_FOLDERS)

doc-clean:
cd docs && make clean
clean-py:
find . -type f -name '*.py[co]' -delete
find . -depth -type d -name ".mypy_cache" -exec rm -r "{}"
find . -depth -type d -name ".pytest_cache" -exec rm -r "{}"

lint: flake8 py-format clang-format cpplint mypy
clean-build:
rm -rf build/ dist/
rm -rf *.egg-info .eggs

format: py-format-install clang-format-install
isort $(PYTHON_FILES)
yapf -ir $(PYTHON_FILES)
clang-format-11 -style=file -i $(CPP_FILES)
addlicense -c $(COPYRIGHT) -l apache -y 2022 $(PROJECT_FOLDER)
clean: clean-py clean-build clean-docs