Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Oct 16, 2023
2 parents 454df21 + 33b2662 commit 89dd343
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 18 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ jobs:
if: success() && startsWith(github.ref, 'refs/tags/') && github.event_name != 'schedule'
runs-on: ubuntu-latest

permissions:
id-token: write
contents: write

steps:
- uses: actions/checkout@v4
with:
Expand All @@ -83,17 +87,13 @@ jobs:

- name: install
run: |
git tag
pip install -U pip build twine
python -m pip install build
python -m build
twine check dist/*
- name: Build and publish
run: twine upload dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TWINE_API_KEY }}
- name: 🚢 Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

- uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
files: './dist/*'
2 changes: 1 addition & 1 deletion .github_changelog_generator
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
user=tlambert03
user=pyapp-kit
project=pydantic-compat
issues=false
exclude-labels=duplicate,question,invalid,wontfix,hide
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ ci:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.287
rev: v0.0.292
hooks:
- id: ruff
args: [--fix]

- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.9.1
hooks:
- id: black

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# pydantic-compat

[![GitHub](https://img.shields.io/github/license/tlambert03/pydantic-compat)
](https://github.com/tlambert03/pydantic-compat/raw/main/LICENSE)
[![GitHub](https://img.shields.io/github/license/pyapp-kit/pydantic-compat)
](https://github.com/pyapp-kit/pydantic-compat/raw/main/LICENSE)
[![PyPI](https://img.shields.io/pypi/v/pydantic-compat.svg?color=green)](https://pypi.org/project/pydantic-compat)
[![Python Version](https://img.shields.io/pypi/pyversions/pydantic-compat.svg?color=green)](https://python.org)
[![CI](https://github.com/tlambert03/pydantic-compat/actions/workflows/ci.yml/badge.svg)](https://github.com/tlambert03/pydantic-compat/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/tlambert03/pydantic-compat/branch/main/graph/badge.svg)](https://codecov.io/gh/tlambert03/pydantic-compat)
[![CI](https://github.com/pyapp-kit/pydantic-compat/actions/workflows/ci.yml/badge.svg)](https://github.com/pyapp-kit/pydantic-compat/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/pyapp-kit/pydantic-compat/branch/main/graph/badge.svg)](https://codecov.io/gh/pyapp-kit/pydantic-compat)

## Motivation

Expand All @@ -23,7 +23,7 @@ regardless of the pydantic version installed. (Prefer using v2 names when possib
Tests are run on Pydantic v1.8 and up

The API conversion is not exhaustive, but suffices for many of the use cases
I have come across. I will be using it in:
I have come across. It is in use by the following libraries:

- [ome-types](https://github.com/tlambert03/ome-types)
- [psygnal](https://github.com/pyapp-kit/psygnal)
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Framework :: Pydantic",
"Typing :: Typed",
]
dynamic = ["version"]
dependencies = ["pydantic", "importlib_metadata; python_version<'3.8'"]
Expand Down Expand Up @@ -72,8 +74,8 @@ dev = [
]

[project.urls]
homepage = "https://github.com/tlambert03/pydantic-compat"
repository = "https://github.com/tlambert03/pydantic-compat"
homepage = "https://github.com/pyapp-kit/pydantic-compat"
repository = "https://github.com/pyapp-kit/pydantic-compat"

# https://hatch.pypa.io/latest/config/metadata/
[tool.hatch.version]
Expand Down
1 change: 1 addition & 0 deletions src/pydantic_compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"BaseModel",
]


from ._shared import PYDANTIC2

if TYPE_CHECKING:
Expand Down
16 changes: 16 additions & 0 deletions src/pydantic_compat/v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""This module is a try/except pass-through for the pydantic.v1 namespace.
The pydantic.v1 namespace was added in pydantic v2. It contains the entire
pydantic v1 package. For packages that would like to unpin their 'pydantic<2'
dependency *without* needing to update all of their code to use the pydantic v2 api,
this provides a simple way to delay that update.
This is different from the goal of pydantic_compat on the whole, which is to provide
an API translation layer that allows you to actually use pydantic v2 features
(e.g. rust-backed speed, etc...) while also being compatible with packages that pin
pydantic<2.
"""
try:
from pydantic.v1 import * # noqa
except ImportError:
from pydantic import * # type: ignore # noqa
10 changes: 10 additions & 0 deletions tests/test_base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,13 @@ class Model(PydanticCompatMixin, pydantic.BaseModel):
# test extra
with pytest.raises((ValueError, TypeError)): # (v1, v2)
Model(extra=1)


def test_v1_namespace() -> None:
from pydantic_compat.v1 import BaseModel

class Model(BaseModel):
x: int = 1

m = Model()
assert m.dict() == {"x": 1} # no warning

0 comments on commit 89dd343

Please sign in to comment.