Skip to content
Merged
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
36 changes: 19 additions & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
name: Linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.11"
- uses: pre-commit/action@v2.0.3
python-version: "3.14"
- uses: pre-commit/action@v3.0.1

tests:
name: Python ${{ matrix.python-version }}
Expand All @@ -25,15 +25,15 @@ jobs:
max-parallel: 5
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
# - "3.12" # Enable when we get rid of setuptools
- "3.12"
- "3.13"
- "3.14"

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Upgrade packaging tools
Expand All @@ -44,31 +44,33 @@ jobs:
run: |
ENV_PREFIX=$(tr -C -d "0-9" <<< "${{ matrix.python-version }}")
TOXENV=$(tox --listenvs | grep "^py$ENV_PREFIX" | tr '\n' ',') python -m tox
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v6
with:
name: coverage-files
path: ./.coverage.*
name: coverage-files-${{ matrix.python-version }}
path: ./.coverage*
include-hidden-files: true

coverage:
name: Reporting Coverage
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize')
needs: [tests]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.11"
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v6
with:
name: coverage-files
pattern: coverage-files-*
merge-multiple: true
path: .
- name: Combine coverage reports
run: |
python -m pip install coverage
make coverage-lcov
- name: Upload coverage report
uses: coverallsapp/github-action@1.1.3
uses: coverallsapp/github-action@v2.3.6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: "./coverage.info"
39 changes: 7 additions & 32 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,52 +1,27 @@
default_language_version:
python: python3.11
python: python3.14
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v6.0.0
hooks:
- id: check-case-conflict
- id: check-merge-conflict
- id: end-of-file-fixer
- id: trailing-whitespace
- id: debug-statements
- id: detect-private-key
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.15.4'
hooks:
- id: pyupgrade
args:
- --py38-plus
- repo: https://github.com/pycqa/autoflake
rev: v2.2.1
hooks:
- id: autoflake
args:
- --in-place
- --remove-all-unused-imports
- --ignore-init-module-imports
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
- id: ruff-check
- id: ruff-format
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies: [black==23.9.1]
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-comprehensions
- flake8-tidy-imports
- repo: https://github.com/sirosen/check-jsonschema
rev: 0.27.0
rev: 0.37.0
hooks:
- id: check-github-workflows
# - repo: https://github.com/mgedmin/check-manifest
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include setup.py README.md MANIFEST.in LICENSE AUTHORS
include README.md MANIFEST.in LICENSE AUTHORS

recursive-include djedi/templates *
recursive-include djedi/static *
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ help:

.PHONY: test
test:
coverage run setup.py test
python -m coverage run runtests.py

.PHONY: test_all # runs tests using detox, combines coverage and reports it
test_all:
Expand All @@ -29,11 +29,11 @@ lint:

.PHONY: install
install:
python setup.py install
python -m pip install .

.PHONY: develop
develop:
python setup.py develop
python -m pip install -e .

.PHONY: build_example
build_example:
Expand Down
6 changes: 3 additions & 3 deletions djedi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def get_version(version=None):


def configure():
from django.conf import settings as django_settings
from django.conf import settings as django_settings # noqa: PLC0415

from cio.conf import settings
from cio.conf import settings # noqa: PLC0415

# Djedi default config
config = {
Expand Down Expand Up @@ -66,7 +66,7 @@ def configure():
"THEME",
"XSS_DOMAIN",
):
conf = getattr(django_settings, "DJEDI_%s" % setting, None)
conf = getattr(django_settings, f"DJEDI_{setting}", None)
if conf is not None:
config[setting] = conf

Expand Down
24 changes: 13 additions & 11 deletions djedi/admin/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from cio.plugins import plugins
from cio.plugins.exceptions import UnknownPlugin
from cio.utils.uri import URI
from djedi import auth
from djedi.plugins.base import DjediPlugin

from .. import auth
from ..plugins.base import DjediPlugin
from .exceptions import InvalidNodeData
from .mixins import DjediContextMixin, JSONResponseMixin

Expand All @@ -31,7 +31,7 @@ def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)
except Http404:
raise
except Exception as e:
except Exception as e: # noqa: BLE001
return HttpResponseBadRequest(e)

def get_post_data(self, request):
Expand All @@ -55,10 +55,11 @@ def get_post_data(self, request):
field = field[:-1]
try:
data[prefix][field] = value
except TypeError:
except TypeError as exc:
raise InvalidNodeData(
'Got both reserved parameter "data" and plugin specific parameters.'
)
'Got both reserved parameter "data" and '
"plugin specific parameters."
) from exc
else:
data[prefix] = value

Expand All @@ -67,7 +68,8 @@ def get_post_data(self, request):
def decode_uri(self, uri):
decoded = unquote(uri)

# If uri got decoded then recursive try more times until nothing more can be decoded
# If uri got decoded, recursively try more times until nothing else
# can be decoded.
if decoded != uri:
decoded = self.decode_uri(decoded)

