Skip to content

Commit

Permalink
Fix pre commit + cleanup old compatibility code (#10)
Browse files Browse the repository at this point in the history
Fix ruff settings
  • Loading branch information
pfouque authored Oct 29, 2023
1 parent da859b3 commit 8708f7d
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 351 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: django-fsm linting

on:
pull_request:
push:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v2
with:
python-version: '3.11'
- uses: pre-commit/[email protected]
5 changes: 3 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: django-fsm testing

on:
- push
- pull_request
pull_request:
push:
branches: [main]

jobs:
build:
Expand Down
15 changes: 4 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args:
- "--py38-plus"

- repo: https://github.com/adamchainz/django-upgrade
rev: 1.15.0
hooks:
Expand All @@ -32,14 +25,14 @@ repos:


- repo: https://github.com/python-poetry/poetry
rev: 1.6.1
rev: 1.6.0
hooks:
- id: poetry-check
- id: poetry-lock
- id: poetry-export
# - id: poetry-lock
# - id: poetry-export

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.291
rev: v0.1.3
hooks:
- id: ruff-format
- id: ruff
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## django-fsm unreleased


- Remove South support...if exists
- Add support for django 5.0
- Remove support for django < 3.2
- Add support for python 3.12
Expand Down
161 changes: 0 additions & 161 deletions CHANGELOG.rst

This file was deleted.

30 changes: 5 additions & 25 deletions django_fsm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,13 @@
from functools import partialmethod, wraps

import django
from django.apps import apps as django_apps
from django.db import models
from django.db.models import Field
from django.db.models.query_utils import DeferredAttribute
from django.db.models.signals import class_prepared
from django_fsm.signals import pre_transition, post_transition

try:
from django.apps import apps as django_apps

def get_model(app_label, model_name):
app = django_apps.get_app_config(app_label)
return app.get_model(model_name)


except ImportError:
from django.db.models.loading import get_model
from django_fsm.signals import pre_transition, post_transition


__all__ = [
Expand All @@ -38,16 +29,6 @@ def get_model(app_label, model_name):
"RETURN_VALUE",
]

# South support; see http://south.aeracode.org/docs/tutorial/part4.html#simple-inheritance
try:
from south.modelsinspector import add_introspection_rules
except ImportError:
pass
else:
add_introspection_rules([], [r"^django_fsm\.FSMField"])
add_introspection_rules([], [r"^django_fsm\.FSMIntegerField"])
add_introspection_rules([], [r"^django_fsm\.FSMKeyField"])


class TransitionNotAllowed(Exception):
"""Raised when a transition is not allowed"""
Expand Down Expand Up @@ -297,7 +278,8 @@ def set_proxy(self, instance, state):
app_label = instance._meta.app_label
model_name = state_proxy

model = get_model(app_label, model_name)
model = django_apps.get_app_config(app_label).get_model(model_name)

if model is None:
raise ValueError(f"No model found {state_proxy}")

Expand Down Expand Up @@ -374,9 +356,7 @@ def contribute_to_class(self, cls, name, **kwargs):
super().contribute_to_class(cls, name, **kwargs)
setattr(cls, self.name, self.descriptor_class(self))
setattr(cls, f"get_all_{self.name}_transitions", partialmethod(get_all_FIELD_transitions, field=self))
setattr(
cls, f"get_available_{self.name}_transitions", partialmethod(get_available_FIELD_transitions, field=self)
)
setattr(cls, f"get_available_{self.name}_transitions", partialmethod(get_available_FIELD_transitions, field=self))
setattr(
cls,
f"get_available_user_{self.name}_transitions",
Expand Down
Loading

0 comments on commit 8708f7d

Please sign in to comment.