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

Replace black and flake8 with ruff #260

Merged
merged 4 commits into from
Nov 23, 2023
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
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ db974d9214b491144b43be35d8e806d1df15fada
e9206fb9b470718d3b4a88717ab2ce19de02aac9
99f26965fb610e1336a186ae2891af06f82d7a20
b6b50b4e85333b2cb981c4e1f74cd0d6ba9ac324
8e673b591e105bfd606d1488c7421369a3aaeb14
15 changes: 7 additions & 8 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ jobs:
steps:
- uses: actions/checkout@master
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.11.5
- name: Install flake8
run: pip install flake8
- name: Install dependencies
run: pip install .[linting]
- name: Run flake8
uses: suo/flake8-github-action@releases/v1
with:
checkName: 'flake8'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ruff .
ruff format --check .
isort src/organizations --check --diff
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.x'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
exclude: "docs|node_modules|migrations|.git|.tox"
default_stages: [ commit ]
fail_fast: true

repos:

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.1.6"
hooks:
- id: ruff-format
- id: ruff

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args:
- --settings-path=pyproject.toml
2 changes: 2 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import django

import pytest


Expand Down Expand Up @@ -67,6 +68,7 @@ def pytest_configure():
)
django.setup()


@pytest.fixture(autouse=True)
def enable_db_access_for_all_tests(db):
pass
3 changes: 1 addition & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down Expand Up @@ -90,7 +89,7 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'furo'
html_theme = "furo"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down
5 changes: 3 additions & 2 deletions example/accounts/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.contrib import admin

from .models import Account, AccountUser, AccountOwner

from .models import Account
from .models import AccountOwner
from .models import AccountUser

admin.site.register(Account)
admin.site.register(AccountUser)
Expand Down
15 changes: 11 additions & 4 deletions example/accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Generated by Django 2.2.4 on 2019-12-10 18:25

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations
from django.db import models

import organizations.base
import organizations.fields

