Skip to content

Commit

Permalink
Modernize Python packaging (#451)
Browse files Browse the repository at this point in the history
* Modernize Python packaging

* Run 'make format'

* Add releasing instructions

* Fix validate_setup script

* Use pip-compile to upgrade requirements

* Use python -m venv

* Install pinned requirements.txt

* @grahamalama review

* Move to src-layout

* Fix 'make clean'

* Fix path .ini when running kinto

* Narrow finding files when deleting cache

* Fix 'make lint'

* Fix 'tox -e lint'

* tox, your days are counted

* Remove superfluous -o requirements.txt for pip-compile

* Split venv creation from install
  • Loading branch information
leplatrem authored Jan 18, 2024
1 parent 253ba26 commit 023bfba
Show file tree
Hide file tree
Showing 24 changed files with 1,062 additions and 824 deletions.
3 changes: 0 additions & 3 deletions .coveragerc

This file was deleted.

23 changes: 23 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
changelog:
exclude:
authors:
- dependabot
categories:
- title: Breaking Changes
labels:
- "breaking-change"
- title: Bug Fixes
labels:
- "bug"
- title: New Features
labels:
- "enhancement"
- title: Documentation
labels:
- "documentation"
- title: Dependency Updates
labels:
- "dependencies"
- title: Other Changes
labels:
- "*"
55 changes: 55 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Publish Python 🐍 distribution 📦 to PyPI

on:
push:
tags:
- '*'

jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

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

- name: Print environment
run: |
python --version
- name: Install pypa/build
run: python3 -m pip install build

- name: Build a binary wheel and a source tarball
run: python3 -m build

- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/p/kinto-emailer
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
toxenv: [py38, flake8, functional]
toxenv: [py38, lint, functional]
include:
- toxenv: py38
python-version: "3.8"
- toxenv: flake8
- toxenv: lint
python-version: "3.X"
- toxenv: functional
python-version: "3.11"
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
.cache
.tox
.coverage
records.json
.pytest_cache
.ruff_cache
*.pyc
__pycache__/
*.egg-info/
*.egg
mail/
.venv/
build/
dist/
6 changes: 3 additions & 3 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Changelog

This document describes changes between each past release.

2.2.0 (unreleased)
------------------
>= 2.2.0
--------

- Nothing changed yet.
Since version 2.2.0, we use `Github releases <https://github.com/Kinto/kinto-emailer/releases>`_ and autogenerated changelogs.


2.1.0 (2021-11-29)
Expand Down
58 changes: 26 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,55 +1,49 @@
VIRTUALENV = virtualenv
VENV := $(shell echo $${VIRTUAL_ENV-$$PWD/.venv})
PYTHON = $(VENV)/bin/python
DEV_STAMP = $(VENV)/.dev_env_installed.stamp
INSTALL_STAMP = $(VENV)/.install.stamp
TEMPDIR := $(shell mktemp -d)

.IGNORE: clean
.PHONY: all install virtualenv tests install-dev tests-once
.PHONY: all install virtualenv tests tests-once

OBJECTS = .venv .coverage

all: install
install: $(INSTALL_STAMP)
$(INSTALL_STAMP): $(PYTHON) requirements.txt setup.py

$(VENV)/bin/python:
python -m venv $(VENV)

install: $(INSTALL_STAMP) pyproject.toml requirements.txt
$(INSTALL_STAMP): $(VENV)/bin/python pyproject.toml requirements.txt
$(VENV)/bin/pip install -r requirements.txt
$(PYTHON) setup.py develop
$(VENV)/bin/pip install ".[dev]"
touch $(INSTALL_STAMP)

install-dev: $(INSTALL_STAMP) $(DEV_STAMP)
$(DEV_STAMP): $(PYTHON) dev-requirements.txt
$(VENV)/bin/pip install -r dev-requirements.txt
touch $(DEV_STAMP)
lint: install
$(VENV)/bin/ruff check src tests *.py
$(VENV)/bin/ruff format --check src tests *.py

virtualenv: $(PYTHON)
$(PYTHON):
virtualenv $(VENV)
format: install
$(VENV)/bin/ruff check --fix src tests *.py
$(VENV)/bin/ruff format src tests *.py

build-requirements:
$(VIRTUALENV) $(TEMPDIR)
$(TEMPDIR)/bin/pip install -U pip
$(TEMPDIR)/bin/pip install -Ue .
$(TEMPDIR)/bin/pip freeze | grep -v -- '^-e' > requirements.txt
requirements.txt: requirements.in
pip-compile requirements.in

tests-once: install-dev
tests-once: install
$(VENV)/bin/py.test --cov-report term-missing --cov-fail-under 100 --cov kinto_emailer
tests: install-dev

tests: install
$(VENV)/bin/tox

clean:
find . -name '*.pyc' -delete
find . -name '__pycache__' -type d -exec rm -fr {} \;

install-kinto: $(VENV)/bin/kinto
$(VENV)/bin/kinto: install
$(VENV)/bin/pip install kinto
find src/ -name '*.pyc' -delete
find src/ -name '__pycache__' -type d -exec rm -fr {} \;
rm -rf .tox $(VENV) mail/ *.egg-info .pytest_cache .ruff_cache .coverage build dist

run-kinto: install-kinto
$(VENV)/bin/kinto start --ini kinto_emailer/tests/config/kinto.ini
run-kinto: install
$(VENV)/bin/kinto start --ini tests/config/kinto.ini

need-kinto-running:
@curl http://localhost:8888/v0/ 2>/dev/null 1>&2 || (echo "Run 'make run-kinto' before starting tests." && exit 1)

functional: install-dev need-kinto-running
$(VENV)/bin/py.test kinto_emailer/tests/functional.py
functional: install need-kinto-running
$(VENV)/bin/py.test tests/functional.py
12 changes: 10 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Template
The template string can have placeholders:

* ``bucket_id``
* ``id``: record or collection ``id``)
* ``id``: record or collection ``id``
* ``user_id``
* ``resource_name``
* ``uri``
Expand Down Expand Up @@ -181,7 +181,15 @@ For the functional tests, run a Kinto instance in a separate terminal::

$ make run-kinto


And start the test suite::

$ make functional


Releasing
=========

1. Create a release on Github on https://github.com/Kinto/kinto-emailer/releases/new
2. Create a new tag `X.Y.Z` (*This tag will be created from the target when you publish this release.*)
3. Generate release notes
4. Publish release
9 changes: 0 additions & 9 deletions dev-requirements.txt

This file was deleted.

Loading

0 comments on commit 023bfba

Please sign in to comment.