Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobi-De committed Oct 13, 2024
1 parent 6b64129 commit b10cb56
Show file tree
Hide file tree
Showing 23 changed files with 52 additions and 69 deletions.
3 changes: 1 addition & 2 deletions demo/demo/books/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by Django 5.1.2 on 2024-10-12 21:56
import django.db.models.deletion
from django.db import migrations
from django.db import models
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
1 change: 0 additions & 1 deletion demo/demo/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.contrib import admin
from django.urls import include
from django.urls import path

urlpatterns = [
Expand Down
6 changes: 2 additions & 4 deletions docs/_static/snippets/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

import sentry_sdk
from environs import Env
from falco_toolbox.sentry import sentry_profiles_sampler
from falco_toolbox.sentry import sentry_traces_sampler
from marshmallow.validate import Email
from marshmallow.validate import OneOf
from falco_toolbox.sentry import sentry_profiles_sampler, sentry_traces_sampler
from marshmallow.validate import Email, OneOf
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.logging import LoggingIntegration

Expand Down
6 changes: 2 additions & 4 deletions docs/_static/snippets/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from functools import wraps

from django.core.paginator import InvalidPage
from django.core.paginator import Paginator
from django.core.paginator import InvalidPage, Paginator
from django.db.models import QuerySet
from django.http import Http404
from django.http import HttpResponse
from django.http import Http404, HttpResponse
from django.template.loader import render_to_string
from django.utils.translation import gettext_lazy as _

Expand Down
2 changes: 0 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from importlib.metadata import version as get_version

import falco

# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
Expand Down
2 changes: 1 addition & 1 deletion src/falco/__about__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2024-present Tobi DEGNON <[email protected]>
#
# SPDX-License-Identifier: MIT
__version__ = "0.2.0"
__version__ = "0.3.0"
1 change: 1 addition & 0 deletions src/falco/htmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.http import HttpResponse
from django.template.loader import render_to_string

from falco.types import HttpRequest


Expand Down
4 changes: 2 additions & 2 deletions src/falco/management/base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pathlib import Path

from django.conf import settings
from django.core.management.base import BaseCommand
from django.core.management.base import CommandError
from django.core.management.base import BaseCommand, CommandError

from falco.utils import clean_git_repo


Expand Down
8 changes: 3 additions & 5 deletions src/falco/management/commands/copy_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@

from django.apps import apps
from django.conf import settings
from django.core.management.base import BaseCommand
from django.core.management.base import CommandError
from django.core.management.base import BaseCommand, CommandError
from django.template import loader
from django.template.exceptions import TemplateDoesNotExist
from django.template.exceptions import TemplateSyntaxError
from django.template.exceptions import TemplateDoesNotExist, TemplateSyntaxError


def get_template_absolute_path(template_path):
Expand All @@ -44,7 +42,7 @@ def get_template_absolute_path(template_path):
raise CommandError(msg)
except TemplateSyntaxError as e:
msg = f"Syntax error in template {template_path}: {e}"
raise CommandError(msg)
raise CommandError(msg) from e


class Command(BaseCommand):
Expand Down
18 changes: 10 additions & 8 deletions src/falco/management/commands/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
from typing import TypedDict

import parso
from django.apps import AppConfig
from django.apps import apps
from django.apps import AppConfig, apps
from django.conf import settings
from django.core.management import call_command
from django.core.management.base import CommandError
from django.template import Context
from django.template import Template
from django.template import Context, Template

from falco.management.base import CleanRepoOnlyCommand
from falco.management.commands.copy_template import get_template_absolute_path
from falco.utils import run_html_formatters
from falco.utils import run_python_formatters
from falco.utils import simple_progress
from falco.utils import run_html_formatters, run_python_formatters, simple_progress

IMPORT_START_COMMENT = "# IMPORTS:START"
IMPORT_END_COMMENT = "# IMPORTS:END"
Expand Down Expand Up @@ -45,10 +42,15 @@ class DjangoModel(TypedDict):

class BlueprintContext(TypedDict):
login_required: bool
entry_point: bool
app_label: str
model: DjangoModel
fields_tuple: str
editable_fields_tuple: str
view_name_prefix: str
entry_point: bool
list_view_name: str
detail_view_name: str
delete_view_name: str
list_view_url: str
create_view_url: str
detail_view_url: str
Expand Down
12 changes: 6 additions & 6 deletions src/falco/management/commands/htmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import httpx
from django.conf import settings
from django.core.management.base import BaseCommand
from django.core.management.base import CommandError
from falco.utils import simple_progress
from django.core.management.base import BaseCommand, CommandError
from httpx import codes

from falco.utils import simple_progress

HTMX_DOWNLOAD_URL = "https://unpkg.com/htmx.org@{version}/dist/htmx.min.js"
HTMX_GH_RELEASE_LATEST_URL = "https://api.github.com/repos/bigskysoftware/htmx/releases/latest"

Expand All @@ -27,7 +27,7 @@ def add_arguments(self, parser):
help="The directory to write the downloaded file to.",
)

def handle(self, *args, **options):
def handle(self, *_, **options):
version = options["version"]
version = version if version != "latest" else get_latest_tag()
output_dir = options.get("output_dir") or default_htmx_output_folder()
Expand Down Expand Up @@ -63,11 +63,11 @@ def get_latest_tag() -> str:
def default_htmx_output_folder() -> Path:
try:
folder = Path(settings.STATICFILES_DIRS[0]) / "vendors" / "htmx"
folder.mkdir(exist_ok=True, parents=True)
return folder
except IndexError:
msg = "Add at least one folder in your STATICFILES_DIRS settings and make sure it exists"
raise CommandError(msg)
folder.mkdir(exist_ok=True, parents=True)
return folder


