Skip to content

Commit

Permalink
ci: basic test, build and release setup
Browse files Browse the repository at this point in the history
  • Loading branch information
jhassine committed Nov 18, 2024
1 parent c0377af commit 864ec24
Show file tree
Hide file tree
Showing 50 changed files with 1,573 additions and 872 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"ms-azuretools.vscode-docker",
"github.vscode-github-actions",
"ms-python.isort",
"ms-toolsai.jupyter"
"ms-toolsai.jupyter",
"ms-vscode.makefile-tools"
]
}
}
Expand Down
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ updates:
directory: "/"
schedule:
interval: weekly
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: weekly
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: weekly
-
114 changes: 114 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: CI/CD pipeline

on:
push:
branches:
- "*"

jobs:
tests:
runs-on: ubuntu-latest

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

- name: Build Docker image
run: |
docker build -t django2pydantic .
- name: Run tests
run: |
docker run --volume $(pwd):/app --workdir /app --rm django2pydantic nox -s noop
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
path: dist/
name: python-package-distributions

release:
# If main branch is updated, we want to release the package.
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs:
- tests
- build
concurrency: release
runs-on: ubuntu-latest

permissions:
id-token: write
contents: write

steps:
# Note: we need to checkout the repository at the workflow sha in case during the workflow
# the branch was updated. To keep PSR working with the configured release branches,
# we force a checkout of the desired release branch but at the workflow sha HEAD.
- name: Setup | Checkout Repository at workflow sha
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.sha }}

- name: Setup | Force correct release branch on workflow sha
run: |
git checkout -B ${{ github.ref_name }} ${{ github.sha }}
- name: Action | Semantic Version Release
id: release
# Adjust tag with desired version if applicable.
uses: python-semantic-release/python-semantic-release@v9.14.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
git_committer_name: "github-actions"
git_committer_email: "actions@users.noreply.github.com"

- name: Publish | Upload to GitHub Release Assets
uses: python-semantic-release/publish-action@v9.14.0
if: steps.release.outputs.released == 'true'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.release.outputs.tag }}


publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- release
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/django2pydantic

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ $RECYCLE.BIN/

# End of https://www.toptal.com/developers/gitignore/api/macos,linux,windows,visualstudiocode,python,django,pycharm+all

.testmondata
.testmondata*
.import_linter_cache
lcov.info
debug.json
41 changes: 18 additions & 23 deletions .importlinter
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[importlinter]
root_package = superschema
root_package = django2pydantic
include_external_packages = True


Expand All @@ -8,28 +8,23 @@ name = Lower layers shall not import from higher layers
type = layers

containers =
superschema
django2pydantic

layers =
handlers
registry
schema

ignore_imports =
superschema.schema -> superschema.registry

superschema.registry -> superschema.handlers.base
superschema.schema -> superschema.registry
superschema.schema -> superschema.handlers
superschema.registry -> superschema.handlers.base
django2pydantic.registry -> django2pydantic.handlers.base


[importlinter:contract:tests-restrictions]
name = Source code shall not import anything from tests
type = forbidden

source_modules =
superschema
django2pydantic

forbidden_modules =
tests
Expand All @@ -39,18 +34,18 @@ forbidden_modules =
name = Handlers shall be independent
type = independence
modules =
superschema.handlers.auto
superschema.handlers.base
superschema.handlers.boolean
superschema.handlers.file
superschema.handlers.json
superschema.handlers.network
superschema.handlers.numbers
superschema.handlers.property
superschema.handlers.relational
superschema.handlers.text
superschema.handlers.time
django2pydantic.handlers.auto
django2pydantic.handlers.base
django2pydantic.handlers.boolean
django2pydantic.handlers.file
django2pydantic.handlers.json
django2pydantic.handlers.network
django2pydantic.handlers.numbers
django2pydantic.handlers.property
django2pydantic.handlers.relational
django2pydantic.handlers.text
django2pydantic.handlers.time
ignore_imports =
superschema.handlers.* -> superschema.handlers.base
superschema.handlers.relational -> superschema.registry
superschema.registry -> superschema.handlers.base
django2pydantic.handlers.* -> django2pydantic.handlers.base
django2pydantic.handlers.relational -> django2pydantic.registry
django2pydantic.registry -> django2pydantic.handlers.base
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"ms-azuretools.vscode-docker",
"github.vscode-github-actions",
"ms-python.isort",
"ms-toolsai.jupyter"
"ms-toolsai.jupyter",
"ms-vscode.makefile-tools"
]
}
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: superschema
title: django2pydantic
message: >-
If you use this software, please cite it using the
metadata from this file.
Expand All @@ -11,7 +11,7 @@ authors:
- given-names: Jukka
family-names: Hassinen
email: jukka.hassinen@gmail.com
repository-code: 'https://github.com/jhassine/superschema'
repository-code: 'https://github.com/NextGenContributions/django2pydantic'
abstract: Convert Django models to Pydantic models/schema
keywords:
- Django
Expand Down
60 changes: 60 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Contribution guidelines

