Skip to content

Commit 3f3e18c

Browse files
committed
feat: add support for protobuf 4, update packaging and CI
Changes: 1. Update github actions base image to 22.04 since github is retiring 20.04. 2. Add DGP_PROTO_VERISON for controlling proto version. 3. Remove previously generated old pb2 files from tracking. 4. Fix docker container build and test.
1 parent 2bcb53d commit 3f3e18c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+309
-8234
lines changed

.github/workflows/build-docker.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ name: build-docker
33
on:
44
push:
55
branches:
6-
- 'master'
6+
- "master"
77
tags:
8-
- '*'
8+
- "*"
99

1010
env:
1111
REGISTRY: ghcr.io
1212
IMAGE_NAME: ${{ github.repository }}
1313

1414
jobs:
1515
build-and-push-image:
16-
runs-on: ubuntu-20.04
16+
runs-on: ubuntu-22.04
1717
permissions:
1818
contents: read
1919
packages: write

.github/workflows/coverage.yml

+13-8
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,27 @@ name: coverage
22
on:
33
pull_request:
44
branches:
5-
- 'master'
5+
- "master"
66
push:
77
branches:
8-
- 'master'
8+
- "master"
99
jobs:
1010
code-coverage:
11-
runs-on: ubuntu-20.04
11+
runs-on: ubuntu-22.04
1212
env:
1313
ENVIRONMENT: TEST_RUNNER
14-
OS: ubuntu-20.04
15-
PYTHON: '3.9'
14+
OS: ubuntu-22.04
15+
PYTHON: "3.9"
1616
COVERAGE_TOTAL: 49 # Coverage threshold percentage
17+
strategy:
18+
matrix:
19+
protobuf_major_version: [3, 4]
1720
steps:
1821
- name: Checkout (admin token)
1922
if: ${{github.event_name != 'pull_request'}} # We don't want to use the admin token for PR flows
2023
uses: actions/checkout@master
2124
with:
22-
token: '${{ secrets.GIT_ADMIN_WORKFLOW_TOKEN }}'
25+
token: "${{ secrets.GIT_ADMIN_WORKFLOW_TOKEN }}"
2326
fetch-depth: "2" # Original commit + code cov badge commit
2427
- name: Checkout (normal flow)
2528
if: ${{github.event_name == 'pull_request'}}
@@ -34,17 +37,19 @@ jobs:
3437
id: coverage-installer
3538
run: |
3639
python -m pip install --upgrade pip
37-
pip install cython==0.29.21 numpy==1.23.2
3840
sudo apt-get install jq
3941
pip install -r requirements.txt
4042
pip install -r requirements-dev.txt
4143
pip install coverage-badge
44+
DGP_PROTO_VERSION=3 pip install ".[dev]"
45+
make develop PROTO_VERSION=${{ matrix.protobuf_major_version }}
4246
- name: Run tests and calculate coverage
4347
id: test-runner
4448
run: |
4549
coverage run -m pytest
4650
coverage-badge -f -o docs/coverage.svg
47-
COVERAGE_SCORE=$(coverage json -o /dev/stdout | jq .totals.percent_covered)
51+
coverage json
52+
COVERAGE_SCORE=$(jq '.totals.percent_covered' coverage.json)
4853
echo "::set-output name=coverageScore::$COVERAGE_SCORE"
4954
- name: Verify Changed files
5055
uses: tj-actions/verify-changed-files@v6

.github/workflows/doc-gen.yml

+6-7
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ name: doc-gen
22
on:
33
push:
44
branches:
5-
- 'master'
5+
- "master"
66
pull_request:
77
branches:
8-
- 'master'
8+
- "master"
99

1010
jobs:
1111
run:
12-
runs-on: ubuntu-20.04
12+
runs-on: ubuntu-22.04
1313
env:
14-
OS: ubuntu-20.04
15-
PYTHON: '3.9'
14+
OS: ubuntu-22.04
15+
PYTHON: "3.9"
1616
steps:
1717
- uses: actions/checkout@master
1818
with:
@@ -26,7 +26,6 @@ jobs:
2626
- name: Setup requirements and run sphinx
2727
run: |
2828
python -m pip install --upgrade pip
29-
pip install cython==0.29.21 numpy==1.23.2
3029
pip install -r requirements.txt
3130
pip install -r requirements-dev.txt
3231
pip install -r docs/requirements-doc.txt
@@ -39,4 +38,4 @@ jobs:
3938
with:
4039
branch: gh-pages
4140
folder: ./docs/build/html
42-
commit-message: 'docs: update build documentation'
41+
commit-message: "docs: update build documentation"