@contextmanager
Expand Down
11 changes: 5 additions & 6 deletions src/falco/management/commands/htmx_ext.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
from pathlib import Path

import httpx
from django.core.management.base import BaseCommand
from django.core.management.base import CommandError
from falco.management.commands.htmx import default_htmx_output_folder
from falco.management.commands.htmx import network_request_with_progress
from falco.utils import simple_progress
from django.core.management.base import BaseCommand, CommandError
from rich import print as rich_print
from rich.console import Console
from rich.panel import Panel
from rich.table import Table

from falco.management.commands.htmx import default_htmx_output_folder, network_request_with_progress
from falco.utils import simple_progress

REGISTRY_URL = "https://htmx-extensions.oluwatobi.dev/extensions.json"


Expand All @@ -33,7 +32,7 @@ def add_arguments(self, parser):
help="The directory to write the downloaded file to.",
)

def handle(self, *args, **options):
def handle(self, *_, **options):
output_dir = options.get("output_dir") or default_htmx_output_folder()
name = options.get("name")
if name:
Expand Down
4 changes: 2 additions & 2 deletions src/falco/management/commands/reset_migrations.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.core.management import call_command
from django.core.management.base import BaseCommand
from django.db import connection
from falco.management.base import exit_if_debug_false
from falco.management.base import get_apps_dir

from falco.management.base import exit_if_debug_false, get_apps_dir
from falco.management.commands.rm_migrations import Command as RmMigrationsCommand
from falco.utils import simple_progress

Expand Down
6 changes: 2 additions & 4 deletions src/falco/management/commands/rm_migrations.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from pathlib import Path

from falco.management.base import CleanRepoOnlyCommand
from falco.management.base import exit_if_debug_false
from falco.management.base import get_apps_dir
from falco.management.base import CleanRepoOnlyCommand, exit_if_debug_false, get_apps_dir
from falco.utils import simple_progress


class Command(CleanRepoOnlyCommand):
help = "Remove all migrations for the specified applications directory, intended only for development."

def handle(self, *args, **options):
def handle(self, *_, **__):
exit_if_debug_false()
apps_dir = get_apps_dir()
apps = self.delete_migration_files(apps_dir=apps_dir)
Expand Down
9 changes: 4 additions & 5 deletions src/falco/management/commands/start_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import parso
from django.conf import settings
from django.core.management import call_command
from django.core.management import CommandError
from django.core.management import CommandError, call_command
from django.core.management.base import BaseCommand

from falco.management.base import get_apps_dir
from falco.utils import run_python_formatters
from falco.utils import simple_progress
from falco.utils import run_python_formatters, simple_progress


class Command(BaseCommand):
Expand All @@ -16,7 +15,7 @@ class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument("app_name", type=str, help="Name of the app to create.")

def handle(self, *args, **options):
def handle(self, *_, **options):
app_name = options["app_name"]
apps_dir = get_apps_dir()
app_dir = apps_dir / app_name
Expand Down
3 changes: 2 additions & 1 deletion src/falco/management/commands/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.conf import settings
from django.core.management import call_command
from django.core.management.base import BaseCommand

from falco.conf import app_settings


Expand All @@ -20,7 +21,7 @@ def add_arguments(self, parser):
help="Address to run the django server on",
)

def handle(self, *args, **options):
def handle(self, *_, **options):
address = options["address"]
commands = {"runserver": f"python manage.py runserver {address}"}
if "django_tailwind_cli" in settings.INSTALLED_APPS:
Expand Down
4 changes: 2 additions & 2 deletions src/falco/pagination.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.core.paginator import InvalidPage
from django.core.paginator import Paginator
from django.core.paginator import InvalidPage, Paginator
from django.db.models import QuerySet
from django.http import Http404

from falco.types import HttpRequest


Expand Down
4 changes: 1 addition & 3 deletions src/falco/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
import subprocess
from contextlib import contextmanager

from rich.progress import Progress
from rich.progress import SpinnerColumn
from rich.progress import TextColumn
from rich.progress import Progress, SpinnerColumn, TextColumn

if importlib.util.find_spec("falco_cli"):
from falco_cli.utils import run_html_formatters, run_python_formatters
Expand Down
1 change: 1 addition & 0 deletions src/falco/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.utils import timezone
from django.views.decorators.cache import cache_control
from django.views.decorators.http import require_GET

from falco.conf import app_settings
from falco.decorators import login_not_required

Expand Down
3 changes: 1 addition & 2 deletions tests/old/_test_htmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import pytest
from cappa.testing import CommandRunner
from falco.management.commands.htmx import Htmx
from falco_cli.config import read_falco_config
from falco_cli.config import write_falco_config
from falco_cli.config import read_falco_config, write_falco_config


@pytest.fixture(autouse=True)
Expand Down
1 change: 1 addition & 0 deletions tests/old/_test_start_app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path

from cappa.testing import CommandRunner

from tests.commands.test_crud import healthy_django_project


Expand Down
4 changes: 1 addition & 3 deletions tests/old/_test_work.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import pytest
from falco.management.commands.work import default_address
from falco.management.commands.work import default_server_cmd
from falco.management.commands.work import Work
from falco.management.commands.work import Work, default_address, default_server_cmd
from falco_cli.config import write_falco_config


Expand Down
8 changes: 2 additions & 6 deletions tests/test_commands/test_copy_template.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
from __future__ import annotations

from io import StringIO

import pytest
from django.apps import apps
from django.core.management import call_command
from django.core.management import CommandError
from django.core.management import CommandError, call_command
from django.test import override_settings
from falco.management.commands.copy_template import Command
from falco.management.commands.copy_template import get_template_absolute_path
from falco.management.commands.copy_template import Command, get_template_absolute_path


@pytest.fixture
Expand Down

0 comments on commit b10cb56

Please sign in to comment.