Skip to content

Commit cbdf895

Browse files
Ruff: Add PLC0415 (#13156)
* Ruff: Preparation for PLC0415 * udpate * update * update * update * update * update * update * update * update * update * update * update * update * update * update * update
1 parent 58e87a9 commit cbdf895

26 files changed

Lines changed: 78 additions & 95 deletions

dojo/api_v2/views.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
prefetch,
4141
serializers,
4242
)
43+
from dojo.api_v2.prefetch.prefetcher import _Prefetcher
4344
from dojo.authorization.roles_permissions import Permissions
4445
from dojo.cred.queries import get_authorized_cred_mappings
4546
from dojo.endpoint.queries import (
@@ -584,8 +585,6 @@ def files(self, request, pk=None):
584585
)
585586
@action(detail=True, methods=["get", "post"])
586587
def complete_checklist(self, request, pk=None):
587-
from dojo.api_v2.prefetch.prefetcher import _Prefetcher
588-
589588
engagement = self.get_object()
590589
check_lists = Check_List.objects.filter(engagement=engagement)
591590
if request.method == "POST":

dojo/apps.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,21 @@ def ready(self):
7171

7272
# Load any signals here that will be ready for runtime
7373
# Importing the signals file is good enough if using the reciever decorator
74-
import dojo.announcement.signals
75-
import dojo.benchmark.signals
76-
import dojo.cred.signals
77-
import dojo.endpoint.signals
78-
import dojo.engagement.signals
79-
import dojo.file_uploads.signals
80-
import dojo.finding_group.signals
81-
import dojo.notes.signals
82-
import dojo.product.signals
83-
import dojo.product_type.signals
84-
import dojo.risk_acceptance.signals
85-
import dojo.sla_config.helpers
86-
import dojo.tags_signals
87-
import dojo.test.signals
88-
import dojo.tool_product.signals # noqa: F401
74+
import dojo.announcement.signals # noqa: PLC0415 raised: AppRegistryNotReady
75+
import dojo.benchmark.signals # noqa: PLC0415 raised: AppRegistryNotReady
76+
import dojo.cred.signals # noqa: PLC0415 raised: AppRegistryNotReady
77+
import dojo.endpoint.signals # noqa: PLC0415 raised: AppRegistryNotReady
78+
import dojo.engagement.signals # noqa: PLC0415 raised: AppRegistryNotReady
79+
import dojo.file_uploads.signals # noqa: PLC0415 raised: AppRegistryNotReady
80+
import dojo.finding_group.signals # noqa: PLC0415 raised: AppRegistryNotReady
81+
import dojo.notes.signals # noqa: PLC0415 raised: AppRegistryNotReady
82+
import dojo.product.signals # noqa: PLC0415 raised: AppRegistryNotReady
83+
import dojo.product_type.signals # noqa: PLC0415 raised: AppRegistryNotReady
84+
import dojo.risk_acceptance.signals # noqa: PLC0415 raised: AppRegistryNotReady
85+
import dojo.sla_config.helpers # noqa: PLC0415 raised: AppRegistryNotReady
86+
import dojo.tags_signals # noqa: PLC0415 raised: AppRegistryNotReady
87+
import dojo.test.signals # noqa: PLC0415 raised: AppRegistryNotReady
88+
import dojo.tool_product.signals # noqa: F401,PLC0415 raised: AppRegistryNotReady
8989

9090

9191
def get_model_fields_with_extra(model, extra_fields=()):

dojo/celery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import os
3+
from logging.config import dictConfig
34

45
from celery import Celery
56
from celery.signals import setup_logging
@@ -26,7 +27,6 @@ def debug_task(self):
2627

2728
@setup_logging.connect
2829
def config_loggers(*args, **kwags):
29-
from logging.config import dictConfig
3030
dictConfig(settings.LOGGING)
3131

3232

dojo/context_processors.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import contextlib
2+
import time
23

34
# import the settings file
45
from django.conf import settings
56

7+
from dojo.models import Alerts, System_Settings, UserAnnouncement
8+
69

710
def globalize_vars(request):
811
# return the value you want as a dictionnary. you may add multiple values in there.
@@ -34,23 +37,18 @@ def globalize_vars(request):
3437

3538

3639
def bind_system_settings(request):
37-
from dojo.models import System_Settings
38-
3940
return {"system_settings": System_Settings.objects.get()}
4041

4142

4243
def bind_alert_count(request):
4344
if not settings.DISABLE_ALERT_COUNTER:
44-
from dojo.models import Alerts
4545

4646
if hasattr(request, "user") and request.user.is_authenticated:
4747
return {"alert_count": Alerts.objects.filter(user_id=request.user).count()}
4848
return {}
4949

