Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Django 4 and latest Python versions #9

Merged
merged 14 commits into from
Jan 10, 2024
Merged
27 changes: 27 additions & 0 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Publish Python distribution to PyPI

on: push

jobs:
publish-to-pypi:
name: Publish Python distribution to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/metaset
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Install pypa/build
run: pip install build
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
21 changes: 6 additions & 15 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
name: Quality

on:
push:
pull_request:
schedule:
- cron: '0 0 * * 0' # weekly
on: push

jobs:
build:
name: quality
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install --upgrade black flake8
- name: Run checks
run: |
make quality
run: make quality
37 changes: 19 additions & 18 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: Tests

on:
push:
pull_request:
schedule:
- cron: '0 0 * * 0' # weekly
on: push

jobs:
build:
Expand All @@ -30,25 +26,30 @@ jobs:
strategy:
matrix:
python-version:
- 3.6
- 3.7
- 3.8
- 3.9
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
django:
- django22
- django31
- django32
- django42
- django50
exclude:
- django: django50
python-version: "3.8"
- django: django50
python-version: "3.9"
- django: django32
python-version: "3.11"
- django: django32
python-version: "3.12"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
Expand Down
49 changes: 0 additions & 49 deletions .travis.yml

This file was deleted.

7 changes: 6 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
1.4.2 (unreleased)
------------------

- Nothing changed yet.
- Add support for Python 3.11 & 3.12
- Add support for Django 4.2 & 5.0
- Add support for Python 3.10
- Drop support for Python 3.6 & 3.7
- Drop support for Django 3.1
- Drop support for Django 2.2


1.4.1 (2021-06-24)
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.PHONY: update quality tests clean

update:
pip install -r requirements/dev.txt
pip install -r requirements/tests.txt
sandre35 marked this conversation as resolved.
Show resolved Hide resolved
pip install -r requirements/quality.txt

quality:
black --check --diff metaset tests
Expand Down
4 changes: 2 additions & 2 deletions metaset/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from copy import deepcopy
from itertools import chain, groupby
from pkg_resources import get_distribution
from importlib.metadata import version


__version__ = get_distribution("metaset").version
__version__ = version("metaset")


class MetaSet(dict):
Expand Down
11 changes: 2 additions & 9 deletions metaset/django_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@

try:
from django.utils.translation import gettext_lazy

try:
# Django >= 3.1
from django.db import JSONField
from django.forms import JSONField as JSONFormField
except ImportError:
# For Django < 3.1
from django.contrib.postgres.fields import JSONField
from django.contrib.postgres.forms import JSONField as JSONFormField
from django.db.models import JSONField
from django.forms import JSONField as JSONFormField
# avoid import failures for non Django builds.
except ImportError:
JSONField = object
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
35 changes: 34 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,40 @@
exclude = venv

[metadata]
description-file = README.rst
name = metaset
version = 1.4.2.dev0
author = Polyconseil
author_email = [email protected]
description = A container for dicts of sets - alternative to dictset
long_description = file: README.rst
license = BSD
keywords = metaset, dictset, set, container
url = https://github.com/Polyconseil/metaset
download_url = https://pypi.python.org/pypi/metaset/
classifiers =
Development Status :: 5 - Production/Stable
Intended Audience :: Developers
Natural Language :: English
Programming Language :: Python
License :: OSI Approved :: BSD License
Topic :: Software Development :: Libraries :: Python Modules
Operating System :: OS Independent
Programming Language :: Python
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

[options]
include_package_data = True
packages = find:
python_requires = >=3.8

[options.packages.find]
exclude =
tests*

[zest.releaser]
create-wheel = yes
39 changes: 2 additions & 37 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,4 @@
# Copyright (c) Polyconseil SAS. All rights reserved.
from setuptools import find_packages, setup
from setuptools import setup


def read(filename):
with open(filename) as fp:
return fp.read()


setup(
name="metaset",
version="1.4.2.dev0",
author="Polyconseil",
author_email="[email protected]",
description="A container for dicts of sets - alternative to dictset",
license="BSD",
keywords=["metaset", "dictset", "set", "container"],
url="https://github.com/Polyconseil/metaset",
download_url="http://pypi.python.org/pypi/metaset/",
packages=find_packages(exclude=["tests*"]),
long_description=read("README.rst"),
install_requires=[],
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Natural Language :: English",
"Programming Language :: Python",
"License :: OSI Approved :: BSD License",
"Topic :: Software Development :: Libraries :: Python Modules",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
],
include_package_data=True,
)
setup()
30 changes: 15 additions & 15 deletions tests/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from django.test import TestCase

import pytest

from metaset import MetaSet

from .django_test_app import forms as test_forms
Expand All @@ -17,26 +15,25 @@ def refresh_from_db(obj):

class DjangoTest(TestCase):
def test_save_load(self):
obj = test_models.TestModel.objects.create(value={"a": {1}, "b": {2, 3}})
obj = test_models.TestModel.objects.create(
value={"a": {1}, "b": {2, 3}},
)
obj.full_clean()
obj = refresh_from_db(obj)
assert type(obj.value) == MetaSet, type(obj.value)
assert isinstance(obj.value, MetaSet), type(obj.value)
assert obj.value == MetaSet({"a": {1}, "b": {2, 3}}), obj.value

def test_model_form(self):
obj = test_models.TestModel.objects.create(value={"a": {1}, "b": {2, 3}})
obj = test_models.TestModel.objects.create(
value={"a": {1}, "b": {2, 3}},
)
form = test_forms.TestModelForm(instance=obj)
assert json.loads(form["value"].value()) == {"a": [1], "b": [2, 3]}

def test_query(self):
try:
from django.contrib.postgres.fields import JSONField # noqa: F401
except ImportError:
pytest.skip(
"JSON queries are only available " "for native Django (>=1.9) JSONField"
)

obj = test_models.TestModel.objects.create(value={"a": {1}, "b": {2, 3}})
obj = test_models.TestModel.objects.create(
value={"a": {1}, "b": {2, 3}},
)
res = test_models.TestModel.objects.filter(value__b__contains=[2])
assert obj == res.first(), res
res = test_models.TestModel.objects.filter(value__has_key="a")
Expand All @@ -47,5 +44,8 @@ def test_inception(self):
value={"a": {"b": {1}, "c": {2, 3}}, "d": {"e": {4}}}
)
obj = refresh_from_db(obj)
assert obj.value == MetaSet(a=MetaSet(b={1}, c={2, 3}), d=MetaSet(e={4}))
assert type(obj.value["a"]) == MetaSet, type(obj.value["a"])
assert obj.value == MetaSet(
a=MetaSet(b={1}, c={2, 3}),
d=MetaSet(e={4}),
)
assert isinstance(obj.value["a"], MetaSet), type(obj.value["a"])
Loading