forked from sail-sg/envpool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
191 lines (137 loc) · 6.98 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
SHELL = /bin/bash
PROJECT_NAME = envpool
PROJECT_FOLDER = $(PROJECT_NAME) third_party examples benchmark
PYTHON_FILES = $(shell find . -type f -name "*.py")
CPP_FILES = $(shell find $(PROJECT_NAME) -type f -name "*.h" -o -name "*.cc")
BAZEL_FILES = $(shell find . -type f -name "*BUILD" -o -name "*.bzl")
COMMIT_HASH = $(shell git log -1 --format=%h)
COPYRIGHT = "Garena Online Private Limited"
BAZELOPT =
DATE = $(shell date "+%Y-%m-%d")
DOCKER_TAG = $(DATE)-$(COMMIT_HASH)
DOCKER_USER = trinkle23897
PATH := $(HOME)/go/bin:$(PATH)
# installation
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 -)
flake8-install:
$(call check_install, flake8)
$(call check_install_extra, bugbear, flake8_bugbear)
py-format-install:
$(call check_install, isort)
$(call check_install, yapf)
mypy-install:
$(call check_install, mypy)
cpplint-install:
$(call check_install, cpplint)
clang-format-install:
command -v clang-format || sudo apt-get install -y clang-format
clang-tidy-install:
command -v clang-tidy || sudo apt-get install -y clang-tidy
go-install:
# requires go >= 1.16
command -v go || (sudo apt-get install -y golang-1.18 && sudo ln -sf /usr/lib/go-1.18/bin/go /usr/bin/go)
bazel-install: go-install
command -v bazel || (go install github.com/bazelbuild/bazelisk@latest && ln -sf $(HOME)/go/bin/bazelisk $(HOME)/go/bin/bazel)
buildifier-install: go-install
command -v buildifier || go install github.com/bazelbuild/buildtools/buildifier@latest
addlicense-install: go-install
command -v addlicense || go install github.com/google/addlicense@latest
doc-install:
$(call check_install, pydocstyle)
$(call check_install_extra, doc8, "doc8<1")
$(call check_install, sphinx)
$(call check_install, sphinx_rtd_theme)
$(call check_install_extra, sphinxcontrib.spelling, sphinxcontrib.spelling pyenchant)
auditwheel-install:
$(call check_install_extra, auditwheel, auditwheel typed-ast patchelf)
# python linter
flake8: flake8-install
flake8 $(PYTHON_FILES) --count --show-source --statistics
py-format: py-format-install
isort --check $(PYTHON_FILES) && yapf -r -d $(PYTHON_FILES)
mypy: mypy-install
mypy $(PROJECT_NAME)
# c++ linter
cpplint: cpplint-install
cpplint $(CPP_FILES)
clang-format: clang-format-install
clang-format --style=file -i $(CPP_FILES) -n --Werror
# bazel file linter
buildifier: buildifier-install
buildifier -r -lint=warn $(BAZEL_FILES)
# bazel build/test
bazel-pip-requirement-dev:
cd third_party/pip_requirements && (cmp requirements.txt requirements-dev.txt || ln -sf requirements-dev.txt requirements.txt)
bazel-pip-requirement-release:
cd third_party/pip_requirements && (cmp requirements.txt requirements-release.txt || ln -sf requirements-release.txt requirements.txt)
clang-tidy: clang-tidy-install bazel-pip-requirement-dev
bazel build $(BAZELOPT) //... --config=clang-tidy --config=test
bazel-debug: bazel-install bazel-pip-requirement-dev
bazel --output_user_root=$(TEMPDIR) run --repository_cache=$(TEMPDIR) --sandbox_writable_path=$(CCACHEDIR) $(BAZELOPT) //:setup --config=debug -- bdist_wheel
mkdir -p dist
cp bazel-bin/setup.runfiles/$(PROJECT_NAME)/dist/*.whl ./dist
bazel-build: bazel-install bazel-pip-requirement-dev
bazel --output_user_root=$(TEMPDIR) run --repository_cache=$(TEMPDIR) --sandbox_writable_path=$(CCACHEDIR) $(BAZELOPT) //:setup --config=test -- bdist_wheel
mkdir -p dist
cp bazel-bin/setup.runfiles/$(PROJECT_NAME)/dist/*.whl ./dist
bazel-release: bazel-install bazel-pip-requirement-release
bazel --output_user_root=$(TEMPDIR) run --repository_cache=$(TEMPDIR) --sandbox_writable_path=$(CCACHEDIR) $(BAZELOPT) //:setup --config=release -- bdist_wheel
mkdir -p dist
cp bazel-bin/setup.runfiles/$(PROJECT_NAME)/dist/*.whl ./dist
bazel-test: bazel-install bazel-pip-requirement-dev
bazel --output_user_root=$(TEMPDIR) test --repository_cache=$(TEMPDIR) --sandbox_writable_path=$(CCACHEDIR) --test_output=all $(BAZELOPT) //... --config=test --spawn_strategy=local --color=yes
bazel-clean: bazel-install
bazel clean --expunge
# documentation
addlicense: addlicense-install
addlicense -c $(COPYRIGHT) -l apache -y 2023 -check $(PROJECT_FOLDER)
docstyle: doc-install
pydocstyle $(PROJECT_NAME) && doc8 docs && cd docs && make html SPHINXOPTS="-W"
doc: doc-install
cd docs && make html && cd _build/html && python3 -m http.server
spelling: doc-install
cd docs && make spelling SPHINXOPTS="-W"
doc-clean:
cd docs && make clean
doc-benchmark:
pandoc benchmark/README.md --from markdown --to rst -s -o docs/content/benchmark.rst --columns 1000
cd benchmark && ./plot.py --suffix png && mv *.png ../docs/_static/images/throughput
lint: buildifier flake8 py-format clang-format cpplint clang-tidy mypy docstyle spelling
format: py-format-install clang-format-install buildifier-install addlicense-install
isort $(PYTHON_FILES)
yapf -ir $(PYTHON_FILES)
clang-format -style=file -i $(CPP_FILES)
buildifier -r -lint=fix $(BAZEL_FILES)
addlicense -c $(COPYRIGHT) -l apache -y 2023 $(PROJECT_FOLDER)
# Build docker images
docker-ci:
docker build --network=host -t $(PROJECT_NAME):$(DOCKER_TAG) -f docker/dev.dockerfile .
echo successfully build docker image with tag $(PROJECT_NAME):$(DOCKER_TAG)
docker-ci-push: docker-ci
docker tag $(PROJECT_NAME):$(DOCKER_TAG) $(DOCKER_USER)/$(PROJECT_NAME):$(DOCKER_TAG)
docker push $(DOCKER_USER)/$(PROJECT_NAME):$(DOCKER_TAG)
docker-ci-launch: docker-ci
docker run --network=host -v /home/ubuntu:/home/github-action --shm-size=4gb -it $(PROJECT_NAME):$(DOCKER_TAG) bash
docker-dev: docker-ci
docker run --network=host -v /:/host -v $(shell pwd):/app -v $(HOME)/.cache:/root/.cache --shm-size=4gb -it $(PROJECT_NAME):$(DOCKER_TAG) zsh
# for mainland China
docker-dev-cn:
docker build --network=host -t $(PROJECT_NAME):$(DOCKER_TAG) -f docker/dev-cn.dockerfile .
echo successfully build docker image with tag $(PROJECT_NAME):$(DOCKER_TAG)
docker run --network=host -v /:/host -v $(shell pwd):/app -v $(HOME)/.cache:/root/.cache --shm-size=4gb -it $(PROJECT_NAME):$(DOCKER_TAG) zsh
docker-release:
docker build --network=host -t $(PROJECT_NAME)-release:$(DOCKER_TAG) -f docker/release.dockerfile .
echo successfully build docker image with tag $(PROJECT_NAME)-release:$(DOCKER_TAG)
docker-release-push: docker-release
docker tag $(PROJECT_NAME)-release:$(DOCKER_TAG) $(DOCKER_USER)/$(PROJECT_NAME)-release:$(DOCKER_TAG)
docker push $(DOCKER_USER)/$(PROJECT_NAME)-release:$(DOCKER_TAG)
docker-release-launch: docker-release
docker run --network=host -v /:/host -v $(shell pwd):/app -v $(HOME)/.cache:/root/.cache --shm-size=4gb -it $(PROJECT_NAME)-release:$(DOCKER_TAG) zsh
pypi-wheel: auditwheel-install bazel-release
ls dist/*.whl -Art | tail -n 1 | xargs auditwheel repair --plat manylinux_2_24_x86_64
release-test1:
cd envpool && python3 make_test.py
release-test2:
cd examples && python3 make_env.py && python3 env_step.py
release-test: release-test1 release-test2