Skip to content

Commit

Permalink
Publish Python generated protobuf code to PyPI (#74)
Browse files Browse the repository at this point in the history
**Public-Facing Changes**
Published a new package to PyPI called `foxglove-schemas-protobuf`.
Import classes as follows:

```py
from foxglove_schemas_protobuf.RawImage_pb2 import RawImage
```
  • Loading branch information
jtbandes authored Nov 17, 2022
1 parent 3eeda84 commit 5dbf56e
Show file tree
Hide file tree
Showing 12 changed files with 500 additions and 2 deletions.
40 changes: 39 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI
on:
push:
branches: [main]
tags: ["releases/typescript/v*"]
tags: ["releases/**"]
pull_request:
branches: ["*"]

Expand Down Expand Up @@ -45,6 +45,44 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

python:
runs-on: ubuntu-latest
defaults:
run:
working-directory: python
steps:
- uses: actions/checkout@v3
- uses: arduino/setup-protoc@v1
- uses: actions/setup-python@v4
with:
python-version: 3.7
cache: pipenv
- run: pip install pipenv==2022.7.24

- run: make test
- run: make build

- name: Publish foxglove-schemas-protobuf to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
if: ${{ !github.event.pull_request.head.repo.fork && github.actor != 'dependabot[bot]' }}
with:
user: __token__
password: ${{ secrets.TESTPYPI_API_TOKEN }}
packages_dir: python/foxglove-schemas-protobuf/dist
repository_url: https://test.pypi.org/legacy/
skip_existing: true

- name: Publish foxglove-schemas-protobuf to PyPI
if: |
!github.event.pull_request.head.repo.fork &&
github.actor != 'dependabot[bot]' &&
startsWith(github.ref, 'refs/tags/releases/python/foxglove-schemas-protobuf/v')
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
packages_dir: python/foxglove-schemas-protobuf/dist

ros:
runs-on: ubuntu-latest
strategy:
Expand Down
11 changes: 10 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,14 @@
"eslint.options": {
"reportUnusedDisableDirectives": "error"
},
"jest.jestCommandLine": "yarn test"
"jest.jestCommandLine": "yarn test",

"python.formatting.provider": "black",
"python.analysis.typeCheckingMode": "strict",
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"python.linting.flake8Args": ["--config", "python/.flake8"],
"[python]": {
"editor.defaultFormatter": "ms-python.python"
}
}
6 changes: 6 additions & 0 deletions python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**/*.pyc
build
dist
*.egg-info
*_pb2*
.pytest_cache
39 changes: 39 additions & 0 deletions python/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.PHONY: pipenv
pipenv:
SETUPTOOLS_ENABLE_FEATURES="legacy-editable" pipenv install --dev --deploy

ifeq ($(shell uname),Darwin)
SED_ARGS = -i ''
else
SED_ARGS = -i
endif

.PHONY: generate-protobuf
generate-protobuf:
rm -rf foxglove-schemas-protobuf/foxglove_schemas_protobuf/*_pb2*
pipenv run protoc \
--python_out=foxglove-schemas-protobuf/foxglove_schemas_protobuf \
--mypy_out=foxglove-schemas-protobuf/foxglove_schemas_protobuf \
--proto_path ../schemas/proto \
../schemas/proto/foxglove/*.proto
mv foxglove-schemas-protobuf/foxglove_schemas_protobuf/foxglove/* foxglove-schemas-protobuf/foxglove_schemas_protobuf
rmdir foxglove-schemas-protobuf/foxglove_schemas_protobuf/foxglove
sed -E $(SED_ARGS) 's/from foxglove import/from . import/g' foxglove-schemas-protobuf/foxglove_schemas_protobuf/*_pb2.py
sed -E $(SED_ARGS) 's/import foxglove\.(.+)$$/from . import \1 as foxglove_\1/g' foxglove-schemas-protobuf/foxglove_schemas_protobuf/*_pb2.pyi
sed -E $(SED_ARGS) 's/foxglove\./foxglove_/g' foxglove-schemas-protobuf/foxglove_schemas_protobuf/*_pb2.pyi

.PHONY: build
build: pipenv generate-protobuf
pipenv run python -m build foxglove-schemas-protobuf

.PHONY: test
test: pipenv generate-protobuf
pipenv run python -m pytest foxglove-schemas-protobuf

.PHONY: clean
clean:
rm -rf dist
find . -name "build" -type d -exec rm -rf {} +
find . -name "dist" -type d -exec rm -rf {} +
find . -name "*.egg-info" -type d -exec rm -rf {} +
find . -name "*_pb2*" -delete
17 changes: 17 additions & 0 deletions python/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
protobuf = "*"
foxglove-schemas-protobuf = {editable = true, path = "./foxglove-schemas-protobuf"}

[dev-packages]
build = "*"
mypy-protobuf = "*"
pipenv = "*"
pytest = "*"

[requires]
python_version = "3"
Loading

0 comments on commit 5dbf56e

Please sign in to comment.