Skip to content

Commit

Permalink
Dev chores (#561)
Browse files Browse the repository at this point in the history
* Migrate to pyproject.toml; use ruff; add RELEASING.md; remove copyright year

* tox -e lint

* Update build and release pipeline
  • Loading branch information
sloria committed Jan 30, 2024
1 parent 29ad48f commit 26f4bed
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 166 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ updates:
schedule:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
62 changes: 41 additions & 21 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,60 @@ jobs:
- { name: "lowest", python: "3.8", tox: py38-lowest }
- { name: "dev", python: "3.12", tox: py312-marshmallowdev }
steps:
- uses: actions/checkout@v3.1.0
- uses: actions/setup-python@v4.3.0
- uses: actions/checkout@v4.0.0
- uses: actions/setup-python@v4.7.0
with:
python-version: ${{ matrix.python }}
- run: python -m pip install --upgrade pip
- run: python -m pip install tox
- run: python -m tox -e${{ matrix.tox }}
build:
name: Build package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install pypa/build
run: python -m pip install build
- name: Build a binary wheel and a source tarball
run: python -m build
- name: Install twine
run: python -m pip install twine
- name: Check build
run: python -m twine check --strict dist/*
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/
# this duplicates pre-commit.ci, so only run it on tags
# it guarantees that linting is passing prior to a release
lint-pre-release:
name: lint
if: startsWith(github.ref, 'refs/tags')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.1.0
- uses: actions/setup-python@v4.3.0
- uses: actions/checkout@v4.0.0
- uses: actions/setup-python@v4.7.0
with:
python-version: "3.11"
- run: python -m pip install --upgrade pip
- run: python -m pip install tox
- run: python -m tox -elint
release:
needs: [tests, lint-pre-release]
- run: python -m tox -e lint
publish-to-pypi:
name: PyPI release
if: startsWith(github.ref, 'refs/tags')
if: startsWith(github.ref, 'refs/tags/')
needs: [build, tests, lint-pre-release]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/marshmallow-sqlalchemy
permissions:
id-token: write
steps:
- uses: actions/checkout@v3.1.0
- uses: actions/setup-python@v4.3.0
- name: install requirements
run: python -m pip install build twine
- name: build dists
run: python -m build
- name: check package metadata
run: twine check dist/*
- name: publish
run: twine upload -u __token__ -p ${{ secrets.PYPI_API_TOKEN }} dist/*
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
24 changes: 12 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.14
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/psf/black
rev: 23.12.1
- id: ruff
- id: ruff-format
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.3
hooks:
- id: black
language_version: python3
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
- id: check-github-workflows
- id: check-readthedocs
- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear==23.9.16]
- id: blacken-docs
additional_dependencies: [black==23.12.1]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2015-2024 Steven Loria and contributors
Copyright Steven Loria and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
9 changes: 0 additions & 9 deletions MANIFEST.in

This file was deleted.

8 changes: 8 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Releasing

1. Bump version in `pyproject.toml` and update the changelog
with today's date.
2. Commit: `git commit -m "Bump version and update changelog"`
3. Tag the commit: `git tag x.y.z`
4. Push: `git push --tags origin dev`. CI will take care of the
PyPI release.
11 changes: 3 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import importlib.metadata
from collections import OrderedDict
import datetime as dt
import os
import sys

import alabaster

sys.path.insert(0, os.path.abspath(os.path.join("..", "src")))
import marshmallow_sqlalchemy # noqa: E402

extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
Expand All @@ -29,9 +24,9 @@
source_suffix = ".rst"
master_doc = "index"
project = "marshmallow-sqlalchemy"
copyright = f"Steven Loria and contributors {dt.datetime.utcnow():%Y}"
copyright = "Steven Loria and contributors"

version = release = marshmallow_sqlalchemy.__version__
version = release = importlib.metadata.version("marshmallow-sqlalchemy")

exclude_patterns = ["_build"]

Expand Down
63 changes: 60 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,60 @@
[tool.black]
line-length = 88
target-version = ['py38', 'py39', 'py310', 'py311', 'py312']
[project]
name = "marshmallow-sqlalchemy"
version = "0.30.0"
description = "SQLAlchemy integration with the marshmallow (de)serialization library"
readme = "README.rst"
license = { file = "LICENSE" }
maintainers = [{ name = "Steven Loria", email = "sloria1@gmail.com" }]
classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
requires-python = ">=3.8"
dependencies = [
"marshmallow>=3.0.0",
"SQLAlchemy>=1.4.40,<3.0",
"packaging>=21.3",
]

[project.urls]
Changelog = "https://marshmallow-sqlalchemy.readthedocs.io/en/latest/changelog.html"
Funding = "https://opencollective.com/marshmallow"
Issues = "https://github.com/marshmallow-code/marshmallow-sqlalchemy/issues"
Source = "https://github.com/marshmallow-code/marshmallow-sqlalchemy"

[project.optional-dependencies]
docs = ["sphinx==7.2.6", "alabaster==0.7.16", "sphinx-issues==3.0.1"]
# TODO: Remove pytest pin when https://github.com/TvoroG/pytest-lazy-fixture/issues/65 is resolved
tests = ["pytest<8", "pytest-lazy-fixture>=0.6.2"]
dev = ["marshmallow-sqlalchemy[tests]", "tox", "pre-commit~=3.5"]

[build-system]
requires = ["flit_core<4"]
build-backend = "flit_core.buildapi"

[tool.flit.sdist]
include = ["docs/", "tests/", "CHANGELOG.rst", "CONTRIBUTING.rst", "tox.ini"]
exclude = ["docs/_build/"]

[tool.ruff]
src = ["src"]
fix = true
show-fixes = true
show-source = true

[tool.ruff.lint]
ignore = ["E203", "E266", "E501", "E731"]
select = [
"B", # flake8-bugbear
"E", # pycodestyle error
"F", # pyflakes
"I", # isort
"UP", # pyupgrade
"W", # pycodestyle warning
]
11 changes: 0 additions & 11 deletions setup.cfg

This file was deleted.

87 changes: 0 additions & 87 deletions setup.py

This file was deleted.

5 changes: 4 additions & 1 deletion src/marshmallow_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import importlib.metadata

from .convert import (
ModelConverter,
column2field,
Expand All @@ -14,7 +16,8 @@
auto_field,
)

__version__ = "0.30.0"
# TODO: Deprecate __version__
__version__ = importlib.metadata.version("marshmallow-sqlalchemy")
__all__ = [
"SQLAlchemySchema",
"SQLAlchemyAutoSchema",
Expand Down
4 changes: 2 additions & 2 deletions src/marshmallow_sqlalchemy/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ def _get_existing_instance(self, related_model, value):
lookup_values = [value.get(prop.key) for prop in self.related_keys]
try:
result = self.session.get(related_model, lookup_values)
except TypeError:
except TypeError as error:
keys = [prop.key for prop in self.related_keys]
raise self.make_error("invalid", value=value, keys=keys)
raise self.make_error("invalid", value=value, keys=keys) from error
if result is None:
raise NoResultFound
return result
Expand Down
2 changes: 1 addition & 1 deletion src/marshmallow_sqlalchemy/schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sqlalchemy as sa
from marshmallow.fields import Field
from marshmallow.schema import Schema, SchemaMeta, SchemaOpts
import sqlalchemy as sa
from sqlalchemy.ext.declarative import DeclarativeMeta

from .convert import ModelConverter
Expand Down

0 comments on commit 26f4bed

Please sign in to comment.