Skip to content

Commit

Permalink
Switch to ruff instead of black, isort, flake8 and autoflake
Browse files Browse the repository at this point in the history
  • Loading branch information
suricactus committed Jun 20, 2024
1 parent 3caa5b7 commit 2a22f62
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 53 deletions.
5 changes: 0 additions & 5 deletions .flake8

This file was deleted.

42 changes: 8 additions & 34 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,16 @@ repos:
args:
- '--fix=lf'

# Remove unused imports/variables
- repo: https://github.com/myint/autoflake
rev: v2.2.1
# Lint and format
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.4
hooks:
- id: autoflake
args:
- "--in-place"
- "--remove-all-unused-imports"
- "--remove-unused-variables"

# Sort imports
- repo: https://github.com/pycqa/isort
rev: "5.12.0"
hooks:
- id: isort
args: ["--profile", "black"]

# Black formatting
- repo: https://github.com/psf/black
rev: "23.7.0"
hooks:
- id: black

# tool to automatically upgrade syntax for newer versions of the language
- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
hooks:
- id: pyupgrade
args: [--py37-plus]
# Run the linter.
- id: ruff

# Lint files
- repo: https://github.com/pycqa/flake8
rev: "6.1.0"
hooks:
- id: flake8
additional_dependencies: [flake8-match==1.0.0, flake8-walrus==1.1.0]
# Run the formatter.
- id: ruff-format

# Static type-checking with mypy
- repo: https://github.com/pre-commit/mirrors-mypy
Expand Down
13 changes: 5 additions & 8 deletions docker-app/qfieldcloud/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,9 +732,7 @@ def clean(self) -> None:
if self.organization.organization_owner == self.member:
raise ValidationError(_("Cannot add the organization owner as a member."))

max_organization_members = (
self.organization.useraccount.current_subscription.plan.max_organization_members
)
max_organization_members = self.organization.useraccount.current_subscription.plan.max_organization_members
if (
max_organization_members > -1
and self.organization.members.count() >= max_organization_members
Expand Down Expand Up @@ -933,8 +931,9 @@ class Status(models.TextChoices):

class StatusCode(models.TextChoices):
OK = "ok", _("Ok")
FAILED_PROCESS_PROJECTFILE = "failed_process_projectfile", _(
"Failed process projectfile"
FAILED_PROCESS_PROJECTFILE = (
"failed_process_projectfile",
_("Failed process projectfile"),
)
TOO_MANY_COLLABORATORS = "too_many_collaborators", _("Too many collaborators")

Expand Down Expand Up @@ -1268,9 +1267,7 @@ def status(self) -> Status:
else:
status = Project.Status.OK
status_code = Project.StatusCode.OK
max_premium_collaborators_per_private_project = (
self.owner.useraccount.current_subscription.plan.max_premium_collaborators_per_private_project
)
max_premium_collaborators_per_private_project = self.owner.useraccount.current_subscription.plan.max_premium_collaborators_per_private_project

# TODO use self.problems to get if there are project problems
if not self.project_filename or not self.project_details:
Expand Down
4 changes: 1 addition & 3 deletions docker-app/qfieldcloud/core/permissions_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,7 @@ def check_can_become_collaborator(user: QfcUser, project: Project) -> bool:
)
)

max_premium_collaborators_per_private_project = (
project.owner.useraccount.current_subscription.plan.max_premium_collaborators_per_private_project
)
max_premium_collaborators_per_private_project = project.owner.useraccount.current_subscription.plan.max_premium_collaborators_per_private_project
if max_premium_collaborators_per_private_project >= 0 and not project.is_public:
project_collaborators_count = project.direct_collaborators.count()
if project_collaborators_count >= max_premium_collaborators_per_private_project:
Expand Down
2 changes: 1 addition & 1 deletion docker-app/qfieldcloud/core/utils2/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def upload_file(file: IO, key: str):


def upload_project_file(
project: qfieldcloud.core.models.Project, file: IO, filename: str # noqa: F821
project: qfieldcloud.core.models.Project, file: IO, filename: str
) -> str:
key = f"projects/{project.id}/files/{filename}"
bucket = qfieldcloud.core.utils.get_s3_bucket()
Expand Down
5 changes: 3 additions & 2 deletions docker-app/qfieldcloud/subscription/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ class SubscriptionStatus(models.TextChoices):
# the user draft expired (e.g. a new subscription is attempted)
INACTIVE_DRAFT_EXPIRED = "inactive_draft_expired", _("Inactive Draft Expired")
# requested creating the subscription on Stripe
INACTIVE_REQUESTED_CREATE = "inactive_requested_create", _(
"Inactive Requested Create"
INACTIVE_REQUESTED_CREATE = (
"inactive_requested_create",
_("Inactive Requested Create"),
)
# requested creating the subscription on Stripe
INACTIVE_AWAITS_PAYMENT = "inactive_awaits_payment", _("Inactive Awaits Payment")
Expand Down
26 changes: 26 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# See the default values at: https://docs.astral.sh/ruff/configuration/

# Exclude a variety of commonly ignored directories.
exclude = [
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".ruff_cache",
".vscode",
"__pypackages__",
"site-packages",
# Custom QFieldCloud dirs to ignore.
"**/docker-qgis/libqfieldsync/",
"**/docker-qgis/qfieldcloud-sdk-python/",
]

# Support Python 3.10+.
target-version = "py310"

[lint]
ignore = []

[lint.mccabe]
max-complexity = 30

0 comments on commit 2a22f62

Please sign in to comment.