Contributions are welcome! Here are some guidelines to help you get started.

## Support the project

If you like this project and want to support it, you can:

- Give it a star on GitHub.
- Share it with others.
- Report issues or request new features.
- Contribute code, documentation, or tests.
- Sponsor the project on GitHub.


## Reporting issues

If you find a bug or have a feature request, please open an issue. Make sure to include a detailed description of the issue or feature request, and include any relevant information that can help us reproduce the issue.


## Contributing code

### Setup development environment

If you are using Visual Studio Code, you can use the included devcontainer in order to quickly set up a proper development environment.

### Discuss your changes

If you are planning to make a significant change, it is a good idea to discuss it first with the project authors. You can open an issue to discuss your changes or discuss it with other contributors the project's discussion channels.

### Implement your changes

Make your changes in a new git branch. Make sure to add tests for your changes.

### Run the tests and checks

In order for your changes to be accepted, they must pass all the tests and checks. We are using `nox` to run the tests and checks.
The tests and checks are defined in the [noxfile.py](noxfile.py) file.

You can run `nox` locally to run the tests and checks:

```shell
nox
```

### Add yourself to the contributors list

If you want to get credit from your contribution, add yourself to the following files:

- [pyproject.toml](pyproject.toml)
- [CITATION.cff](CITATION.cff)

### Create a pull request

Once you are happy with your changes, create a pull request. Make sure to include a description of your changes and why they are needed.

### Review process

Your pull request will be reviewed by the project maintainers. They may ask for changes or suggest improvements. Once your pull request is approved, it will be merged into the main branch.

1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ FROM python:3.12-bookworm

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV POETRY_VIRTUALENVS_CREATE=0

RUN apt-get update && apt-get install -y --no-install-recommends \
watchman \
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Jukka Hassinen
Copyright (c) 2024 See CITATION.cff for the full list of authors

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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# What

SuperSchema is a library that allows to define Pydantic schemas based on Django database models.
django2pydantic is a library that allows to define Pydantic schemas based on Django database models.

Similar libraries:
- [Djantic](https://jordaneremieff.github.io/djantic/)
Expand All @@ -9,7 +9,7 @@ Similar libraries:

# Why

SuperSchema is the most complete Pydantic schemas based on Django models.
django2pydantic is the most complete Pydantic schemas based on Django models.

# Key features

Expand Down
7 changes: 7 additions & 0 deletions django2pydantic/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Super schema packages."""

from django2pydantic.schema import django2pydantic
from django2pydantic.types import Infer, InferExcept, MetaFields, ModelFields

__all__ = ["Infer", "InferExcept", "ModelFields", "MetaFields", "django2pydantic"]
__version__ = "0.0.0"
14 changes: 7 additions & 7 deletions superschema/base.py → django2pydantic/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
from pydantic.fields import FieldInfo
from pydantic_core import PydanticUndefined

from superschema.defaults import field_type_registry
from superschema.mixin import BaseMixins
from superschema.registry import FieldTypeRegistry
from superschema.types import Infer, InferExcept, ModelFields
from django2pydantic.defaults import field_type_registry
from django2pydantic.mixin import BaseMixins
from django2pydantic.registry import FieldTypeRegistry
from django2pydantic.types import Infer, InferExcept, ModelFields

SupportedParentFields = (
models.Field[Any, Any]
Expand Down Expand Up @@ -251,7 +251,7 @@ def create_pydantic_model(


class SuperSchemaResolver(ModelMetaclass):
"""Metaclass for SuperSchema."""
"""Metaclass for django2pydantic."""

@override
def __new__( # pylint: disable=W0222,C0204
Expand All @@ -261,8 +261,8 @@ def __new__( # pylint: disable=W0222,C0204
namespace: Namespace,
**kwargs: Kwargs,
) -> type[BaseModel]:
"""Create a new SuperSchema class."""
if name == "SuperSchema":
"""Create a new django2pydantic class."""
if name == "django2pydantic":
return super().__new__(cls, name, bases, namespace, **kwargs)

if "Meta" not in namespace:
Expand Down
6 changes: 3 additions & 3 deletions superschema/defaults.py → django2pydantic/defaults.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Default field type handlers for superschema."""
"""Default field type handlers for django2pydantic."""

from superschema import handlers
from superschema.registry import FieldTypeRegistry
from django2pydantic import handlers
from django2pydantic.registry import FieldTypeRegistry

field_type_registry: FieldTypeRegistry = FieldTypeRegistry.instance()
field_type_registry.register(handlers.CharFieldHandler)
Expand Down
File renamed without changes.
Loading

0 comments on commit 864ec24

Please sign in to comment.