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

Features/python eol #4

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
51 changes: 51 additions & 0 deletions .github/workflows/build-artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Build envsub tarballs for supported python.

name: "Build artifact"

on:
workflow_call:
inputs:
release-version:
required: true
type: string
dry-run:
required: true
type: boolean
python-version:
required: true
type: string
pull_request:
paths:
# When we change pyproject.toml, we want to ensure that the maturin builds still work.
- pyproject.toml
# And when we change this workflow itself...
- .github/workflows/build-artifacts.yml

concurrency:
group: sdist-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
sdist:
name: Build artifact for ${{ inputs.release-version }} ${{ inputs.dry-run && '(dry-run)' || '' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Install the project
run: uv sync

- name: Build tarball
run: uv build

- name: "Upload sdist"
uses: actions/upload-artifact@v4
with:
name: pypi_files
path: dist/*
35 changes: 35 additions & 0 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Publish a release to PyPI.
#
name: "Publish to PyPI"

on:
workflow_call:
inputs:
release-version:
required: true
type: string
dry-run:
required: true
type: boolean

jobs:
pypi-publish:
name: Upload to PyPI ${{ inputs.release-version }} ${{ inputs.dry-run && '(dry-run)' || '' }}
runs-on: ubuntu-latest
if: ${{ !inputs.dry-run }}
permissions:
contents: read
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
pattern: pypi_files
path: dist
merge-multiple: true

- uses: pdm-project/setup-pdm@v4
with:
python-version: 3.12

- name: Publish package distributions to PyPI
run: pdm publish --no-build
87 changes: 87 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Release

on:
push:
tags:
- 'v*' # Automatically trigger on version tags
- 'dry-run'

workflow_dispatch:
inputs:
tag:
description: "Release Tag"
required: true
default: "dry-run"
type: string

env:
PYTHON_VERSION: "3.12"


jobs:
plan:
runs-on: ubuntu-latest
outputs:
release_version: ${{ steps.release-version.outputs.release_version }}
dry-run: ${{ steps.release-version.outputs.dry_run }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set Release Version
id: release-version
run: |
if [ "${{ github.event_name }}" == "push" ]; then
echo "release_version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
if [ "${{ github.ref_name }}" == "dry-run" ]; then
echo "dry_run=true" >> $GITHUB_OUTPUT
else
echo "dry_run=false" >> $GITHUB_OUTPUT
fi
else
version="${{ github.event.inputs.tag || 'dry-run' }}"
if [ "${version}" == "dry-run" ]; then
echo "release_version=latest" >> $GITHUB_OUTPUT
echo "dry_run=true" >> $GITHUB_OUTPUT
else
echo "release_version=${version}" >> $GITHUB_OUTPUT
echo "dry_run=false" >> $GITHUB_OUTPUT
fi
fi
- name: Display Release Version
run: echo "The release version is ${{ steps.release-version.outputs.release_version }}"

unit-tests:
uses: ./.github/workflows/tests.yml

build-artifacts:
needs:
- plan
- unit-tests
uses: ./.github/workflows/build-artifacts.yml
with:
release-version: ${{ needs.plan.outputs.release_version }}
dry-run: ${{ needs.plan.outputs.dry-run == 'true' }}
python-version: '3.12'

tests-artifacts:
needs:
- plan
- build-artifacts
uses: ./.github/workflows/tests-artifacts.yml
with:
release-version: ${{ needs.plan.outputs.release_version }}
dry-run: ${{ needs.plan.outputs.dry-run == 'true' }}

publish-pypi:
needs:
- plan
- tests-artifacts
uses: ./.github/workflows/publish-pypi.yml
with:
release-version: ${{ needs.plan.outputs.release_version }}
dry-run: ${{ needs.plan.outputs.dry-run == 'true' }}
permissions:
contents: read
id-token: write
34 changes: 34 additions & 0 deletions .github/workflows/tests-artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: tests artifacts

# Controls when the workflow will run
on:
# Allows you to run this workflow manually from the Actions tab
workflow_call:
inputs:
release-version:
required: true
type: string
description: "release number"
dry-run:
required: true
type: boolean
description: "blank run means that the release will not be pushed"

jobs:
test-sdist:
name: test tarball archive of ${{ inputs.release-version }} ${{ inputs.dry-run && '(dry-run)' || '' }}
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
pattern: pypi_files
path: dist
merge-multiple: true

- name: "Install"
run: |
pip install dist/celery_prometheus-*.whl --force-reinstall

- name: "Test sdist"
run: |
python -c "from celery_prometheus import __version__; print(__version__, end='')"
52 changes: 16 additions & 36 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,35 @@
name: tests

on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

workflow_call:

jobs:
tests:
# The type of runner that the job will run on
CI:
runs-on: ubuntu-latest
# Uncomment this part in case unit tests joins the party
# strategy:
# matrix:
# python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
# poetry-version: ["1.4.0"]
# Steps represent a sequence of tasks that will be executed as part of the job
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: 3.8
# python-version: ${{ matrix.python-version }}
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1

- name: Run image
uses: abatilo/actions-poetry@v2
- uses: actions/setup-python@v5
with:
poetry-version: latest
# poetry-version: ${{ matrix.poetry-version }}

- name: Setup the virtualenv for celery-prometheus
run: poetry install --with dev
python-version: ${{ matrix.python-version }}

- name: Check lint with Flake8
run: |
poetry run flake8 .

- name: Check imports with isort
run: |
poetry run isort -c .
- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Check formatting with black
run: |
poetry run black -C .
- name: Install the project
run: uv sync --group dev

- name: Check typing with mypy
- name: Check types
run: |
poetry run mypy src/celery_prometheus/
uv run mypy src/celery_prometheus/
40 changes: 24 additions & 16 deletions Justfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
package := 'celery_prometheus'

install:
poetry install --with dev
uv sync

lint:
poetry run flake8 && echo "$(tput setaf 10)Success: no lint issue$(tput setaf 7)"
uv run ruff check .

mypy:
poetry run mypy src/
typecheck:
uv run mypy src/

black:
poetry run isort .
poetry run black .
fmt:
uv run ruff check --fix .
uv run ruff format src

release major_minor_patch: && changelog
poetry version {{major_minor_patch}}
poetry install
release major_minor_patch: changelog
#! /bin/bash
# Try to bump the version first
if ! uvx pdm bump {{major_minor_patch}}; then
# If it fails, check if pdm-bump is installed
if ! uvx pdm self list | grep -q pdm-bump; then
# If not installed, add pdm-bump
uvx pdm self add pdm-bump
fi
# Attempt to bump the version again
uvx pdm bump {{major_minor_patch}}
fi
uv sync

changelog:
poetry run python scripts/write_changelog.py
uv run python scripts/write_changelog.py
cat CHANGELOG.md >> CHANGELOG.md.new
rm CHANGELOG.md
mv CHANGELOG.md.new CHANGELOG.md
$EDITOR CHANGELOG.md

publish:
git commit -am "Release $(poetry version -s)"
poetry build
poetry publish
git commit -am "Release $(uv run scripts/get_version.py)"
git push
git tag "$(poetry version -s)"
git push origin "$(poetry version -s)"
git tag "v$(uv run scripts/get_version.py)"
git push origin "v$(uv run scripts/get_version.py)"
44 changes: 25 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
[tool.poetry]
[project]
name = "celery-prometheus"
version = "1.1.0"
version = "2.1.2"
description = "Celery with your own prometheus metrics"
authors = ["Guillaume Gauvrit <[email protected]>"]
authors = [{ name = "Guillaume Gauvrit", email = "[email protected]" }]
readme = "README.md"
license = "BSD-Derived"
requires-python = ">=3.9"
dependencies = ["celery>=5.4.0,<6", "prometheus-client >=0.17,<1"]

[tool.poetry.dependencies]
python = "^3.7"
celery = ">=4"

[tool.poetry.group.dev.dependencies]
black = "^23.1.0"
flake8 = "5.0.4"
isort = "5.11.4"
mypy = "1.0.0"
prometheus-client = "^0.16.0"
types-setuptools = "^67.4.0.3"
[dependency-groups]
dev = ["celery>=5.4.0,<6", "mypy>=1.13.0,<2"]

[[tool.mypy.overrides]]
disallow_any_generics = true
disallow_untyped_defs = true
module = "celery_prometheus.*"

[tool.isort]
profile = "black"
[[tool.mypy.overrides]]
module = ["celery.*"]
ignore_missing_imports = true

[tool.ruff]
line-length = 88
target-version = "py39"

[tool.ruff.lint]
select = [
"B", # bug bear security warning
"I", # isort import order
"F", # pyflakes
"UP", # alter when better syntax is available
"RUF", # the ruff devleoper's own rules
]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
requires = ["pdm-backend"]
build-backend = "pdm.backend"
Loading
Loading