Skip to content

Commit e15e9aa

Browse files
authored
Ruff: Fix PTH118, merge PTH11 (#11503)
1 parent 9747701 commit e15e9aa

File tree

217 files changed

+1361
-1431
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

217 files changed

+1361
-1431
lines changed

dojo/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2428,7 +2428,7 @@ def get_jira_issue_template_dir_choices():
24282428

24292429
for dirname in dirnames:
24302430
clean_base_dir = base_dir.removeprefix(settings.TEMPLATE_DIR_PREFIX)
2431-
template_dir_list.append((os.path.join(clean_base_dir, dirname), dirname))
2431+
template_dir_list.append((str(Path(clean_base_dir) / dirname), dirname))
24322432

24332433
logger.debug("templates: %s", template_dir_list)
24342434
return template_dir_list

dojo/jira_link/helper.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import io
22
import json
33
import logging
4-
import os
54
from pathlib import Path
65
from typing import Any
76

@@ -333,8 +332,8 @@ def get_jira_issue_template(obj):
333332
template_dir = "issue-trackers/jira_full/"
334333

335334
if isinstance(obj, Finding_Group):
336-
return os.path.join(template_dir, "jira-finding-group-description.tpl")
337-
return os.path.join(template_dir, "jira-description.tpl")
335+
return Path(template_dir) / "jira-finding-group-description.tpl"
336+
return Path(template_dir) / "jira-description.tpl"
338337

339338

340339
def get_jira_creation(obj):

dojo/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import copy
33
import hashlib
44
import logging
5-
import os
65
import re
76
import warnings
87
from contextlib import suppress
@@ -150,7 +149,7 @@ def __call__(self, model_instance, filename):
150149
filename += ext
151150
if self.directory is None:
152151
return filename
153-
return os.path.join(now().strftime(self.directory), filename)
152+
return Path(now().strftime(self.directory)) / filename
154153

155154

156155
class Regulation(models.Model):

dojo/settings/settings.dist.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def generate_url(scheme, double_slashes, user, password, host, port, path, param
442442
# Put strings here, like "/home/html/static" or "C:/www/django/static".
443443
# Always use forward slashes, even on Windows.
444444
# Don't forget to use absolute paths, not relative paths.
445-
os.path.join(Path(DOJO_ROOT).parent, "components", "node_modules"),
445+
Path(DOJO_ROOT).parent / "components" / "node_modules",
446446
)
447447

448448
# List of finder classes that know how to find static files in
@@ -912,8 +912,6 @@ def saml2_attrib_map_format(dict):
912912
SAML2_LOGIN_BUTTON_TEXT = env("DD_SAML2_LOGIN_BUTTON_TEXT")
913913
SAML2_LOGOUT_URL = env("DD_SAML2_LOGOUT_URL")
914914
if SAML2_ENABLED:
915-
from os import path
916-
917915
import saml2
918916
import saml2.saml
919917
# SSO_URL = env('DD_SSO_URL')
@@ -949,7 +947,7 @@ def saml2_attrib_map_format(dict):
949947
"entityid": str(SAML2_ENTITY_ID),
950948

951949
# directory with attribute mapping
952-
"attribute_map_dir": path.join(BASEDIR, "attribute-maps"),
950+
"attribute_map_dir": Path(BASEDIR) / "attribute-maps",
953951
# do now discard attributes not specified in attribute-maps
954952
"allow_unknown_attributes": SAML_ALLOW_UNKNOWN_ATTRIBUTES,
955953
# this block states what services we provide

dojo/tools/factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def requires_tool_type(scan_type):
117117
package_dir = str(Path(__file__).resolve().parent)
118118
for module_name in os.listdir(package_dir): # noqa: PTH208
119119
# check if it's dir
120-
if Path(os.path.join(package_dir, module_name)).is_dir():
120+
if (Path(package_dir) / module_name).is_dir():
121121
try:
122122
# check if it's a Python module
123123
if find_spec(f"dojo.tools.{module_name}.parser"):

dojo/views.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
import os
32
from pathlib import Path
43

54
from auditlog.models import LogEntry
@@ -151,7 +150,7 @@ def manage_files(request, oid, obj_type):
151150

152151
for o in files_formset.deleted_objects:
153152
logger.debug("removing file: %s", o.file.name)
154-
Path(os.path.join(settings.MEDIA_ROOT, o.file.name)).unlink()
153+
(Path(settings.MEDIA_ROOT) / o.file.name).unlink()
155154

156155
for o in files_formset.new_objects:
157156
logger.debug("adding file: %s", o.file.name)
@@ -162,7 +161,7 @@ def manage_files(request, oid, obj_type):
162161
finding__isnull=True)
163162
for o in orphan_files:
164163
logger.debug("purging orphan file: %s", o.file.name)
165-
Path(os.path.join(settings.MEDIA_ROOT, o.file.name)).unlink()
164+
(Path(settings.MEDIA_ROOT) / o.file.name).unlink()
166165
o.delete()
167166