5050

5151
def bind_announcement(request):
52-
from dojo.models import UserAnnouncement
53-
5452
with contextlib.suppress(Exception): # TODO: this should be replaced with more meaningful exception
5553
if request.user.is_authenticated:
5654
user_announcement = UserAnnouncement.objects.select_related(
@@ -61,8 +59,6 @@ def bind_announcement(request):
6159

6260

6361
def session_expiry_notification(request):
64-
import time
65-
6662
try:
6763
if request.user.is_authenticated:
6864
last_activity = request.session.get("_last_activity", time.time())

dojo/decorators.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ def get_tasks(self):
5555

5656

5757
def we_want_async(*args, func=None, **kwargs):
58-
from dojo.models import Dojo_User
59-
from dojo.utils import get_current_user
58+
from dojo.utils import get_current_user # noqa: PLC0415 circular import
6059

6160
sync = kwargs.get("sync", False)
6261
if sync:
@@ -83,7 +82,7 @@ def we_want_async(*args, func=None, **kwargs):
8382
def dojo_async_task(func):
8483
@wraps(func)
8584
def __wrapper__(*args, **kwargs):
86-
from dojo.utils import get_current_user
85+
from dojo.utils import get_current_user # noqa: PLC0415 circular import
8786
user = get_current_user()
8887
kwargs["async_user"] = user
8988

dojo/filters.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3465,7 +3465,6 @@ class Meta:
34653465

34663466

34673467
class LogEntryFilter(DojoFilter):
3468-
from auditlog.models import LogEntry
34693468

34703469
action = MultipleChoiceFilter(choices=LogEntry.Action.choices)
34713470
actor = ModelMultipleChoiceFilter(queryset=Dojo_User.objects.none())

dojo/finding/helper.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@
2727
Vulnerability_Id_Template,
2828
)
2929
from dojo.notes.helper import delete_related_notes
30-
from dojo.utils import get_current_user, mass_model_updater, to_str_typed
30+
from dojo.tools import tool_issue_updater
31+
from dojo.utils import (
32+
calculate_grade,
33+
do_dedupe_finding,
34+
do_false_positive_history,
35+
get_current_user,
36+
mass_model_updater,
37+
to_str_typed,
38+
)
3139

