Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Test
on:
push:
branches:
- main
tags:
- "v[0-9]+.*"
pull_request:
branches:
- "*"

workflow_dispatch:

env:
python-version: "3.14"

jobs:
test-matrix:
name: Python ${{ matrix.python-version }}, Django ${{ matrix.django-version }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- python-version: "3.10"
django-version: "5.2"
- python-version: "3.11"
django-version: "5.2"
- python-version: "3.12"
django-version: "5.2"
- python-version: "3.13"
django-version: "5.2"
- python-version: "3.14"
django-version: "5.2"

- python-version: "3.13"
django-version: "6.0"
- python-version: "3.14"
django-version: "6.0"

steps:
- uses: actions/checkout@v6

- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install
shell: bash -l {0}
run: |
pip install -e.[testing] "Django~=${DJANGO_VERSION}"
env:
DJANGO_VERSION: ${{ matrix.django-version }}

- name: Test
shell: bash -l {0}
run: |
./runtests.py

lint:
name: Lint and docs
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v6

- uses: actions/setup-python@v6
with:
python-version: ${{ env.python-version }}
cache: 'pip'

- name: Install
shell: bash -l {0}
run: |
pip install -e.[testing,docs]
env:
DJANGO_VERSION: ${{ matrix.django-version }}

- name: Lint
shell: bash -l {0}
run: |
ruff check enumchoicefield/

- name: Docs
shell: bash -l {0}
run: |
cd ./docs
make SPHINXOPTS=-nW clean html
23 changes: 13 additions & 10 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import os
import sys
import importlib.metadata
import pathlib
import tomllib
from packaging import version as _version

import sphinx_rtd_theme
from enumchoicefield.version import version as module_version

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down Expand Up @@ -52,19 +53,24 @@

# General information about the project.
project = 'Django EnumChoiceField'
copyright = '2016, Tim Heap'
copyright = '2026, Tim Heap'
author = 'Tim Heap'

version = '.'.join(module_version.split('.')[:2])
with open(pathlib.Path(__file__).parent.parent / 'pyproject.toml', 'rb') as f:
_pyproject = tomllib.load(f)

# The full version, including alpha/beta/rc tags.
release = module_version
release = _pyproject['project']['version']
# The major.minor version
_v = _version.parse(release)
version = f'{_v.major}.{_v.minor}'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = 'en'

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
Expand Down Expand Up @@ -118,9 +124,6 @@
# a list of builtin themes.
html_theme = "sphinx_rtd_theme"

# Add any paths that contain custom themes here, relative to this directory.
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
Expand Down
2 changes: 0 additions & 2 deletions docs/requirements.txt

This file was deleted.

5 changes: 3 additions & 2 deletions enumchoicefield/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import absolute_import, unicode_literals
import importlib.metadata

from .enum import ChoiceEnum
from .fields import EnumChoiceField
from .version import version

__all__ = ['ChoiceEnum', 'EnumChoiceField', 'version']

version = importlib.metadata.version('django-enumchoicefield')
2 changes: 0 additions & 2 deletions enumchoicefield/enum.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, unicode_literals

import enum


Expand Down
2 changes: 0 additions & 2 deletions enumchoicefield/fields.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, unicode_literals

from django.db.models.fields import Field

from .forms import EnumField
Expand Down
2 changes: 1 addition & 1 deletion enumchoicefield/tests/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ def test_exact(self):
ChoiceModel.objects.get(choice=MyEnum.foo))

def test_in(self):
self.assertQuerysetEqual(
self.assertQuerySetEqual(
ChoiceModel.objects.filter(choice__in=[MyEnum.bar, MyEnum.baz]),
[self.bar, self.baz], transform=lambda x: x)
19 changes: 13 additions & 6 deletions enumchoicefield/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import django
from django import forms
from django.core.exceptions import ValidationError
from django.forms.utils import flatatt
Expand All @@ -23,10 +22,18 @@ class TranslatedEnum(ChoiceEnum):


class SelectTestCase(SimpleTestCase):
def assertSelectOptions(self, html, options, required=True, name='choice'):
attrs = {'id': 'id_' + name, 'name': name}
if django.VERSION >= (1, 10) and required:
attrs['required'] = True
def assertSelectOptions(self, html, options, required=True, name='choice', error=False):
attrs = {
'id': 'id_' + name,
'name': name,
'required': required,
}
if error:
attrs.update({
'aria-describedby': 'id_' + name + '_error',
'aria-invalid': 'true',
})

select = '<select{attrs}>{options}</select>'.format(
attrs=flatatt(attrs), options=''.join(options))
self.assertHTMLEqual(select, html)
Expand Down Expand Up @@ -143,7 +150,7 @@ def test_invalid_choice(self):
'<option value="foo">Foo</option>',
'<option value="bar">Bar</option>',
'<option value="baz">Baz Quux</option>',
])
], error=True)


class TestLimitedMembers(SelectTestCase):
Expand Down
2 changes: 0 additions & 2 deletions enumchoicefield/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, unicode_literals

from django.db.models import Case, IntegerField, When


Expand Down
1 change: 0 additions & 1 deletion enumchoicefield/version.py

This file was deleted.

54 changes: 54 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[build-system]
requires = [
"setuptools >= 35.0.2",
]
build-backend = "setuptools.build_meta"

[project]
name = "django-enumchoicefield"
version = "3.0.1"
description = "A choice field for Django using native Python Enums"
authors = [
{name = "Tim Heap", email = "tim@timheap.me"},
]
license = "BSD-2-Clause"
license-files = ["LICENSE"]
requires-python = ">=3.10"
dependencies = [
"Django>=5.2"
]

dynamic = ["readme"]

classifiers = [
"Environment :: Web Environment",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Framework :: Django",
]

[project.optional-dependencies]
testing = [
"dj-database-url~=3.1.2",
"ruff",
]

docs = [
"Sphinx~=9.1.0",
"sphinx_rtd_theme",
]

[project.urls]
Documentation = "https://django-enumchoicefield.readthedocs.io/"
Source = "https://github.com/mx-moth/django-enumchoicefield"

[tool.setuptools.dynamic]
readme = {file = ["README.rst"], content-type = "text/x-rst"}

[tool.isort]
line_length = 79
multi_line_output = 4
known_first_party = "enumchoicefield,tests"
skip = "migrations"
2 changes: 0 additions & 2 deletions requirements-dev.txt

This file was deleted.

1 change: 0 additions & 1 deletion requirements-test.txt

This file was deleted.

13 changes: 0 additions & 13 deletions setup.cfg

This file was deleted.

46 changes: 0 additions & 46 deletions setup.py

This file was deleted.

Loading