Expand Down Expand Up @@ -50,7 +52,9 @@ class Migration(migrations.Migration):
organizations.fields.SlugField(
blank=True,
editable=False,
help_text="The name in all lowercase, suitable for URL identification",
help_text=(
"The name in all lowercase, suitable for URL identification"
),
max_length=200,
populate_from="name",
unique=True,
Expand Down Expand Up @@ -178,7 +182,10 @@ class Migration(migrations.Migration):
(
"invitee_identifier",
models.CharField(
help_text="The contact identifier for the invitee, email, phone number, social media handle, etc.",
help_text=(
"The contact identifier for the invitee, email, "
"phone number, social media handle, etc."
),
max_length=1000,
),
),
Expand Down
10 changes: 4 additions & 6 deletions example/accounts/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from django.db import models

from organizations.abstract import (
AbstractOrganization,
AbstractOrganizationInvitation,
AbstractOrganizationOwner,
AbstractOrganizationUser,
)
from organizations.abstract import AbstractOrganization
from organizations.abstract import AbstractOrganizationInvitation
from organizations.abstract import AbstractOrganizationOwner
from organizations.abstract import AbstractOrganizationUser


class Account(AbstractOrganization):
Expand Down
6 changes: 3 additions & 3 deletions example/conf/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.conf.urls import include, url
from django.conf.urls import include
from django.contrib import admin
from django.urls import path

from organizations.backends import invitation_backend, registration_backend

from organizations.backends import invitation_backend
from organizations.backends import registration_backend

urlpatterns = [
path("admin/", admin.site.urls),
Expand Down
10 changes: 1 addition & 9 deletions example/conf/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,7 @@
"""
import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "conf.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "conf.settings")
application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
5 changes: 3 additions & 2 deletions example/vendors/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.contrib import admin

from .models import Vendor, VendorUser, VendorOwner

from .models import Vendor
from .models import VendorOwner
from .models import VendorUser

admin.site.register(Vendor)
admin.site.register(VendorUser)
Expand Down
15 changes: 11 additions & 4 deletions example/vendors/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Generated by Django 2.2.4 on 2019-12-10 18:25

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations
from django.db import models

import organizations.base
import organizations.fields

Expand Down Expand Up @@ -54,7 +56,9 @@ class Migration(migrations.Migration):
organizations.fields.SlugField(
blank=True,
editable=False,
help_text="The name in all lowercase, suitable for URL identification",
help_text=(
"The name in all lowercase, suitable for URL identification"
),
max_length=200,
populate_from="name",
unique=True,
Expand Down Expand Up @@ -195,7 +199,10 @@ class Migration(migrations.Migration):
(
"invitee_identifier",
models.CharField(
help_text="The contact identifier for the invitee, email, phone number, social media handle, etc.",
help_text=(
"The contact identifier for the invitee, email, "
"phone number, social media handle, etc."
),
max_length=1000,
),
),
Expand Down
10 changes: 4 additions & 6 deletions example/vendors/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from django.contrib.auth.models import Permission
from django.db import models

from organizations.abstract import (
AbstractOrganization,
AbstractOrganizationInvitation,
AbstractOrganizationOwner,
AbstractOrganizationUser,
)
from organizations.abstract import AbstractOrganization
from organizations.abstract import AbstractOrganizationInvitation
from organizations.abstract import AbstractOrganizationOwner
from organizations.abstract import AbstractOrganizationUser


class Vendor(AbstractOrganization):
Expand Down
4 changes: 1 addition & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import nox


NOX_DIR = os.path.abspath(os.path.dirname(__file__))

DEFAULT_INTERPRETER = "3.8"
Expand Down Expand Up @@ -46,7 +45,7 @@ def manage(session, *args):
session.install("six")
session.install("django-autoslug")
session.install("Django==3.1")
session.install('-e', '.')
session.install("-e", ".")
args = args if args else session.posargs
session.run("python", "manage.py", *args)

Expand Down Expand Up @@ -105,7 +104,6 @@ def publish(session):
session.run("python", "-m", "twine", "upload", "dist/*")



@nox.session(python=DEFAULT_INTERPRETER, reuse_venv=True)
def docs(session):
session.run("make", "-C", "docs", "clean")
Expand Down
19 changes: 16 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ docs = [
"Sphinx==3.5.4",
"furo==2021.4.11b34",
]
linting = [
"ruff",
"isort",
]
dev = [
"django-organizations[tests]",
"django-organizations[tests,linting]",
"tox",
"black",
"ruff",
"pre-commit",
]

[build-system]
Expand All @@ -73,3 +76,13 @@ packages = ["src/oranizations"]

[tool.black]
target-version = ["py311"]

[tool.isort]
line_length = 88
force_single_line = true
known_future_library = "future"
known_django = "django"
known_first_party = ["organizations"]
sections = ["FUTURE", "STDLIB", "DJANGO", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
default_section = "THIRDPARTY"
skip_glob = ["**/__init__.py", "*/__init__.py"]
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
"""

from setuptools import setup

setup()
4 changes: 1 addition & 3 deletions src/organizations/abstract.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@

import warnings

from django.conf import settings
from django.db import models
from django.urls import reverse
from django.utils.translation import gettext_lazy as _


from organizations.base import AbstractBaseInvitation
from organizations.base import AbstractBaseOrganization
from organizations.base import AbstractBaseOrganizationOwner
from organizations.base import AbstractBaseOrganizationUser
from organizations.base import with_metaclass
from organizations.base import OrgMeta
from organizations.base import with_metaclass
from organizations.fields import AutoCreatedField
from organizations.fields import AutoLastModifiedField
from organizations.fields import SlugField
Expand Down
1 change: 0 additions & 1 deletion src/organizations/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from django.contrib import admin

from organizations import models
Expand Down
1 change: 0 additions & 1 deletion src/organizations/app_settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from django.conf import settings
from django.contrib.auth.models import User

Expand Down
1 change: 0 additions & 1 deletion src/organizations/apps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from django.apps import AppConfig


Expand Down
1 change: 0 additions & 1 deletion src/organizations/backends/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from importlib import import_module
from typing import Optional # noqa
from typing import Text # noqa
Expand Down
5 changes: 2 additions & 3 deletions src/organizations/backends/defaults.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

"""Backend classes should provide common interface"""

import email.utils
Expand Down Expand Up @@ -144,8 +143,8 @@ def email_message(
):
"""
Returns an email message for a new user. This can be easily overridden.
For instance, to send an HTML message, use the EmailMultiAlternatives message_class
and attach the additional conent.
For instance, to send an HTML message, use the EmailMultiAlternatives
message_class and attach the additional conent.
"""
if sender:
try:
Expand Down
1 change: 0 additions & 1 deletion src/organizations/backends/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from django import forms
from django.contrib.auth.forms import UserCreationForm

Expand Down
Loading