.github/workflows/pre-merge.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
jobs:
1111
pre-merge-tests:
12-
runs-on: ubuntu-20.04
12+
runs-on: ubuntu-22.04
1313
env:
1414
ENVIRONMENT: TEST_RUNNER
1515
steps:
@@ -28,7 +28,6 @@ jobs:
2828
- name: Install dependencies
2929
run: |
3030
python -m pip install --upgrade pip
31-
pip install cython==0.29.21 numpy==1.23.2
3231
pip install -r requirements.txt
3332
pip install -r requirements-dev.txt
3433
- name: Lint all files with pre-commit

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,13 @@ Pipfile
111111
Pipfile.lock
112112

113113
\.vscode/
114+
*.ply
115+
116+
*.pyi
117+
*_pb2.py
118+
*_pb2_grpc.py
119+
120+
# Test data
121+
tests/data/dgp/autolabel_root/
122+
tests/data/dgp/test_scene/scene_01/autolabels/
123+
tests/data/dgp/test_scene/scene_02/autolabels/

.pre-commit-config.yaml

+16-9
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,21 @@ repos:
6161
hooks:
6262
- id: yapf
6363
# pre-commit requires that we split args at whitespce boundaries.
64-
args: [
65-
--style, .style.yapf,
66-
-i,
67-
-e, '*pb2.py',
68-
-e, '*pb2_grpc.py',
69-
-e, '*eggs*.py',
70-
-e, '*env*',
71-
-e, 'build/*'
72-
]
64+
args:
65+
[
66+
--style,
67+
.style.yapf,
68+
-i,
69+
-e,
70+
"*pb2.py",
71+
-e,
72+
"*pb2_grpc.py",
73+
-e,
74+
"*eggs*.py",
75+
-e,
76+
"*env*",
77+
-e,
78+
"build/*",
79+
]
7380
exclude: '\w*pb2.py'
7481
additional_dependencies: [toml]

Dockerfile

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
FROM nvidia/cuda:11.2.2-devel-ubuntu20.04
1+
FROM nvidia/cuda:11.6.1-cudnn8-devel-ubuntu20.04
22

33
ARG python=3.9
4-
ENV PYTORCH_VERSION=1.8.1+cu111
5-
ENV TORCHVISION_VERSION=0.9.1+cu111
4+
ENV PYTORCH_VERSION=1.13.1+cu116
5+
ENV TORCHVISION_VERSION=0.14.1+cu116
66

77
ENV LC_ALL=C.UTF-8
88
ENV LANG=C.UTF-8
@@ -42,11 +42,13 @@ RUN pip install --no-cache-dir \
4242
torchvision==${TORCHVISION_VERSION} \
4343
-f https://download.pytorch.org/whl/${PYTORCH_VERSION/*+/}/torch_stable.html
4444

45+
4546
# Install python dependencies
4647
ARG WORKSPACE=/home/dgp
4748
WORKDIR ${WORKSPACE}
4849
COPY requirements.txt requirements-dev.txt /tmp/
49-
RUN pip install --no-cache-dir cython==0.29.30 numpy==1.20.3
50+
# Install torch-compatible NumPy.
51+
RUN pip install numpy==1.26.4
5052
RUN pip install --no-cache-dir -r /tmp/requirements.txt
5153
RUN pip install --no-cache-dir -r /tmp/requirements-dev.txt
5254

Makefile

+25-13
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,18 @@ DOCKER_USER_OPTS ?= $(DOCKER_COMMON_OPTS) \
3636
UNITTEST ?= pytest
3737
UNITTEST_OPTS ?= -v
3838

39+
.PHONY: clean build develop
40+
3941
all: clean test
4042

41-
build-proto:
43+
44+
build:
45+
ifndef PROTO_VERSION
46+
$(error PROTO_VERSION is not set. Please invoke make with PROTO_VERSION=X! X could be 3 or 4 now.)
47+
endif
48+
@echo "Building the Python wheel for $(PROTO_VERSION)."
4249
PYTHONPATH=$(PWD):$(PYTHONPATH) \
43-
$(PYTHON) setup.py build_py
50+
DGP_PROTO_VERSION=$(PROTO_VERSION) $(PYTHON) setup.py bdist_wheel
4451

4552
clean:
4653
$(PYTHON) setup.py clean && \
@@ -51,26 +58,31 @@ clean:
5158
find dgp/proto -name "*_grpc.py" | xargs rm -rf
5259
find dgp/proto -name "*_pb2.py" | xargs rm -rf
5360
find dgp/contribs/pd -name "*_pb2.py" | xargs rm -rf
61+
find . -name "*eggs" | xargs rm -rf
5462

