Skip to content

Commit

Permalink
update ruff fomat configs (#794)
Browse files Browse the repository at this point in the history
* modify ruff configs to ignore migrations for linting and formatting

* implement ruff based workflow to check all python files are linted and formatted

* upgrade ruff pre-commit hook version

* update production dependencies
  • Loading branch information
dpgraham4401 authored Oct 4, 2024
1 parent 343c4eb commit 0e3f069
Show file tree
Hide file tree
Showing 19 changed files with 74 additions and 31 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/lint_server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Lint Python files
on:
pull_request:
paths:
- "server/**"
- ".github/workflows/*"
push:
paths:
- "server/**"
- ".github/workflows/*"
workflow_call:
workflow_dispatch:

jobs:
lint:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./server
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install -r requirements_dev.txt
- name: Lint Python files
run: |
ruff check . -e
- name: Format Python files
run: |
ruff format . --check
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ repos:
exclude: (?x)^(\.idea\/.*|\.vscode\/.*)$
# Ruff
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.5.6
rev: v0.6.8
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --config, ./server/pyproject.toml]
args: [--fix, --config, ./server/pyproject.toml]
- id: ruff-format
args: [--config, ./server/pyproject.toml]
# Check django migrations
Expand Down
9 changes: 4 additions & 5 deletions server/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,22 @@
import pytest
import pytest_mock
import responses
from core.models import (
TrakUser,
)
from django.contrib.auth.models import User
from django.db import IntegrityError
from faker import Faker
from faker.providers import BaseProvider
from guardian.shortcuts import assign_perm
from rest_framework.test import APIClient

from core.models import (
TrakUser,
)
from org.models import Org, Site
from rcrasite.models import (
Address,
Contact,
RcraPhone,
RcraSite,
)
from rest_framework.test import APIClient


class SiteIDProvider(BaseProvider):
Expand Down
1 change: 0 additions & 1 deletion server/core/management/commands/celery_beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from django.core.management.base import BaseCommand
from django.utils import autoreload
from django_celery_beat.models import CrontabSchedule, IntervalSchedule, PeriodicTask

from wasteline.tasks import pull_federal_codes

CELERY_LOG_LEVEL = os.getenv("CELERY_LOG_LEVEL", "INFO")
Expand Down
1 change: 0 additions & 1 deletion server/core/services/rcrainfo_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import emanifest
from django.db import IntegrityError
from emanifest import RcrainfoClient, RcrainfoResponse

from org.models import Org
from wasteline.models import WasteCode

Expand Down
1 change: 0 additions & 1 deletion server/core/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import pytest
from faker import Faker

from rcrasite.models import RcraSiteType


Expand Down
1 change: 1 addition & 0 deletions server/haztrak/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Haztrak application level settings.
"""

from .celery import app as celery_app

__all__ = ("celery_app",)
2 changes: 1 addition & 1 deletion server/manifest/services/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

from django.db import transaction
from django.db.models import Q, QuerySet
from org.models import Site

from manifest.models import Manifest
from manifest.services import EManifest, EManifestError, TaskResponse
from manifest.tasks import save_to_emanifest as save_to_emanifest_task
from org.models import Site

logger = logging.getLogger(__name__)

Expand Down
6 changes: 4 additions & 2 deletions server/manifest/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from celery import Task, shared_task, states
from celery.exceptions import Ignore, Reject

from core.services import get_rcra_client

logger = logging.getLogger(__name__)
Expand All @@ -16,6 +15,7 @@ def pull_manifest(self: Task, *, mtn: List[str], username: str) -> dict:
"""

from core.services import TaskService

from manifest.services import EManifest