3240
logger = logging.getLogger(__name__)
3341
deduplicationLogger = logging.getLogger("dojo.specific-loggers.deduplication")
@@ -366,7 +374,6 @@ def post_process_finding_save(finding, dedupe_option=True, rules_option=True, pr
366374
if dedupe_option:
367375
if finding.hash_code is not None:
368376
if system_settings.enable_deduplication:
369-
from dojo.utils import do_dedupe_finding
370377
do_dedupe_finding(finding, *args, **kwargs)
371378
else:
372379
deduplicationLogger.debug("skipping dedupe because it's disabled in system settings")
@@ -378,25 +385,21 @@ def post_process_finding_save(finding, dedupe_option=True, rules_option=True, pr
378385
if system_settings.enable_deduplication:
379386
deduplicationLogger.warning("skipping false positive history because deduplication is also enabled")
380387
else:
381-
from dojo.utils import do_false_positive_history
382388
do_false_positive_history(finding, *args, **kwargs)
383389

384390
# STEP 2 run all non-status changing tasks as celery tasks in the background
385391
if issue_updater_option:
386-
from dojo.tools import tool_issue_updater
387392
tool_issue_updater.async_tool_issue_update(finding)
388393

389394
if product_grading_option:
390395
if system_settings.enable_product_grade:
391-
from dojo.utils import calculate_grade
392396
calculate_grade(finding.test.engagement.product)
393397
else:
394398
deduplicationLogger.debug("skipping product grading because it's disabled in system settings")
395399

396400
# Adding a snippet here for push to JIRA so that it's in one place
397401
if push_to_jira:
398402
logger.debug("pushing finding %s to jira from finding.save()", finding.pk)
399-
import dojo.jira_link.helper as jira_helper
400403

401404
# current approach is that whenever a finding is in a group, the group will be pushed to JIRA
402405
# based on feedback we could introduct another push_group_to_jira boolean everywhere

dojo/finding/views.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
)
102102
from dojo.notifications.helper import create_notification
103103
from dojo.test.queries import get_authorized_tests
104+
from dojo.tools import tool_issue_updater
104105
from dojo.utils import (
105106
FileIterWrapper,
106107
Product_Tab,
@@ -2918,8 +2919,6 @@ def finding_bulk_update_all(request, pid=None):
29182919
error_counts = defaultdict(lambda: 0)
29192920
success_count = 0
29202921
for finding in finds:
2921-
from dojo.tools import tool_issue_updater
2922-
29232922
tool_issue_updater.async_tool_issue_update(finding)
29242923

29252924
# not sure yet if we want to support bulk unlink, so leave as commented out for now

dojo/forms.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from django.contrib.auth.password_validation import validate_password
1919
from django.core import validators
2020
from django.core.exceptions import ValidationError
21+
from django.core.validators import URLValidator
2122
from django.db.models import Count, Q
2223
from django.forms import modelformset_factory
2324
from django.forms.widgets import Select, Widget
@@ -384,8 +385,6 @@ class EditFindingGroupForm(forms.ModelForm):
384385

385386
def __init__(self, *args, **kwargs):
386387
super().__init__(*args, **kwargs)
387-
import dojo.jira_link.helper as jira_helper
388-
389388
self.fields["push_to_jira"] = forms.BooleanField()
390389
self.fields["push_to_jira"].required = False
391390
self.fields["push_to_jira"].help_text = "Checking this will overwrite content of your JIRA issue, or create one."
@@ -2596,7 +2595,6 @@ class BaseJiraForm(forms.ModelForm):
25962595
password = forms.CharField(widget=forms.PasswordInput, required=True, help_text=JIRA_Instance._meta.get_field("password").help_text, label=JIRA_Instance._meta.get_field("password").verbose_name)
25972596

25982597
def test_jira_connection(self):
2599-
import dojo.jira_link.helper as jira_helper
26002598
try:
26012599
# Attempt to validate the credentials before moving forward
26022600
jira_helper.get_jira_connection_raw(self.cleaned_data["url"],
@@ -2665,13 +2663,6 @@ class Meta:
26652663
fields = ["id"]
26662664

26672665

2668-
# class JIRA_ProjectForm(forms.ModelForm):
2669-
2670-
# class Meta:
2671-
# model = JIRA_Project
2672-
# exclude = ['product']
2673-
2674-
26752666
class Product_API_Scan_ConfigurationForm(forms.ModelForm):
26762667

26772668
def __init__(self, *args, **kwargs):
@@ -2768,7 +2759,6 @@ class Meta:
27682759
exclude = ["product"]
27692760

27702761
def clean(self):
2771-
from django.core.validators import URLValidator
27722762
form_data = self.cleaned_data
27732763

27742764
try:
@@ -2849,7 +2839,6 @@ class Meta:
28492839
order = ["name"]
28502840

28512841
def clean(self):
2852-
from django.core.validators import URLValidator
28532842
form_data = self.cleaned_data
28542843

28552844
try:
@@ -3061,7 +3050,6 @@ class Meta:
30613050
fields = ["inherit_from_product", "jira_instance", "project_key", "issue_template_dir", "epic_issue_type_name", "component", "custom_fields", "jira_labels", "default_assignee", "enabled", "add_vulnerability_id_to_jira_label", "push_all_issues", "enable_engagement_epic_mapping", "push_notes", "product_jira_sla_notification", "risk_acceptance_expiration_notification"]
30623051

30633052
def __init__(self, *args, **kwargs):
3064-
from dojo.jira_link import helper as jira_helper
30653053
# if the form is shown for an engagement, we set a placeholder text around inherited settings from product
30663054
self.target = kwargs.pop("target", "product")
30673055
self.product = kwargs.pop("product", None)

dojo/github.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
def reopen_external_issue_github(find, note, prod, eng):
1818

19-
from dojo.utils import get_system_setting
19+
from dojo.utils import get_system_setting # noqa: PLC0415 circular import
2020
if not get_system_setting("enable_github"):
2121
return
2222

@@ -47,7 +47,7 @@ def reopen_external_issue_github(find, note, prod, eng):
4747

4848
def close_external_issue_github(find, note, prod, eng):
4949

50-
from dojo.utils import get_system_setting
50+
from dojo.utils import get_system_setting # noqa: PLC0415 circular import
5151
if not get_system_setting("enable_github"):
5252
return
5353

@@ -78,7 +78,7 @@ def close_external_issue_github(find, note, prod, eng):
7878

7979
def update_external_issue_github(find, prod, eng):
8080

81-
from dojo.utils import get_system_setting
81+
from dojo.utils import get_system_setting # noqa: PLC0415 circular import
8282
if not get_system_setting("enable_github"):
8383
return
8484

@@ -106,7 +106,7 @@ def update_external_issue_github(find, prod, eng):
106106

107107
def add_external_issue_github(find, prod, eng):
108108

109-
from dojo.utils import get_system_setting
109+
from dojo.utils import get_system_setting # noqa: PLC0415 circular import
110110
if not get_system_setting("enable_github"):
111111
return
112112

0 commit comments

Comments
 (0)