Skip to content

Commit

Permalink
Migrate python packages to poetry (#163)
Browse files Browse the repository at this point in the history
### Changelog
None

### Docs
None

### Description
For consistency with our upcoming packages, migrate the existing python
packages from pipenv to poetry.
  • Loading branch information
amacneil authored Feb 1, 2025
1 parent e0dfcb3 commit 1e204da
Show file tree
Hide file tree
Showing 18 changed files with 514 additions and 365 deletions.
37 changes: 21 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,40 +72,45 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

python:
runs-on: ubuntu-22.04 # Required for python 3.7
runs-on: ubuntu-latest
defaults:
run:
working-directory: python
permissions:
id-token: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- run: pipx install poetry

- uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Install Flatbuffer compiler
run: |
curl -LO https://github.com/google/flatbuffers/releases/download/v23.1.21/Linux.flatc.binary.clang++-12.zip
echo "359dbbf56153cc1b022170a228adfde4199f67dc Linux.flatc.binary.clang++-12.zip" | shasum -a 1 -c
unzip Linux.flatc.binary.clang++-12.zip
rm Linux.flatc.binary.clang++-12.zip
sudo mv flatc /usr/local/bin
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: 3.7
cache: pipenv
- run: pip install pipenv==2022.7.24
python-version: '3.9'
cache: poetry

- run: make test
- run: make install
- run: make build
- run: make test

- name: Publish foxglove-schemas-flatbuffer to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
if: ${{ !github.event.pull_request.head.repo.fork && github.actor != 'dependabot[bot]' }}
with:
packages_dir: python/foxglove-schemas-flatbuffer/dist
repository_url: https://test.pypi.org/legacy/
skip_existing: true
packages-dir: python/foxglove-schemas-flatbuffer/dist
repository-url: https://test.pypi.org/legacy/
skip-existing: true
attestations: false # https://github.com/pypa/gh-action-pypi-publish/issues/283#issuecomment-2499296440

- name: Publish foxglove-schemas-flatbuffer to PyPI
Expand All @@ -115,15 +120,15 @@ jobs:
startsWith(github.ref, 'refs/tags/releases/python/foxglove-schemas-flatbuffer/v')
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages_dir: python/foxglove-schemas-flatbuffer/dist
packages-dir: python/foxglove-schemas-flatbuffer/dist

- 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:
packages_dir: python/foxglove-schemas-protobuf/dist
repository_url: https://test.pypi.org/legacy/
skip_existing: true
packages-dir: python/foxglove-schemas-protobuf/dist
repository-url: https://test.pypi.org/legacy/
skip-existing: true
attestations: false # https://github.com/pypa/gh-action-pypi-publish/issues/283#issuecomment-2499296440

- name: Publish foxglove-schemas-protobuf to PyPI
Expand All @@ -133,7 +138,7 @@ jobs:
startsWith(github.ref, 'refs/tags/releases/python/foxglove-schemas-protobuf/v')
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages_dir: python/foxglove-schemas-protobuf/dist
packages-dir: python/foxglove-schemas-protobuf/dist

ros:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -166,7 +171,7 @@ jobs:
- name: setup directories
run: mkdir -p ros_ws/src
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: ros_ws/src
- name: build and test ros1
Expand Down
16 changes: 10 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
.catkin_tools
.DS_Store
.yarn
build
dist
install
log
node_modules
.mypy_cache/
.pytest_cache/
.yarn/
*.py[cod]
/python/**/dist/
/python/foxglove-schemas-flatbuffer/foxglove_schemas_flatbuffer/*.bfbs
/python/foxglove-schemas-flatbuffer/foxglove_schemas_flatbuffer/*.py
/python/foxglove-schemas-protobuf/foxglove_schemas_protobuf/*.py
/python/foxglove-schemas-protobuf/foxglove_schemas_protobuf/*.pyi
node_modules/
1 change: 1 addition & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
plugins: ["prettier-plugin-toml"]
printWidth: 100
trailingComma: all
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"files.eol": "\n",
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
"prettier.prettierPath": "./node_modules/prettier",
"prettier.documentSelectors": ["**/*.toml"],
"search.exclude": {
"**/node_modules": true,
".yarn/**": true,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"eslint-plugin-jest": "27.2.1",
"eslint-plugin-prettier": "4.2.1",
"jest": "29.4.3",
"prettier": "2.8.4",
"prettier": "^2.8.4",
"prettier-plugin-toml": "^2.0.1",
"protobufjs": "^7.2.2",
"rimraf": "^4.1.2",
"ts-jest": "29.0.5",
Expand Down
8 changes: 0 additions & 8 deletions python/.gitignore

This file was deleted.

55 changes: 29 additions & 26 deletions python/Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
.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: all
all: clean install generate build test

.PHONY: install
install:
cd foxglove-schemas-flatbuffer && poetry install
cd foxglove-schemas-protobuf && poetry install

.PHONY: generate-flatbuffer
generate-flatbuffer:
find foxglove-schemas-flatbuffer/foxglove_schemas_flatbuffer ! -name '__init__.py' -type f -exec rm -f {} +
pipenv run flatc \
cd foxglove-schemas-flatbuffer && poetry run flatc \
--require-explicit-ids \
--python \
-o foxglove-schemas-flatbuffer/foxglove_schemas_flatbuffer \
../schemas/flatbuffer/*.fbs
pipenv run flatc \
-o foxglove_schemas_flatbuffer \
../../schemas/flatbuffer/*.fbs
cd foxglove-schemas-flatbuffer && poetry run flatc \
-b \
--schema \
-o foxglove-schemas-flatbuffer/foxglove_schemas_flatbuffer \
../schemas/flatbuffer/*.fbs
-o foxglove_schemas_flatbuffer \
../../schemas/flatbuffer/*.fbs
rm foxglove-schemas-flatbuffer/foxglove_schemas_flatbuffer/foxglove/__init__.py
mv foxglove-schemas-flatbuffer/foxglove_schemas_flatbuffer/foxglove/* foxglove-schemas-flatbuffer/foxglove_schemas_flatbuffer
rmdir foxglove-schemas-flatbuffer/foxglove_schemas_flatbuffer/foxglove
Expand All @@ -29,31 +33,30 @@ generate-flatbuffer:
.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
cd foxglove-schemas-protobuf && poetry run protoc \
--python_out=foxglove_schemas_protobuf \
--mypy_out=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: generate
generate: generate-flatbuffer generate-protobuf

.PHONY: build
build: pipenv generate-flatbuffer generate-protobuf
pipenv run python -m build foxglove-schemas-flatbuffer
pipenv run python -m build foxglove-schemas-protobuf
build: generate
cd foxglove-schemas-flatbuffer && poetry build
cd foxglove-schemas-protobuf && poetry build

.PHONY: test
test: pipenv generate-flatbuffer generate-protobuf
pipenv run python -m pytest foxglove-schemas-flatbuffer
pipenv run python -m pytest foxglove-schemas-protobuf
test:
cd foxglove-schemas-flatbuffer && poetry run pytest
cd foxglove-schemas-protobuf && poetry run pytest

.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
git clean -Xdf
19 changes: 0 additions & 19 deletions python/Pipfile

This file was deleted.

Loading

0 comments on commit 1e204da

Please sign in to comment.