logger.info(f"start task {self.name}, manifest {mtn}")
Expand Down Expand Up @@ -60,9 +60,10 @@ def sign_manifest(
def sync_site_manifests(self, *, site_id: str, username: str):
"""asynchronous task to sync an EPA site's manifests"""

from manifest.services.emanifest import sync_manifests
from org.services import get_user_site, update_emanifest_sync_date

from manifest.services.emanifest import sync_manifests

try:
client = get_rcra_client(username=username)
site = get_user_site(username=username, epa_id=site_id)
Expand All @@ -85,6 +86,7 @@ def save_to_emanifest(self, *, manifest_data: dict, username: str):
user who is creating the manifest
"""
from core.services import TaskService

from manifest.services import EManifest, EManifestError

logger.info(f"start task: {self.name}")
Expand Down
2 changes: 1 addition & 1 deletion server/org/serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from rcrasite.serializers import RcraSiteSerializer
from rest_framework import serializers
from rest_framework.serializers import ModelSerializer

from org.models import Org, Site
from rcrasite.serializers import RcraSiteSerializer


class OrgSerializer(ModelSerializer):
Expand Down
2 changes: 1 addition & 1 deletion server/org/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Optional

import pytest
from rcrasite.models import RcraSite

from org.models import Org, Site
from rcrasite.models import RcraSite


@pytest.fixture
Expand Down
3 changes: 1 addition & 2 deletions server/profile/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
from typing import Optional

import pytest
from faker import Faker

from conftest import SiteIDProvider
from faker import Faker


@pytest.fixture
Expand Down
19 changes: 17 additions & 2 deletions server/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,26 @@ repository = "https://github.com/USEPA/haztrak"

[tool.ruff]
line-length = 99
exclude = [
"**/migrations/*.py",
".venv",
".eggs",
".git",
".mypy_cache",
".pytest_cache",
".ruff_cache",
".venv",
".vscode",
"__pypackages__",
"dist",
"node_modules",
"site-packages",
"venv",
]

[tool.ruff.lint]
select = ["F", "E", "W", "Q", "I001"]
select = ["F", "E", "W", "Q"]
ignore = ["F401"]
exclude = ["**/migrations/*.py"]

[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "haztrak.settings.test"
Expand Down
2 changes: 1 addition & 1 deletion server/rcrasite/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from core.admin import HiddenListView
from django.contrib import admin

from core.admin import HiddenListView
from rcrasite.models import (
Address,
Contact,
Expand Down
2 changes: 1 addition & 1 deletion server/rcrasite/services/rcra_site.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import logging
from typing import Dict, Optional, TypedDict

from core.services import RcraClient, get_rcra_client
from django.core.cache import CacheKeyWarning, cache
from django.db import transaction
from django.db.models import QuerySet
from rest_framework.exceptions import ValidationError

from core.services import RcraClient, get_rcra_client
from rcrasite.models import RcraSite
from rcrasite.serializers import RcraSiteSerializer

Expand Down
3 changes: 1 addition & 2 deletions server/rcrasite/services/rcra_site_search.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from typing import Literal, Optional

from emanifest import RcrainfoResponse

from core.services import RcraClient
from emanifest import RcrainfoResponse

SiteType = Literal["Generator", "Tsdf", "Transporter", "Broker"]

Expand Down
2 changes: 1 addition & 1 deletion server/rcrasite/tests/test_site_search.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json

import pytest

from core.services import RcraClient

from rcrasite.services import RcraSiteSearch


Expand Down
12 changes: 6 additions & 6 deletions server/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Django==5.0.8
Django==5.1.1
django-celery-results==2.5.1
django-cors-headers==4.4.0
django-extensions==3.2.3
django-celery-beat==2.6.0
django-celery-beat==2.7.0
djangorestframework==3.15.2
gunicorn==22.0.0
emanifest==4.0.3
psycopg[binary]==3.2.1
pytz==2024.1
pytz==2024.2
sqlparse==0.5.1
tzdata==2024.1
whitenoise==6.6.0
tzdata==2024.2
whitenoise==6.7.0
celery==5.4.0
redis==5.0.8
redis==5.1.0
drf-spectacular==0.27.2
django-health-check==3.18.3
dj-rest-auth[with_social]==6.0.0
Expand Down
2 changes: 1 addition & 1 deletion server/wasteline/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import pytest
from faker import Faker

from manifest.models import Manifest

from wasteline.models import DotLookup, DotLookupType, WasteCode, WasteLine


Expand Down

0 comments on commit 0e3f069

Please sign in to comment.