168167
messages.add_message(

ruff.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ select = [
6868
"TC",
6969
"INT",
7070
"ARG003", "ARG004", "ARG005",
71-
"PTH2", "PTH10", "PTH110", "PTH111", "PTH112", "PTH113", "PTH114", "PTH115", "PTH116", "PTH117", "PTH119", "PTH120", "PTH121", "PTH122", "PTH124",
71+
"PTH2", "PTH10", "PTH11", "PTH120", "PTH121", "PTH122", "PTH124",
7272
"TD001", "TD004", "TD005",
7373
"FIX001", "FIX003",
7474
"PD",

tests/file_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def test_add_file_finding_level(self):
3535
driver.find_element(By.LINK_TEXT, "Manage Files").click()
3636
# select first file input field: form-0-image
3737
# Set full image path for image file 'strange.png
38-
image_path = os.path.join(dir_path, "finding_image.png")
38+
image_path = dir_path / "finding_image.png"
3939
driver.find_element(By.ID, "id_form-0-title").send_keys("Finding Title")
40-
driver.find_element(By.ID, "id_form-0-file").send_keys(image_path)
40+
driver.find_element(By.ID, "id_form-0-file").send_keys(str(image_path))
4141
# Save uploaded image
4242
with WaitForPageLoad(driver, timeout=50):
4343
driver.find_element(By.CSS_SELECTOR, "button.btn.btn-success").click()
@@ -76,9 +76,9 @@ def test_add_file_test_level(self):
7676
driver.find_element(By.NAME, "Manage Files").click()
7777
# select first file input field: form-0-image
7878
# Set full image path for image file 'strange.png
79-
image_path = os.path.join(dir_path, "finding_image.png")
79+
image_path = dir_path / "finding_image.png"
8080
driver.find_element(By.ID, "id_form-0-title").send_keys("Test Title")
81-
driver.find_element(By.ID, "id_form-0-file").send_keys(image_path)
81+
driver.find_element(By.ID, "id_form-0-file").send_keys(str(image_path))
8282
# Save uploaded image
8383
with WaitForPageLoad(driver, timeout=50):
8484
driver.find_element(By.CSS_SELECTOR, "button.btn.btn-success").click()
@@ -116,9 +116,9 @@ def test_add_file_engagement_level(self):
116116
driver.find_element(By.NAME, "Manage Files").click()
117117
# select first file input field: form-0-image
118118
# Set full image path for image file 'strange.png
119-
image_path = os.path.join(dir_path, "finding_image.png")
119+
image_path = dir_path / "finding_image.png"
120120
driver.find_element(By.ID, "id_form-0-title").send_keys("Engagement Title")
121-
driver.find_element(By.ID, "id_form-0-file").send_keys(image_path)
121+
driver.find_element(By.ID, "id_form-0-file").send_keys(str(image_path))
122122
# Save uploaded image
123123
with WaitForPageLoad(driver, timeout=50):
124124
driver.find_element(By.CSS_SELECTOR, "button.btn.btn-success").click()

tests/finding_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ def test_add_image(self):
146146
driver.find_element(By.LINK_TEXT, "Manage Files").click()
147147
# select first file input field: form-0-image
148148
# Set full image path for image file 'strange.png
149-
image_path = os.path.join(dir_path, "finding_image.png")
150-
driver.find_element(By.ID, "id_form-0-file").send_keys(image_path)
149+
image_path = dir_path / "finding_image.png"
150+
driver.find_element(By.ID, "id_form-0-file").send_keys(str(image_path))
151151
driver.find_element(By.ID, "id_form-0-title").send_keys("Image Title")
152152
# Save uploaded image
153153
with WaitForPageLoad(driver, timeout=50):
@@ -466,8 +466,8 @@ def test_import_scan_result(self):
466466
# Select `Default` as the Environment
467467
Select(driver.find_element(By.ID, "id_environment")).select_by_visible_text("Development")
468468
# upload scan file
469-
file_path = os.path.join(dir_path, "zap_sample.xml")
470-
driver.find_element(By.NAME, "file").send_keys(file_path)
469+
file_path = dir_path / "zap_sample.xml"
470+
driver.find_element(By.NAME, "file").send_keys(str(file_path))
471471
# Click Submit button
472472
with WaitForPageLoad(driver, timeout=50):
473473
driver.find_elements(By.CSS_SELECTOR, "button.btn.btn-primary")[1].click()

tests/ibm_appscan_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def test_import_ibm_app_scan_result(self):
3131
# Select `Default` as the Environment
3232
Select(driver.find_element(By.ID, "id_environment")).select_by_visible_text("Development")
3333
# Upload Scan result file
34-
scanner_file = os.path.join(dir_path, "ibm_appscan_xml_file.xml")
35-
driver.find_element(By.NAME, "file").send_keys(scanner_file)
34+
scanner_file = dir_path / "ibm_appscan_xml_file.xml"
35+
driver.find_element(By.NAME, "file").send_keys(str(scanner_file))
3636
# click on upload button
3737
driver.find_elements(By.CSS_SELECTOR, "button.btn.btn-primary")[1].click()
3838
# Query the site to determine if the finding has been added

0 commit comments

Comments
 (0)