Skip to content

Commit 4858c81

Browse files
authored
Linting fixes, compile fixes (#5)
1 parent 7fda01e commit 4858c81

7 files changed

Lines changed: 62 additions & 23 deletions

File tree

contrib/linux/sensors/file_watch_sensor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ def add_trigger(self, trigger):
5555
self.file_ref[file_path] = ref
5656

5757
stop_event = threading.Event()
58-
t = threading.Thread(target=self._tail, args=(file_path, stop_event), daemon=True)
58+
t = threading.Thread(
59+
target=self._tail, args=(file_path, stop_event), daemon=True
60+
)
5961
self._watchers[file_path] = (t, stop_event)
6062
t.start()
6163

st2common/st2common/content/validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from __future__ import absolute_import
1717
import os
18-
from importlib_metadata import get_distribution
18+
from importlib_metadata import distribution as get_distribution
1919

2020
from st2common.constants.pack import USER_PACK_NAME_BLACKLIST
2121

st2common/st2common/models/utils/action_alias_utils.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ def match_kv_pairs_at_end(self):
121121
ending_pairs = re.match(self._snippets["ending"], param_stream, re.DOTALL)
122122
has_ending_pairs = ending_pairs and ending_pairs.group(1)
123123
if has_ending_pairs:
124-
kv_pairs = re.findall(self._snippets["pairs"], ending_pairs.group(1), re.DOTALL)
124+
kv_pairs = re.findall(
125+
self._snippets["pairs"], ending_pairs.group(1), re.DOTALL
126+
)
125127
param_stream = param_stream.replace(ending_pairs.group(1), "")
126128
else:
127129
kv_pairs = []
@@ -138,7 +140,9 @@ def transform_format_string_into_regex(self):
138140
# Transforming our format string into a regular expression,
139141
# substituting {{ ... }} with regex named groups, so that param_stream
140142
# matched against this expression yields a dict of params with values.
141-
param_match = r'\1["\']?(?P<\2>(?:(?<=\').+?(?=\')|(?<=").+?(?=")|{.+?}|.+?))["\']?'
143+
param_match = (
144+
r'\1["\']?(?P<\2>(?:(?<=\').+?(?=\')|(?<=").+?(?=")|{.+?}|.+?))["\']?'
145+
)
142146
reg = re.sub(
143147
r"(\s*)" + self._snippets["optional"],
144148
r"(?:" + param_match + r")?",
@@ -149,11 +153,15 @@ def transform_format_string_into_regex(self):
149153
reg_tokens = parse(reg, flags=re.DOTALL)
150154

151155
# Add a beginning anchor if none exists
152-
if not search_regex_tokens(((AT, AT_BEGINNING), (AT, AT_BEGINNING_STRING)), reg_tokens):
156+
if not search_regex_tokens(
157+
((AT, AT_BEGINNING), (AT, AT_BEGINNING_STRING)), reg_tokens
158+
):
153159
reg = r"^\s*" + reg
154160

155161
# Add an ending anchor if none exists
156-
if not search_regex_tokens(((AT, AT_END), (AT, AT_END_STRING)), reg_tokens, backwards=True):
162+
if not search_regex_tokens(
163+
((AT, AT_END), (AT, AT_END_STRING)), reg_tokens, backwards=True
164+
):
157165
reg = reg + r"\s*$"
158166

159167
return re.compile(reg, re.DOTALL)
@@ -246,7 +254,9 @@ def extract_parameters(format_str, param_stream, match_multiple=False):
246254
return parser.get_extracted_param_value()
247255

248256

249-
def inject_immutable_parameters(action_alias_db, multiple_execution_parameters, action_context):
257+
def inject_immutable_parameters(
258+
action_alias_db, multiple_execution_parameters, action_context
259+
):
250260
"""
251261
Inject immutable parameters from the alias definiton on the execution parameters.
252262
Jinja expressions will be resolved.
@@ -274,10 +284,14 @@ def inject_immutable_parameters(action_alias_db, multiple_execution_parameters,
274284
rendered_params = render_values(immutable_parameters, context)
275285

276286
for exec_params in multiple_execution_parameters:
277-
overriden = [param for param in immutable_parameters.keys() if param in exec_params]
287+
overriden = [
288+
param for param in immutable_parameters.keys() if param in exec_params
289+
]
278290
if overriden:
279291
raise ValueError(
280-
"Immutable arguments cannot be overriden: {}".format(",".join(overriden))
292+
"Immutable arguments cannot be overriden: {}".format(
293+
",".join(overriden)
294+
)
281295
)
282296

283297
exec_params.update(rendered_params)

st2common/st2common/util/schema/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def get_action_parameters_schema(additional_properties=False):
155155
"pattern": Draft4Validator.VALIDATORS["pattern"],
156156
"patternProperties": Draft4Validator.VALIDATORS["patternProperties"],
157157
"properties": Draft3Validator.VALIDATORS["properties"],
158-
# "required": Draft3Validator.VALIDATORS["required"],
158+
# "required": Draft3Validator.VALIDATORS["required"],
159159
"type": Draft4Validator.VALIDATORS["type"],
160160
"uniqueItems": Draft4Validator.VALIDATORS["uniqueItems"],
161161
},

st2common/tests/unit/test_action_alias_utils.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ def test_arbitrary_pairs(self):
9898
param_stream = 'Malcolm Reynolds is my captain weirdo="River Tam"'
9999
parser = ActionAliasFormatParser(alias_format, param_stream)
100100
extracted_values = parser.get_extracted_param_value()
101-
self.assertEqual(extracted_values, {"captain": "Malcolm Reynolds", "weirdo": "River Tam"})
101+
self.assertEqual(
102+
extracted_values, {"captain": "Malcolm Reynolds", "weirdo": "River Tam"}
103+
)
102104

103105
def test_simple_parsing(self):
104106
alias_format = "skip {{a}} more skip {{b}} and skip more."
@@ -126,7 +128,9 @@ def test_default_values(self):
126128
param_stream = 'acl "a1 a2" "b1" "c1"'
127129
parser = ActionAliasFormatParser(alias_format, param_stream)
128130
extracted_values = parser.get_extracted_param_value()
129-
self.assertEqual(extracted_values, {"a": "a1 a2", "b": "b1", "c": "c1", "d": "1"})
131+
self.assertEqual(
132+
extracted_values, {"a": "a1 a2", "b": "b1", "c": "c1", "d": "1"}
133+
)
130134

131135
def test_spacing(self):
132136
alias_format = "acl {{a=test}}"
@@ -154,7 +158,9 @@ def test_param_spaces(self):
154158
param_stream = "s one more two more three more"
155159
parser = ActionAliasFormatParser(alias_format, param_stream)
156160
extracted_values = parser.get_extracted_param_value()
157-
self.assertEqual(extracted_values, {"a": "one", "b": "two", "c": "three", "d": "99"})
161+
self.assertEqual(
162+
extracted_values, {"a": "one", "b": "two", "c": "three", "d": "99"}
163+
)
158164

159165
def test_enclosed_defaults(self):
160166
alias_format = "skip {{ a = value }} more"
@@ -220,15 +226,22 @@ def test_stream_is_none_no_default_values(self):
220226
param_stream = None
221227
parser = ActionAliasFormatParser(alias_format, param_stream)
222228

223-
expected_msg = 'Command "" doesn\'t match format string "skip {{d}} more skip {{e}}."'
224-
self.assertRaisesRegex(ParseException, expected_msg, parser.get_extracted_param_value)
229+
expected_msg = (
230+
'Command "" doesn\'t match format string "skip {{d}} more skip {{e}}."'
231+
)
232+
self.assertRaisesRegex(
233+
ParseException, expected_msg, parser.get_extracted_param_value
234+
)
225235

226236
def test_all_the_things(self):
227237
# this is the most insane example I could come up with
228238
alias_format = (
229-
"{{ p0='http' }} g {{ p1=p }} a " + "{{ url }} {{ p2={'a':'b'} }} {{ p3={{ e.i }} }}"
239+
"{{ p0='http' }} g {{ p1=p }} a "
240+
+ "{{ url }} {{ p2={'a':'b'} }} {{ p3={{ e.i }} }}"
241+
)
242+
param_stream = (
243+
"g a http://google.com {{ execution.id }} p4='testing' p5={'a':'c'}"
230244
)
231-
param_stream = "g a http://google.com {{ execution.id }} p4='testing' p5={'a':'c'}"
232245
parser = ActionAliasFormatParser(alias_format, param_stream)
233246
extracted_values = parser.get_extracted_param_value()
234247
self.assertEqual(
@@ -249,8 +262,12 @@ def test_command_doesnt_match_format_string(self):
249262
param_stream = "foo lulz ponies"
250263
parser = ActionAliasFormatParser(alias_format, param_stream)
251264

252-
expected_msg = 'Command "foo lulz ponies" doesn\'t match format string "foo bar ponies"'
253-
self.assertRaisesRegex(ParseException, expected_msg, parser.get_extracted_param_value)
265+
expected_msg = (
266+
'Command "foo lulz ponies" doesn\'t match format string "foo bar ponies"'
267+
)
268+
self.assertRaisesRegex(
269+
ParseException, expected_msg, parser.get_extracted_param_value
270+
)
254271

255272
def test_ending_parameters_matching(self):
256273
alias_format = "foo bar"
@@ -364,14 +381,18 @@ def test_immutable_parameters_are_injected(self):
364381
action_alias_db.immutable_parameters = {"env": "dev"}
365382
exec_params = [{"param1": "value1", "param2": "value2"}]
366383
inject_immutable_parameters(action_alias_db, exec_params, {})
367-
self.assertEqual(exec_params, [{"param1": "value1", "param2": "value2", "env": "dev"}])
384+
self.assertEqual(
385+
exec_params, [{"param1": "value1", "param2": "value2", "env": "dev"}]
386+
)
368387

369388
def test_immutable_parameters_with_jinja(self):
370389
action_alias_db = Mock()
371390
action_alias_db.immutable_parameters = {"env": '{{ "dev" + "1" }}'}
372391
exec_params = [{"param1": "value1", "param2": "value2"}]
373392
inject_immutable_parameters(action_alias_db, exec_params, {})
374-
self.assertEqual(exec_params, [{"param1": "value1", "param2": "value2", "env": "dev1"}])
393+
self.assertEqual(
394+
exec_params, [{"param1": "value1", "param2": "value2", "env": "dev1"}]
395+
)
375396

376397
def test_override_raises_error(self):
377398
action_alias_db = Mock()

st2common/tests/unit/test_util_output_schema.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ def test_invalid_runner_schema(self):
208208
OUTPUT_KEY,
209209
)
210210

211-
expected_error = "Additional properties are not allowed ('output' was unexpected)"
211+
expected_error = (
212+
"Additional properties are not allowed ('output' was unexpected)"
213+
)
212214
expected_message = "Error validating output. See error output for more details."
213215

214216
# Use assertIn to avoid fragile exact-string matching: jsonschema error messages

test-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ tox==4.14.2
3636
pyrabbit
3737
prance==25.4.8.0
3838
# pip-tools provides pip-compile: to check for version conflicts
39-
pip-tools==7.4.1
39+
pip-tools==7.5.3
4040
pytest==7.0.1
4141
pytest-benchmark[histogram]==3.4.1
4242
pytest-icdiff==0.9

0 commit comments

Comments
 (0)