Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #32 from kreneskyp/django4.1
Browse files Browse the repository at this point in the history
Django4.1
  • Loading branch information
jdavisp3 authored Jan 11, 2024
2 parents 846a56a + 4ec885d commit 365fa31
Show file tree
Hide file tree
Showing 23 changed files with 173 additions and 45 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: test

on: [push]

jobs:
test:
runs-on: ubuntu-latest
strategy:
max-parallel: 3
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get update -y && sudo apt-get install -y libldap2-dev libssl-dev libsasl2-dev
python -m pip install --upgrade pip
python -m venv venv
source venv/bin/activate
pip install -r requirements-setup.txt
- name: Test with tox
run: |
source venv/bin/activate
tox -vv
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
sudo apt-get update -y && sudo apt-get install -y libldap2-dev libssl-dev libsasl2-dev
python -m pip install --upgrade pip
python -m venv venv
source venv/bin/activate
pip install -r requirements-setup.txt
- name: lint
run: |
source venv/bin/activate
tox -vv -e lint
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
2.1.0: Add support for django 4.0, 4.1. Add support for Python 3.10, 3.11.
2.0.3: remove upper bound on django requirement
2.0.2: Bump py, flake8 and other dependencies for security.
2.0.0: Support for django 2.0, 2.1, 2.2. Add support for Python3.7. Drop support for Python 2.7
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WITH_VENV=. $(VENV_ACTIVATE);
ifdef TRAVIS_PYTHON_VERSION
PYTHON=python$(TRAVIS_PYTHON_VERSION)
else
PYTHON=python3.6
PYTHON=python3.9
endif

ifdef TOX_ENV
Expand Down Expand Up @@ -50,7 +50,7 @@ teardown:

.PHONY: lint
lint: venv
$(WITH_VENV) flake8 -v $(PACKAGE_NAME)/
$(WITH_VENV) tox -e lint

.PHONY: test
test: venv
Expand Down
2 changes: 1 addition & 1 deletion baya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
__version__ # silence codequality

from .membership import RolesNode
from . import permissions # nopep8
from . import permissions # noqa: F401
from .permissions import requires

SetMembershipNode = RolesNode # For backwards compatibility purposes.
Expand Down
2 changes: 1 addition & 1 deletion baya/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.0.3"
__version__ = "2.1.0"
4 changes: 2 additions & 2 deletions baya/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from baya.admin.options import BayaModelAdmin # nopep8
from baya.admin.options import BayaInlineMixin # nopep8
from baya.admin.options import BayaModelAdmin # noqa: F401
from baya.admin.options import BayaInlineMixin # noqa: F401
2 changes: 1 addition & 1 deletion baya/admin/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BayaInlineMixin(object):
UPDATE = ALLOW_ALL
DELETE = ALLOW_ALL

def has_add_permission(self, request):
def has_add_permission(self, request, obj=None):
return has_permission(requires(self.CREATE), request.user, 'post')

def has_change_permission(self, request, obj=None):
Expand Down
9 changes: 6 additions & 3 deletions baya/admin/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
from operator import or_

import django
from django.conf.urls import url
from django.conf.urls import include
if django.VERSION[:2] < (4, 0):
from django.conf.urls import url, include
else:
from django.urls import include, re_path
url = re_path
from django.contrib.admin.sites import AdminSite

from baya.permissions import requires
Expand Down Expand Up @@ -81,7 +84,7 @@ def get_urls(self):
# django >= 2.0 pattern must be compiled into regex
if sys.version_info[0] == 3 and sys.version_info[1] <= 6:
# python 3.0 through 3.6 must escape slashes in the regex
escaped_pattern = pattern.replace('/', '\/')
escaped_pattern = pattern.replace('/', '\/') # noqa: W605
else:
escaped_pattern = pattern
compiled_pattern = re.compile(escaped_pattern)
Expand Down
2 changes: 1 addition & 1 deletion baya/dynamic_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def my_view(request, thing):
url(r'my_view/(?P<param>\w+)/',
requires(DynamicRolesNode(DjangoRequestGroupFormatter(
"%s_admin", 'thing')))(path.to.my_view),
)
) # noqa
Then the named reverse kwarg named `param` will always take precedence over
a url query parameter named `param`. For example:
Expand Down
11 changes: 9 additions & 2 deletions baya/permissions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import collections
import functools
import sys

if sys.version_info[:2] >= (3, 10):
collections.Callable = collections.abc.Callable

import django
from django.conf import settings
Expand Down Expand Up @@ -180,8 +184,11 @@ def __iadd__(self, other):
self.get_requires &= other.get_requires
self.post_requires &= other.post_requires
# Prefer other's login_url, if set
if (other.login_url is not None and
six.text_type(other.login_url) != six.text_type(settings.BAYA_LOGIN_URL)): # nopep8
login_text_type = six.text_type(settings.BAYA_LOGIN_URL)
if (
other.login_url is not None and
six.text_type(other.login_url) != login_text_type
):
self.login_url = other.login_url
return self

Expand Down
7 changes: 6 additions & 1 deletion baya/tests/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from django.conf.urls import url
import django
if django.VERSION[:2] < (4, 0):
from django.conf.urls import url
else:
from django.urls import re_path
url = re_path
from django.contrib import admin
from django.shortcuts import render

Expand Down
7 changes: 6 additions & 1 deletion baya/tests/nested_urls1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from django.conf.urls import include, url
import django
if django.VERSION[:2] < (4, 0):
from django.conf.urls import url, include
else:
from django.urls import include, re_path
url = re_path

from baya.permissions import requires

Expand Down
8 changes: 7 additions & 1 deletion baya/tests/nested_urls2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from django.conf.urls import url
import django