5563
develop:
56-
pip install cython==0.29.30 numpy==1.20.3 grpcio==1.41.0 grpcio-tools==1.41.0
57-
pip install --editable .
64+
ifndef PROTO_VERSION
65+
$(error PROTO_VERSION is not set. Please invoke make with PROTO_VERSION=X! X could be 3 or 4 now.)
66+
endif
67+
@echo "Install develop version for protobuf version $(PROTO_VERSION).X.X."
68+
DGP_PROTO_VERSION=$(PROTO_VERSION) pip install --editable .
5869

5970
docker-build:
6071
docker build \
6172
--build-arg WORKSPACE=$(WORKSPACE) \
6273
-t $(DOCKER_IMAGE) .
6374

64-
docker-exec:
75+
docker-exec: docker-build
6576
docker exec -it $(DOCKER_IMAGE_NAME) $(COMMAND)
6677

67-
docker-run-tests: build-proto
68-
docker run \
69-
--name $(DOCKER_IMAGE_NAME)-tests \
70-
$(DOCKER_ROOT_OPTS) $(DOCKER_IMAGE) \
71-
$(UNITTEST) $(UNITTTEST_OPTS) $(WORKSPACE)/tests
78+
docker-run-tests: docker-build
79+
ifndef PROTO_VERSION
80+
$(error PROTO_VERSION is not set. Please invoke make with PROTO_VERSION=X! X could be 3 or 4 now.)
81+
endif
82+
docker run --name $(DOCKER_IMAGE_NAME)-tests $(DOCKER_ROOT_OPTS) $(DOCKER_IMAGE) make PROTO_VERSION=$(PROTO_VERSION) test
83+
7284

73-
docker-start-interactive:
85+
docker-start-interactive: docker-build
7486
docker run \
7587
$(DOCKER_USER_OPTS) \
7688
$(DOCKER_IMAGE) \
@@ -83,9 +95,9 @@ setup-linters:
8395
pre-commit install
8496
pre-commit install --hook-type commit-msg
8597

86-
test: build-proto
98+
test: develop
8799
PYTHONPATH=$(PWD):$(PYTHONPATH) \
88-
$(UNITTEST) $(UNITTEST_OPTS) $(PWD)/tests/
100+
$(UNITTEST) $(UNITTEST_OPTS) $(PWD)/tests/ -vv
89101

90102
unlink-githooks:
91103
unlink .git/hooks/pre-push && unlink .git/hooks/pre-commit

README.md

+37-2
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,46 @@ You can build the base docker image and run the tests within
6262
[docker container](docs/GETTING_STARTED.md#markdown-header-develop-within-docker)
6363
via:
6464

65-
```sh
65+
`X` of 3 and 4 are supported.
66+
67+
```shell
6668
make docker-build
67-
make docker-run-tests
69+
make PROTO_VERSION=X docker-run-tests
70+
```
71+
72+
Build the Python wheel for vendoring different Protobuf versions.
73+
74+
```shell
75+
make PROTO_VERSION=X build
6876
```
6977

78+
For setup local developement.
79+
80+
```shell
81+
make PROTO_VERSION=X develop
82+
```
83+
84+
Runing the test using local development environment.
85+
86+
```shell
87+
make PROTO_VERSION=X test
88+
```
89+
90+
## Versioning
91+
92+
This repository adheres to [PEP 440](https://peps.python.org/pep-0440/) for
93+
versioning, with a slight modification:
94+
95+
In addition to the standard `major.minor.micro` format, we append a fourth
96+
numeric segment to denote the `protoc` version used for compiling `.proto`
97+
files.
98+
99+
For example, version `1.0.0.3` indicates that the package version is `1.0.0` and
100+
it was compiled using `protoc` version 3.x.x.
101+
102+
This approach maintains compatibility with PEP 440 and allows users to select
103+
the appropriate package version corresponding to their `protoc` version.
104+
70105
## Contributing
71106

72107
We appreciate all contributions to DGP! To learn more about making a

build_proto.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
import subprocess
3+
from pathlib import Path
4+
5+
_ROOT_DIRPATH = Path(__file__).parent.absolute()
6+
7+
8+
def build_proto(proto_version: str):
9+
assert proto_version in {"proto3", "proto4"}, "Unsupported proto version."
10+
from grpc_tools import command
11+
command.build_package_protos(_ROOT_DIRPATH)
12+
13+
14+
if __name__ == "__main__":
15+
proto_version = os.getenv("PROTO_VERSION", "proto3")
16+
build_proto(proto_version)

0 commit comments

Comments
 (0)