Skip to content

Commit

Permalink
update dependecies and modernize
Browse files Browse the repository at this point in the history
  • Loading branch information
gablooge committed Oct 4, 2024
1 parent e287caa commit 151b8ee
Show file tree
Hide file tree
Showing 21 changed files with 1,248 additions and 1,587 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Install virtualenv from poetry
uses: 20c/workflows/poetry@v1
- name: Install uv
uses: astral-sh/setup-uv@v2
- name: deploy mkdocs gh-pages site
run: |
poetry run mkdocs gh-deploy --force
uv run mkdocs gh-deploy --force
35 changes: 18 additions & 17 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,36 @@ jobs:
linting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install virtualenv from poetry
uses: 20c/workflows/poetry@v1
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v2
- name: install project
run: uv sync --all-extras --dev
- name: Run linters
run: |
poetry run pre-commit run --all-files
uv run pre-commit run --all-files
test:
needs: linting
strategy:
fail-fast: true
fail-fast: false
matrix:
os: [ "ubuntu-latest", "macos-latest" ]
python-version: [ "3.8", "3.9", "3.10", "3.11" ]
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
runs-on: ${{ matrix.os }}
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Install virtualenv from poetry
uses: 20c/workflows/poetry@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v2
- name: Install python
run: uv python install ${{ matrix.python-version }}
- name: install tox
run: uv sync --all-extras --dev
- name: Run tests
run: tox
run: uv run tox
- name: Upload coverage
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
dist
coverage.xml
release.sh
.venv
30 changes: 15 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@

fail_fast: true
fail_fast: false
exclude: |
(?x)^(
tests/data/.*
)$
repos:
- repo: local
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: system
name: isort
entry: poetry run isort .
language: system
pass_filenames: false
- id: check-yaml
- id: trailing-whitespace
- repo: local
hooks:
- id: pyupgrade
name: pyupgrade
entry: poetry run pyupgrade --py37-plus
entry: uv run pyupgrade --py36-plus
language: python
types: [python]
pass_filenames: true
- repo: local
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.14
hooks:
- id: system
name: Black
entry: poetry run black .
language: system
pass_filenames: false
- id: ruff
args: [--fix]
- id: ruff-format
2 changes: 1 addition & 1 deletion docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ A user gets his permissions directly or from one of the auth Groups he is a memb

## Custom permission holders

Sometimes you want something else than a user or group model to hold
Sometimes you want something else than a user or group model to hold
permissions - an APIkey implementation for example