if django.VERSION[:2] < (4, 0):
from django.conf.urls import url
else:
from django.urls import re_path
url = re_path

from baya.permissions import requires

Expand Down
7 changes: 6 additions & 1 deletion baya/tests/submod2/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from django.conf.urls import url
import django
if django.VERSION[:2] < (4, 0):
from django.conf.urls import url
else:
from django.urls import re_path
url = re_path

from . import admin

Expand Down
2 changes: 1 addition & 1 deletion baya/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def test_entries_displayed(self):

def test_perms_correct(self):
def _check(inline, request, add, change, delete):
self.assertEqual(inline.opts.has_add_permission(request), add)
self.assertEqual(inline.opts.has_add_permission(request, obj=None), add)
self.assertEqual(
inline.opts.has_change_permission(request), change)
self.assertEqual(
Expand Down
9 changes: 8 additions & 1 deletion baya/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
from django.contrib.auth.models import Group
from django.contrib.auth.models import AnonymousUser
from django.core.exceptions import PermissionDenied
from django.middleware.csrf import _salt_cipher_secret, _get_new_csrf_string
from django.middleware.csrf import _get_new_csrf_string
from django.test import TestCase

if django.VERSION[:2] <= (2, 2):
from django.middleware.csrf import _salt_cipher_secret
else:
from django.middleware.csrf import _mask_cipher_secret
_salt_cipher_secret = _mask_cipher_secret


from . import directory
from ..mock_ldap_helpers import mock_ldap_setup

Expand Down
14 changes: 5 additions & 9 deletions baya/tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
from types import FunctionType

import six
import django
from django.conf import settings
from django.conf.urls import include
if django.VERSION[:2] < (4, 0):
from django.conf.urls import include
else:
from django.urls import include
from django.urls import reverse_lazy
from django.http import HttpResponse
from django.test.utils import override_settings
Expand Down Expand Up @@ -297,14 +301,6 @@ def test_class_view_as_view_method(self):
self.assertTrue(hasattr(decorated1, '_gate'))
self.assertNotEqual(decorated1._gate, decorated2._gate)

def test_functools_bare_partial(self):
"""Test that a bare functools.partial cannot be decorated."""
def pseudoview(request, foo):
pass

self.assertRaises(ValueError, requires(A),
functools.partial(pseudoview, foo=1))

def test_functools_partial(self):
"""Test that a functools.partial is able to be decorated."""
def pseudoview(request, foo):
Expand Down
8 changes: 7 additions & 1 deletion baya/tests/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import django
from django.urls import reverse_lazy
from django.conf.urls import include, url
from django.contrib.auth.views import LoginView
from django.views.generic import ListView
from django.contrib import admin
Expand All @@ -19,6 +19,12 @@
from . import nested_urls1
from .submod2 import urls as sub2_urls

if django.VERSION[:2] < (4, 0):
from django.conf.urls import url, include
else:
from django.urls import include, re_path
url = re_path

A = g('a')
AA = g('aa')
AAA = g('aaa')
Expand Down
7 changes: 4 additions & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
coverage==5.1
django-nose==1.4.6
funcparserlib==0.3.6
mock==1.0.1
mockldap==0.2.6
nose==1.3.7
pycodestyle==2.0.0
pyflakes==0.9
flake8==2.6.2
pycodestyle==2.9.1
pyflakes==2.5.0
flake8==5.0.4
22 changes: 17 additions & 5 deletions requirements-setup.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
# Requirements needed for the setup make target and the test target
# outside of the individual tox environments.

Django>=1.11,<2.0
pluggy==0.3.0
py==1.10.0
tox==2.0.1
virtualenv==16.7.4
pluggy==1.0.0
py==1.11.0
tox==3.27.1
tox-pyenv==1.1.0
tox-setuptools-version==0.0.0.3
tox-gh-actions==2.11.0
virtualenv==20.16.7
xunitmerge==1.0.4

# dependencies
filelock>=3.0.0 # tox
packaging>=14 # tox
tomli>=2.0.1 # tox
importlib_resources==5.10.0 # tox-gh-actions
zipp==3.10.0 # tox-gh-actions
pyparsing==3.0.9
platformdirs==2.5.4
distlib==0.3.6
2 changes: 0 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
[flake8]
max-line-length = 99
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ def load_version():
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
install_requires=[
'django-auth-ldap>=1.2.8',
'Django>=1.11',
'Django>=2.2',
'six>=1.3',
],
packages=find_packages(exclude=[
Expand Down
30 changes: 25 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
[tox]
install_command = pip install {opts} {packages}
downloadcache = {toxworkdir}/_download/
envlist = {py36}-{1.11,2.0,2.1}
envlist = {py37}-django{3.1,3.2},{py38,py39,py310,py311}-django{3.1,3.2,4.0,4.1}
indexserver =
default = https://pypi.python.org/simple


[testenv]
setuptools_version = setuptools<58.0
usedevelop = True
commands =
coverage run --omit="*tests*" --source=baya --branch \
./baya/tests/manage.py test {posargs:baya}
deps =
-r{toxinidir}/requirements-dev.txt
1.11: Django>=1.11,<2.0
2.0: Django>=2.0,<2.1
2.1: Django>=2.1,<2.2
django3.1: Django>=3.1,<3.2
django3.2: Django>=3.2,<3.3
django4.0: Django>=4.0,<4.1
django4.1: Django>=4.1,<4.2


[testenv:lint]
whitelist_externals = flake8
commands =
flake8 -v baya/


[flake8]
ignore = E731,E402
max-line-length = 99
ignore = E731,E402,W504


[gh-actions]
python =
3.7: py37
3.8: py38
3.9: py39
3.10: py310
3.11: py311

0 comments on commit 365fa31

Please sign in to comment.