Expand Down Expand Up @@ -173,10 +175,10 @@ def post(self, request, ext):
"""
try:
plugin = plugins.get(ext)
data, meta = self.get_post_data(request)
data, _meta = self.get_post_data(request)
data = plugin.load(data)
except UnknownPlugin:
raise Http404
raise Http404 from None
else:
content = plugin.render(data)
return self.render_to_response(content)
Expand All @@ -196,7 +198,7 @@ def get(self, request, uri):
plugin_context = plugin.get_editor_context(**plugin_context)

except UnknownPlugin:
raise Http404
raise Http404 from None
else:
return self.render_plugin(request, plugin_context)

Expand All @@ -220,7 +222,7 @@ def render_plugin(self, request, context):
return TemplateResponse(
request,
[
"djedi/plugins/%s/editor.html" % context["uri"].ext,
f"djedi/plugins/{context['uri'].ext}/editor.html",
"djedi/plugins/base/editor.html",
],
self.get_context_data(**context),
Expand Down
3 changes: 2 additions & 1 deletion djedi/admin/cms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from django.views.decorators.clickjacking import xframe_options_exempt
from django.views.generic import View

from ..auth import has_permission
from djedi.auth import has_permission

from .mixins import DjediContextMixin


Expand Down
5 changes: 3 additions & 2 deletions djedi/backends/django/cache/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, **config):
cache_name = self.config.get("NAME", "djedi")
cache = caches[cache_name]
except (InvalidCacheBackendError, ValueError):
from django.core.cache import cache
from django.core.cache import cache # noqa: PLC0415

self._cache = cache

Expand Down Expand Up @@ -45,7 +45,8 @@ def _delete_many(self, keys):

def _encode_content(self, uri, content):
"""
Join node uri and content as string and convert to bytes to ensure no pickling in memcached.
Join node uri and content as string and convert to bytes to ensure
no pickling in memcached.
"""
if content is None:
content = self.NONE
Expand Down
23 changes: 12 additions & 11 deletions djedi/backends/django/db/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ def get_many(self, uris):
uri = storage_keys[key]

# Assert requested plugin matches
if uri.ext in (None, plugin):
if uri.ext in (None, plugin) and (
# Assert version matches or node is published
if (uri.version == version) or (is_published and not uri.version):
meta = self._decode_meta(meta, is_published=is_published)
nodes[uri] = {
"uri": uri.clone(ext=plugin, version=version),
"content": content,
"meta": meta,
}
uri.version == version or (is_published and not uri.version)
):
meta_ = self._decode_meta(meta, is_published=is_published)
nodes[uri] = {
"uri": uri.clone(ext=plugin, version=version),
"content": content,
"meta": meta_,
}

return nodes

Expand Down Expand Up @@ -86,8 +87,8 @@ def _get(self, uri):

try:
return nodes.get()
except Node.DoesNotExist:
raise NodeDoesNotExist('Node for uri "%s" does not exist' % uri)
except Node.DoesNotExist as exc:
raise NodeDoesNotExist(f'Node for uri "{uri}" does not exist') from exc

def _create(self, uri, content, **meta):
try:
Expand All @@ -101,7 +102,7 @@ def _create(self, uri, content, **meta):
meta=meta,
)
except IntegrityError as e:
raise PersistenceError(f'Failed to create node for uri "{uri}"; {e}')
raise PersistenceError(f'Failed to create node for uri "{uri}"; {e}') from e

def _update(self, uri, content, **meta):
node = self._get(uri)
Expand Down
14 changes: 6 additions & 8 deletions djedi/middleware/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ def inject_admin_panel(self, request, response):
admin_prefix = reverse("admin:index")
except NoReverseMatch:
_log.debug(
'No reverse match for "admin:index", can\'t detect '
"django-admin pages"
'No reverse match for "admin:index", can\'t detect django-admin pages'
)
else:
if request.path.startswith(admin_prefix):
Expand All @@ -51,12 +50,12 @@ def inject_admin_panel(self, request, response):

try:
djedi_cms_url = reverse("admin:djedi:cms")
except NoReverseMatch:
except NoReverseMatch as exc:
raise ImproperlyConfigured(
"Could not find djedi in your url conf, "
"enable django admin or include "
"djedi.urls within the admin namespace."
)
) from exc
else:
if request.path.startswith(djedi_cms_url):
_log.debug("djedi page detected, not injecting panel")
Expand All @@ -74,12 +73,11 @@ def render_cms(self):
def get_requested_uri(node):
# Get first namespace URI, remove any version and ensures extension.
# TODO: Default extension fallback should be handled in content-io
uri = node.namespace_uri
uri = uri.clone(
ext=uri.ext or settings.URI_DEFAULT_EXT,
namespace_uri = node.namespace_uri
return namespace_uri.clone(
ext=namespace_uri.ext or settings.URI_DEFAULT_EXT,
version=None,
)
return uri

defaults = {
get_requested_uri(node): node.initial
Expand Down
2 changes: 1 addition & 1 deletion djedi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
if storage.backend.scheme == "db":
from .backends.django.db.models import Node

Node
Node # noqa: B018
Loading