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

Add messages implementation for python #165

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 37 additions & 0 deletions .github/workflows/release-pypi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Release Python

on:
push:
branches: [release/*]

jobs:
release:
name: Release
runs-on: ubuntu-latest
environment: Release
permissions:
id-token: write
defaults:
run:
working-directory: python
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Show Python version
run: python --version

- name: Generate code
working-directory: ./python
run: |
make clean-real
make generate-real

- uses: cucumber/[email protected]
with:
working-directory: "python"
87 changes: 87 additions & 0 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
name: test-python

on: # yamllint disable-line rule:truthy
push:
branches:
- main
- renovate/**
pull_request:
branches:
- main
workflow_dispatch:

jobs:
build:

runs-on: ${{ matrix.os }}
timeout-minutes: 20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks unnecessary.

strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "pypy3.8"
luke-hill marked this conversation as resolved.
Show resolved Hide resolved
- "pypy3.9"
- "pypy3.10"
os:
- ubuntu-latest
- windows-latest
- macos-latest
elchupanebrej marked this conversation as resolved.
Show resolved Hide resolved
exclude:
- python-version: "pypy3.8"
os: macos-latest
- python-version: "pypy3.9"
os: macos-latest
- python-version: "pypy3.10"
os: macos-latest
- python-version: "3.8"
os: macos-latest
- python-version: "3.9"
os: macos-latest
- python-version: "3.10"
os: macos-latest
- python-version: "3.11"
os: macos-latest
- python-version: "pypy3.8"
os: windows-latest
- python-version: "pypy3.9"
os: windows-latest
- python-version: "pypy3.10"
os: windows-latest
- python-version: "3.8"
os: windows-latest
- python-version: "3.9"
os: windows-latest
- python-version: "3.10"
os: windows-latest
- python-version: "3.11"
os: windows-latest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There has to be a more efficient way to run run all versions on ubuntu and exclude osx and windows.


steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Generate code
working-directory: ./python
run: |
make clean-real
make generate-real
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U setuptools
pip install tox tox-gh-actions codecov
- name: Test with tox
working-directory: ./python
run: |
tox
- name: Gather codecov report
working-directory: ./python
run: |
codecov
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed
- [Go] Switch to Google's UUID module ([#251](https://github.com/cucumber/messages/pull/251))

### Added
- [Python] Added Python implementation ([#165](https://github.com/cucumber/messages/pull/165))

## [26.0.0] - 2024-08-15
### Added
- [Dotnet] Added support classes aligned with what is provided for the Java implementation ([#233](https://github.com/cucumber/messages/pull/233) [clrudolphi](https://github.com/clrudolphi))
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ schemas = \
./jsonschema/UndefinedParameterType.json \
./jsonschema/Envelope.json

languages = cpp go java javascript perl php ruby dotnet
languages = cpp dotnet go java javascript perl php python ruby

.DEFAULT_GOAL = help

Expand Down
55 changes: 55 additions & 0 deletions python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
*.rej
*.py[cod]
/.env
*.orig
**/__pycache__

# C extensions
*.so

# Packages
*.egg
*.egg-info
dist
build
_build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox
nosetests.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject
.pytest_cache
.ropeproject

# Sublime
/*.sublime-*

#PyCharm
/.idea

# virtualenv
/.Python
/lib
/include
/share
/local
48 changes: 48 additions & 0 deletions python/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
---
repos:
- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black
args:
- "python/src"
- "python/tests"
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-toml
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.14.0
hooks:
- id: pretty-format-toml
args: [--autofix]
- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
hooks:
- id: pyupgrade
args: ["--py38-plus"]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
- id: mypy
additional_dependencies: [types-setuptools, types-certifi]
- repo: https://github.com/tox-dev/tox-ini-fmt
rev: "1.3.2"
hooks:
- id: tox-ini-fmt
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.35.1
hooks:
- id: yamllint
args: [--format, parsable, --strict]
41 changes: 41 additions & 0 deletions python/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
schemas = $(shell find ../jsonschema -name "*.json")

.DEFAULT_GOAL = help

MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
HERE := $(dir $(MKFILE_PATH))

help: ## Show this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make <target>\n\nWhere <target> is one of:\n"} /^[$$()% a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

generate: ## Stub for the ancestor Makefile
echo "Skipping code generation - code is generated by Python"

generate-real: require install-deps
datamodel-codegen \
mpkorstanje marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to move this into pythons build process?

--output-model-type "pydantic_v2.BaseModel" \
--input $(HERE)../jsonschema/Envelope.json \
--output $(HERE)src/cucumber_messages/messages.py \
--use-generic-container-types \
--allow-extra-fields \
--allow-population-by-field-name \
--snake-case-field \
--input-file-type=jsonschema \
--class-name Envelope \
--use-double-quotes \
--use-union-operator \
--disable-timestamp \
--target-python-version=3.8

require: ## Check requirements for the code generation (python is required)
@python --version >/dev/null 2>&1 || (echo "ERROR: python is required."; exit 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python should not be required. This can be a stub too.


clean: ## Stub for the ancestor Makefile
echo "Skipping code cleanup - code cleanup is done by Python"

clean-real: ## Remove automatically generated files and related artifacts
rm -rf $(HERE)src/_messages.py

install-deps: ## Install generation dependencies
python -m ensurepip --upgrade
pip install $(HERE)[generation]
3 changes: 3 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Messages

Cucumber Messages for Python https://github.com/cucumber/messages
Loading
Loading