```py
Expand Down
3 changes: 1 addition & 2 deletions examples/custom_permission_holder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.db import models

from django_grainy.models import Permission, PermissionManager
from django_grainy.util import Permissions


class APIKey(models.Model):
Expand All @@ -19,8 +20,6 @@ class APIKeyPermission(Permission):
objects = PermissionManager()


from django_grainy.util import Permissions

api_key = APIKey.objects.create(key="test")
api_key.grainy_permissions.add_permission("a.b.c", "r")

Expand Down
2 changes: 1 addition & 1 deletion examples/grainy_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ def detail_view(request, id):
# ignore the user's superuser priviledges
ignore_grant_all=True,
)
def detail_view(request, id):
def detail_view(request, id): # noqa: F811
return HttpResponse()
2 changes: 0 additions & 2 deletions examples/remote/receiver/permissions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from django.conf import settings

import django_grainy.remote


Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
site_name: django-grainy
site_name: django-grainy
site_url: https://github.com/20c/grainy-perms

theme: readthedocs
Expand Down
1,435 changes: 0 additions & 1,435 deletions poetry.lock

This file was deleted.

107 changes: 54 additions & 53 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,66 +1,67 @@
[tool.poetry]
[project]
name = "django-grainy"
repository = "https://github.com/20c/django-grainy"
description = "granular permissions for django"
readme = "README.md"
license = {file = "LICENSE"}
version = "2.0.0"
description = "granular permissions for django"
authors = [ "20C <code@20c.com>",]
license = "LICENSE.txt"
authors = [{name = "20C", email = "code@20c.com"}]
requires-python = ">=3.8,<4.0"
classifiers = [
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]

packages = [
{ include = "django_grainy", from = "src" },
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: Apache Software License",
"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",
]

[tool.poetry.dependencies]
python = "^3.8"
grainy = ">=1.7.0,<2"
six = ">=1.11.0,<=2.0.0"
djangorestframework = ">=3.0,<4.0"
Django = ">=3.2,<5"
black = "^22.3.0"
[[project.packages]]
include = "django_grainy"
from = "src"

[tool.poetry.dev-dependencies]
# test
pytest = ">=6.0.1"
pytest-django = ">=3.8.0"
coverage = ">=4.1"
pytest-cov = ">=2.2.1"
tox = "^3.25.0"
tox-gh-actions = ">=2.9.1"


# lint
bandit = "^1.6.2"
black = "^22.1"
isort = "^5.7.0"
flake8 = "^3.8.4"
pre-commit = "^2.13.0"
pyupgrade = "^2.34.0"
dependencies = [
"grainy >=1.7.0,<2",
"six >=1.11.0,<=2.0.0",
]

# docs
markdown-include = ">=0.5"
mkdocs = "^1.2.3"
[project.optional-dependencies]
dev = [
"django >=3.2,<5",
"djangorestframework >=3.0,<4.0",
# lint
"pre-commit >=2.13.0",
"pyupgrade >=2.34.0",
"ruff>=0.1",
# test
"pytest >=6.0.1",
"pytest-django >=3.8.0",
"coverage >=4.1",
"pytest-cov >=2.2.1",
"tox >=3.25.0",
"tox-gh-actions >=2.9.1",
"tox-uv>=1.13.0",
# docs
"markdown-include >=0.5",
"mkdocs >=1.2.3",
# ctl
"ctl >=1",
"jinja2 >=3",
"tmpl >=1",
]

# ctl
ctl = "^1"
jinja2 = "^3"
tmpl = "^1"
# .ruff.toml
[tool.ruff]
ignore = ["F821"]

[tool.poetry.plugins."markdown.extensions"]
pymdgen = "pymdgen.md:Extension"
[tool.hatch.metadata]
allow-direct-references = true

[build-system]
requires = [ "poetry>=0.12",]
build-backend = "poetry.masonry.api"
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.isort]
profile = "black"
multi_line_output = 3
# temporary solution for https://github.com/python-poetry/poetry/issues/9293
[[project.source]]
name = "pypi-public"
url = "https://pypi.org/simple/"
4 changes: 2 additions & 2 deletions src/django_grainy_test/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
)

router = routers.DefaultRouter()
router.register(r"a", ModelAViewSet)
router.register(r"a_x", ExplicitViewSet)
router.register(r"a", ModelAViewSet, basename="modela")
router.register(r"a_x", ExplicitViewSet, basename="explicit_modela")


urlpatterns = [
Expand Down
3 changes: 1 addition & 2 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.db import models
from grainy.const import PERM_CREATE, PERM_DELETE, PERM_READ, PERM_UPDATE
from grainy.const import PERM_READ, PERM_UPDATE
from grainy.core import PermissionSet

from django_grainy.backends import GrainyBackend
Expand Down
4 changes: 2 additions & 2 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from grainy.const import PERM_CREATE, PERM_DELETE, PERM_READ, PERM_UPDATE

from django_grainy.fields import PermissionField, PermissionFormField
from django_grainy.models import GroupPermission, UserPermission
from django_grainy.fields import PermissionFormField
from django_grainy.models import UserPermission

from .util import UserTestCase

Expand Down
2 changes: 1 addition & 1 deletion tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_request_to_flag(self):
def test_dict_get_namespace(self):
namespace = Namespace("a.b.c")
self.assertEqual(dict_get_namespace({"a": {"b": {"c": 123}}}, namespace), 123)
with self.assertRaises(KeyError) as inst:
with self.assertRaises(KeyError):
self.assertEqual(dict_get_namespace({}, namespace), 123)

def test_int_flags(self):
Expand Down
5 changes: 1 addition & 4 deletions tests/test_manager.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from django.db import models
from grainy.const import PERM_CREATE, PERM_DELETE, PERM_READ, PERM_UPDATE

from django_grainy.decorators import grainy_model
from django_grainy.handlers import GrainyHandler
from django_grainy.models import GroupPermission, PermissionSet, UserPermission
from django_grainy.models import PermissionSet
from django_grainy_test.models import ModelA, ModelB

from .util import UserTestCase
Expand Down
6 changes: 0 additions & 6 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
from django.db import models
from grainy.const import PERM_CREATE, PERM_DELETE, PERM_READ, PERM_UPDATE

from django_grainy.decorators import grainy_model
from django_grainy.handlers import GrainyHandler
from django_grainy.models import GroupPermission, UserPermission
from django_grainy_test.models import (
ModelA,
ModelB,
Expand Down
14 changes: 5 additions & 9 deletions tests/test_permissions.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import json

from django.contrib.auth.models import AnonymousUser
from django.db import models
from django.test import Client, RequestFactory
from django.test.utils import override_settings
from django.test import RequestFactory
from grainy.const import PERM_CREATE, PERM_DELETE, PERM_READ, PERM_UPDATE

from django_grainy.decorators import grainy_model
from django_grainy.handlers import GrainyHandler
from django_grainy.models import GroupPermission, PermissionSet, UserPermission
from django_grainy.util import Permissions, int_flags, namespace, str_flags
from django_grainy_test.models import APIKey, APIKeyPermission, ModelA, ModelB
from django_grainy_test.views import Detail, JsonView, View, detail, view
from django_grainy.models import PermissionSet
from django_grainy.util import Permissions
from django_grainy_test.models import APIKey, ModelA, ModelB
from django_grainy_test.views import JsonView, View, view

from .util import UserTestCase

Expand Down
2 changes: 0 additions & 2 deletions tests/test_rest_framework.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from django.test import RequestFactory
from grainy.const import PERM_CREATE, PERM_DELETE, PERM_READ, PERM_UPDATE
from grainy.core import PermissionSet
from rest_framework.test import APIClient

from django_grainy_test.models import ModelA
from django_grainy_test.views import ModelAViewSet

from .util import UserTestCase

Expand Down
Loading

0 comments on commit 151b8ee

Please sign in to comment.