Skip to content

Commit d2ad922

Browse files
mmhwmoishce
authored andcommitted
[pre-commit ruff] Align the entire repo with ruff (#29603)
* Fix falls of the ruff hook * pre-commit * Fix B003 ruff error * Fix ruff errors on Utils/update_playbook.py
1 parent 015f6be commit d2ad922

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

Packs/CimTrak-SystemIntegrityAssurance/Integrations/CimTrak/CimTrak_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
"""
1515

1616
import json
17-
import io
1817
import logging
1918

2019
LOGGER = logging.getLogger(__name__)
2120

2221

2322
def util_load_json(path):
24-
with io.open(path, mode="r", encoding="utf-8") as f:
23+
with open(path, encoding="utf-8") as f:
2524
return json.loads(f.read())
2625

2726

@@ -45,7 +44,7 @@ def test_cimtrak(requests_mock):
4544
pre_script += " }\n"
4645
pre_script += ")\n"
4746

48-
exec(pre_script + test_json["execute"], globals())
47+
exec(pre_script + test_json["execute"], globals()) # noqa: S102
4948
dict_expected_result = test_json["response"]
5049
dict_actual_result = response
5150

Utils/_script_docker_python_loop_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ def do_ping_pong():
448448

449449

450450
def rollback_system():
451-
os.environ = {}
451+
os.environ.clear()
452452
for key in backup_env_vars:
453453
os.environ[key] = backup_env_vars[key]
454454

@@ -480,7 +480,7 @@ def rollback_system():
480480
'win': win
481481
}
482482

483-
exec(code, sub_globals, sub_globals) # guardrails-disable-line # pylint: disable=W0122
483+
exec(code, sub_globals, sub_globals) # guardrails-disable-line # pylint: disable=W0122 # noqa: S102
484484

485485
except Exception:
486486
exc_type, exc_value, exc_traceback = sys.exc_info()

Utils/update_playbook.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import sys
23
import ntpath
34
import yaml
@@ -26,7 +27,7 @@ def update_playbook_task_name(playbook):
2627
:param playbook: playbook dict loaded from yaml
2728
:return: updated playbook dict
2829
"""
29-
for task_id, task in playbook.get("tasks", {}).items():
30+
for _task_id, task in playbook.get("tasks", {}).items():
3031
if task.get("type") == "playbook":
3132
task["task"]["name"] = task["task"]["playbookName"]
3233

@@ -92,10 +93,10 @@ def update_replace_copy_dev(playbook):
9293

9394

9495
def update_playbook(source_path, destination_path):
95-
print("Starting...")
96+
logging.info("Starting...")
9697

9798
with open(source_path) as f:
98-
playbook = yaml.load(f, Loader=yamlordereddictloader.SafeLoader)
99+
playbook = yaml.safe_load(f)
99100

100101
playbook = update_replace_copy_dev(playbook)
101102

@@ -114,14 +115,14 @@ def update_playbook(source_path, destination_path):
114115
destination_path = ntpath.basename(source_path)
115116

116117
if not destination_path.startswith("playbook-"):
117-
destination_path = "playbook-{}".format(destination_path)
118+
destination_path = f"playbook-{destination_path}"
118119

119120
# Configure safe dumper (multiline for strings)
120121
yaml.SafeDumper.org_represent_str = yaml.SafeDumper.represent_str # type: ignore[attr-defined]
121122

122123
def repr_str(dumper, data):
123124
if '\n' in data:
124-
return dumper.represent_scalar(u'tag:yaml.org,2002:str', data, style='|')
125+
return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='|')
125126
return dumper.org_represent_str(data)
126127
yaml.add_representer(str, repr_str, Dumper=yamlordereddictloader.SafeDumper)
127128

@@ -132,12 +133,12 @@ def repr_str(dumper, data):
132133
Dumper=yamlordereddictloader.SafeDumper,
133134
default_flow_style=False)
134135

135-
print("Finished - new yml saved at {}".format(destination_path))
136+
logging.info(f"Finished - new yml saved at {destination_path}")
136137

137138

138139
def main(argv):
139140
if len(argv) < 1:
140-
print("Please provide <source playbook path>, <optional - destination playbook path>")
141+
logging.info("Please provide <source playbook path>, <optional - destination playbook path>")
141142
sys.exit(1)
142143

143144
source_path = argv[0]

0 commit comments

Comments
 (0)