Skip to content

Commit

Permalink
readme and other packaging files
Browse files Browse the repository at this point in the history
  • Loading branch information
KommuSoft committed Sep 16, 2023
1 parent 6dc6b08 commit 491f575
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# https://help.github.com/en/articles/displaying-a-sponsor-button-in-your-repository
custom: https://www.buymeacoffee.com/hapytex
# https://help.github.com/en/articles/displaying-a-sponsor-button-in-your-repository
custom: https://www.buymeacoffee.com/hapytex
166 changes: 166 additions & 0 deletions .github/workflows/django-single-session-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
name: django-single-session CI
on: push
jobs:
black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: psf/black@stable
with:
options: "--check"

test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: sudo apt install python3-django
- run: pip install Django
- run: django-admin startproject testproject
- name: checkout code
uses: actions/checkout@v2.3.1
with:
path: 'testproject_temp'
- run: "mv testproject_temp/* testproject/"
- run: pip install -r requirements.txt
working-directory: 'testproject'
- run: python manage.py test --settings=docs.source.settings
working-directory: 'testproject'

no-makemigrations:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: sudo apt install python3-django
- run: pip install Django
- run: django-admin startproject testproject
- name: checkout code
uses: actions/checkout@v2.3.1
with:
path: 'testproject_temp'
- run: "mv testproject_temp/* testproject/"
- run: pip install -r requirements.txt
working-directory: 'testproject'
- run: python manage.py makemigrations --dry-run --settings=docs.source.settings
working-directory: 'testproject'
shell: bash

no-makemessages:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
locale: [nl]
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: sudo apt install gettext python3-django
- run: pip install Django
- run: django-admin startproject testproject
- name: checkout code
uses: actions/checkout@v2.3.1
with:
path: 'testproject_temp'
- run: |
shopt -s dotglob
mv testproject_temp/* testproject/
- run: pip install -r requirements.txt
working-directory: 'testproject'
- run: python manage.py makemessages --locale=${{ matrix.locale }} --settings=docs.source.settings
working-directory: 'testproject'
- run: git diff --ignore-matching-lines='^"POT-Creation-Date:' --exit-code
working-directory: 'testproject'

no-compilemessages:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: sudo apt install gettext python3-django
- run: pip install Django
- run: django-admin startproject testproject
- name: checkout code
uses: actions/checkout@v2.3.1
with:
path: 'testproject_temp'
- run: |
shopt -s dotglob
mv testproject_temp/* testproject/
- run: pip install -r requirements.txt
working-directory: 'testproject'
- run: python manage.py compilemessages --settings=docs.source.settings
working-directory: 'testproject'
- run: git diff --exit-code
working-directory: 'testproject'

build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
steps:
- name: checkout code
uses: actions/checkout@v2.3.1
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: |
pip install setuptools>=38.6.0 twine>=1.11.0 wheel>=0.31.0 setuptools_scm>=6.2
python -m setuptools_scm
python setup.py sdist bdist_wheel
test-publish:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
needs: [black, build, test, no-makemigrations, no-makemessages, no-compilemessages]
steps:
- name: checkout code
uses: actions/checkout@v2.3.1
- name: Set up Python
uses: actions/setup-python@v4
- run: |
pip install setuptools>=38.6.0 twine>=1.11.0 wheel>=0.31.0 setuptools_scm>=6.2
python -m setuptools_scm
python setup.py sdist bdist_wheel
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_TOKEN }}
repository_url: https://test.pypi.org/legacy/

publish:
runs-on: ubuntu-latest
needs: [test-publish]
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: checkout code
uses: actions/checkout@v2.3.1
- name: Set up Python
uses: actions/setup-python@v4
- run: |
pip install setuptools>=38.6.0 twine>=1.11.0 wheel>=0.31.0 setuptools_scm>=6.2
python -m setuptools_scm
python setup.py sdist bdist_wheel
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }}
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
*.log
*.pot
*.pyc
*.sw[po]
*.sqlite
*.sqlite3

docs/_build
build/
dist/
*.egg-info/
.tox/
.idea/
*.python-version
.coverage

djutils/
manage.py
30 changes: 30 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright Willem Van Onsem (c) 2022

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Willem Van Onsem nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include LICENSE
include README.md
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Django-enforced-choices

[![PyPi version](https://badgen.net/pypi/v/django-enforced-choices/)](https://pypi.python.org/pypi/django-enforced-choices/)
[![Documentation Status](https://readthedocs.org/projects/django-enforced-choices/badge/?version=latest)](http://django-enforced-choices.readthedocs.io/?badge=latest)
[![PyPi license](https://badgen.net/pypi/license/django-enforced-choices/)](https://pypi.python.org/pypi/django-enforced-choices/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

Django does *not* enforce choices at the model level: yes a `ModelForm` can validate these, but unfortunately people oftend define form fields themselves or even worse don't work with any `Form` or `Serializer` at all. So this means that if we define a model:

```
Expand Down Expand Up @@ -29,6 +34,19 @@ This package provides a `ChoicesConstraintModelMixin` mixin to mix into models.

Another option is to import the correspond field from the `django_enforced_choices.fields` module, or `django_enforced_choices.fields.postgres` for PostgreSQL-specific fields. This will, by default, also check if the fields have choices, but we do *not* recommend to use these, since this means the field has for example as type `ChoiceCharField`, and certain Django functionalities (and packages) sometimes check full type equality to determine a widget, not through an `instanceof`. This thus means that certain functionalities might no longer work as intended.

### Usage

One can import the `ChoicesConstraintModelMixin` and mix it into a model, like:

```
from django_enforced_choices.models import ChoicesConstraintModelMixin
class Movie(ChoicesConstraintModelMixin, models.Model):
genre = models.CharField(max_length=1, choices=[('d', 'drama'), ('h', 'horror')])
```

this will then add `CheckConstraint`s to the model to enforce that `genre` only can contain `'d'` and `'h'` at the database side.

## How does the package work?

For the fields defined, it will check if the `choices` are defined. If that is the case, it will create a `CheckConstraint` with `fieldname__in` with the keys in the choices. If the field is NULLable, it will also allow `NULL`/`None` to be used.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
django >= 2.2.0
34 changes: 34 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[metadata]
name = django-enforced-choices
version= file: _version.py
description = A Django package to enforce choices as database constraints.
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/hapytex/django-enforced-choices/
author = Willem Van Onsem
author_email = hapytexeu+gh@gmail.com
license = BSD-3-Clause
classifiers =
Environment :: Web Environment
Framework :: Django
Framework :: Django :: 3.0
Framework :: Django :: 3.1
Framework :: Django :: 3.2
Framework :: Django :: 4.0
Intended Audience :: Developers
License :: OSI Approved :: BSD License
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Topic :: Internet :: WWW/HTTP
Topic :: Internet :: WWW/HTTP :: Dynamic Content

[options]
include_package_data = true
packages = find:
python_requires = >=3.8
install_requires =
Django >= 2.2
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from setuptools import setup

setup()

0 comments on commit 491f575

Please sign in to comment.