Skip to content

Commit 540d1f1

Browse files
committed
refactor: fix invalid escape sequences
Signed-off-by: Kevin James <KevinJames@thekev.in>
1 parent 0d098db commit 540d1f1

File tree

19 files changed

+46
-40
lines changed

19 files changed

+46
-40
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ repos:
1515
- id: double-quote-string-fixer
1616
- id: no-commit-to-branch
1717
args: [--branch, master]
18+
- repo: https://github.com/PyCQA/flake8
19+
rev: 7.1.1
20+
hooks:
21+
- id: flake8
22+
args:
23+
- --select=W605
1824
# required formatting jobs (run these last)
1925

2026
# add comment "noqa" to ignore an import that should not be removed

backend/src/apiserver/visualization/types/tfdv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def get_statistics_html(
7272
# facets element and then remove it once we have appended the serialized proto
7373
# string to the element. We do this to avoid any collision of ids when
7474
# displaying multiple facets output in the notebook.
75-
html_template = """<iframe id='facets-iframe' width="100%" height="500px"></iframe>
75+
html_template = r"""<iframe id='facets-iframe' width="100%" height="500px"></iframe>
7676
<script>
7777
facets_iframe = document.getElementById('facets-iframe');
7878
facets_html = '<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/1.3.3/webcomponents-lite.js"><\/script><link rel="import" href="https://raw.githubusercontent.com/PAIR-code/facets/master/facets-dist/facets-jupyter.html"><facets-overview proto-input="protostr"></facets-overview>';

components/aws/athena/query/src/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def query(client, query, database, output, workgroup=None):
6363
"OutputLocation"
6464
]
6565
# could be multiple files?
66-
filename = re.findall(".*\/(.*)", s3_path)[0]
66+
filename = re.findall(r".*\/(.*)", s3_path)[0]
6767
logging.info("S3 output file name %s", filename)
6868
break
6969
time.sleep(5)

components/google-cloud/google_cloud_pipeline_components/container/v1/aiplatform/remote_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def write_to_artifact(executor_input, text):
8888
# Add URI Prefix
8989
# "https://[location]-aiplatform.googleapis.com/API_VERSION/": For AI Platform resource names, current version is defined in AIPLATFORM_API_VERSION.
9090
if RESOURCE_NAME_PATTERN.match(text):
91-
location = re.findall('locations/([\w\-]+)', text)[0]
91+
location = re.findall(r'locations/([\w\-]+)', text)[0]
9292
uri_with_prefix = f'https://{location}-aiplatform.googleapis.com/{AIPLATFORM_API_VERSION}/{text}'
9393
metadata.update({'resourceName': text})
9494

components/google-cloud/google_cloud_pipeline_components/v1/hyperparameter_tuning_job/component.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def hyperparameter_tuning_job(
4242
project: str = _placeholders.PROJECT_ID_PLACEHOLDER,
4343
):
4444
# fmt: off
45-
"""Creates a Vertex AI hyperparameter tuning job and waits for it to
45+
r"""Creates a Vertex AI hyperparameter tuning job and waits for it to
4646
complete.
4747
4848
See [more information](https://cloud.google.com/vertex-ai/docs/training/using-hyperparameter-tuning).

proxy/get_proxy_url.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def urls_for_zone(zone, location_to_urls_map):
4040
...
4141
}
4242
"""
43-
zone_match = re.match("((([a-z]+)-[a-z]+)\d+)-[a-z]", zone)
43+
zone_match = re.match(r"((([a-z]+)-[a-z]+)\d+)-[a-z]", zone)
4444
if not zone_match:
4545
raise ValueError("Incorrect zone specified: {}".format(zone))
4646

@@ -55,7 +55,7 @@ def urls_for_zone(zone, location_to_urls_map):
5555
url for url in location_to_urls_map[region] if url not in urls
5656
])
5757

58-
region_regex = re.compile("([a-z]+-[a-z]+)\d+")
58+
region_regex = re.compile(r"([a-z]+-[a-z]+)\d+")
5959
for location in location_to_urls_map:
6060
region_match = region_regex.match(location)
6161
if region_match and region_match.group(1) == approx_region:

sdk/python/kfp/compiler/compiler_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4445,7 +4445,7 @@ def test_other_control_flow_instantiated_between_if_else_not_permitted(
44454445
self):
44464446
with self.assertRaisesRegex(
44474447
tasks_group.InvalidControlFlowException,
4448-
'dsl\.Else can only be used following an upstream dsl\.If or dsl\.Elif\.'
4448+
r'dsl\.Else can only be used following an upstream dsl\.If or dsl\.Elif\.'
44494449
):
44504450

44514451
@dsl.pipeline
@@ -4908,7 +4908,7 @@ def flip_coin_pipeline(execute_pipeline: bool):
49084908
def test_nested_under_condition_returned_raises(self):
49094909
with self.assertRaisesRegex(
49104910
compiler_utils.InvalidTopologyException,
4911-
f'Pipeline outputs may only be returned from the top level of the pipeline function scope\. Got pipeline output dsl\.OneOf from within the control flow group dsl\.If\.'
4911+
r'Pipeline outputs may only be returned from the top level of the pipeline function scope\. Got pipeline output dsl\.OneOf from within the control flow group dsl\.If\.'
49124912
):
49134913

49144914
@dsl.pipeline
@@ -4961,7 +4961,7 @@ def test_deeply_nested_returned_raises(self):
49614961

49624962
with self.assertRaisesRegex(
49634963
compiler_utils.InvalidTopologyException,
4964-
f'Pipeline outputs may only be returned from the top level of the pipeline function scope\. Got pipeline output dsl\.OneOf from within the control flow group dsl\.ParallelFor\.'
4964+
r'Pipeline outputs may only be returned from the top level of the pipeline function scope\. Got pipeline output dsl\.OneOf from within the control flow group dsl\.ParallelFor\.'
49654965
):
49664966

49674967
@dsl.pipeline
@@ -4983,7 +4983,7 @@ def test_consume_at_wrong_level(self):
49834983

49844984
with self.assertRaisesRegex(
49854985
compiler_utils.InvalidTopologyException,
4986-
f'Illegal task dependency across DSL context managers\. A downstream task cannot depend on an upstream task within a dsl\.If context unless the downstream is within that context too\. Found task print-artifact which depends on upstream task condition-branches-5 within an uncommon dsl\.If context\.'
4986+
r'Illegal task dependency across DSL context managers\. A downstream task cannot depend on an upstream task within a dsl\.If context unless the downstream is within that context too\. Found task print-artifact which depends on upstream task condition-branches-5 within an uncommon dsl\.If context\.'
49874987
):
49884988

49894989
@dsl.pipeline
@@ -5006,7 +5006,7 @@ def flip_coin_pipeline(execute_pipeline: bool):
50065006
def test_return_at_wrong_level(self):
50075007
with self.assertRaisesRegex(
50085008
compiler_utils.InvalidTopologyException,
5009-
f'Pipeline outputs may only be returned from the top level of the pipeline function scope\. Got pipeline output dsl\.OneOf from within the control flow group dsl\.If\.'
5009+
r'Pipeline outputs may only be returned from the top level of the pipeline function scope\. Got pipeline output dsl\.OneOf from within the control flow group dsl\.If\.'
50105010
):
50115011

50125012
@dsl.pipeline
@@ -5143,7 +5143,7 @@ def roll_die_pipeline(
51435143
def test_oneof_in_fstring(self):
51445144
with self.assertRaisesRegex(
51455145
NotImplementedError,
5146-
f'dsl\.OneOf does not support string interpolation\.'):
5146+
r'dsl\.OneOf does not support string interpolation\.'):
51475147

51485148
@dsl.pipeline
51495149
def roll_die_pipeline():

sdk/python/kfp/deprecated/compiler/v2_compatible_compiler_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def _load_compiled_template(filename: str) -> Dict:
8888

8989
if 'container' in template:
9090
template['container'] = json.loads(
91-
re.sub("'kfp==(\d+).(\d+).(\d+)'", 'kfp',
91+
re.sub(r"'kfp==(\d+).(\d+).(\d+)'", 'kfp',
9292
json.dumps(template['container'])))
9393

9494
return workflow
@@ -154,8 +154,8 @@ def my_pipeline():
154154
with self.assertRaisesRegex(
155155
RuntimeError,
156156
'Constructing ContainerOp instances directly is deprecated and not '
157-
'supported when compiling to v2 \(using v2 compiler or v1 compiler '
158-
'with V2_COMPATIBLE or V2_ENGINE mode\).'):
157+
r'supported when compiling to v2 \(using v2 compiler or v1 compiler '
158+
r'with V2_COMPATIBLE or V2_ENGINE mode\)\.'):
159159
compiler.Compiler(
160160
mode=v1dsl.PipelineExecutionMode.V2_COMPATIBLE).compile(
161161
pipeline_func=my_pipeline, package_path='result.json')

sdk/python/kfp/deprecated/components/type_annotation_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def get_short_type_name(type_name: str) -> str:
5858
Returns:
5959
The short form type name or the original name if pattern doesn't match.
6060
"""
61-
match = re.match('(typing\.)?(?P<type>\w+)(?:\[.+\])?', type_name)
61+
match = re.match(r'(typing\.)?(?P<type>\w+)(?:\[.+\])?', type_name)
6262
if match:
6363
return match.group('type')
6464
else:

sdk/python/kfp/deprecated/components_tests/test_python_op.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ def my_func(args: Sequence[int]):
12241224
task_factory = comp.create_component_from_func(my_func)
12251225
with self.assertRaisesRegex(
12261226
TypeError,
1227-
'There are no registered serializers for type "(typing.)?Sequence(\[int\])?"'
1227+
r'There are no registered serializers for type "(typing.)?Sequence(\[int\])?"'
12281228
):
12291229
self.helper_test_component_using_local_call(
12301230
task_factory, arguments={'args': [1, 2, 3]})

sdk/python/kfp/deprecated/dsl/_ops_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _get_matching_opsgroup_already_in_pipeline(group_type, name):
6868
if name is None:
6969
return None
7070
name_pattern = '^' + (group_type + '-' + name + '-').replace(
71-
'_', '-') + '[\d]+$'
71+
'_', '-') + r'[\d]+$'
7272
for ops_group_already_in_pipeline in _pipeline.Pipeline.get_default_pipeline(
7373
).groups:
7474
import re

sdk/python/kfp/dsl/executor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def get_short_type_name(type_name: str) -> str:
400400
Returns:
401401
The short form type name or the original name if pattern doesn't match.
402402
"""
403-
match = re.match('(typing\.)?(?P<type>\w+)(?:\[.+\])?', type_name)
403+
match = re.match(r'(typing\.)?(?P<type>\w+)(?:\[.+\])?', type_name)
404404
return match['type'] if match else type_name
405405

406406

sdk/python/kfp/dsl/for_loop.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _get_loop_item_type(type_name: str) -> Optional[str]:
4444
Returns:
4545
The collection item type or None if no match found.
4646
"""
47-
match = re.match('(typing\.)?(?:\w+)(?:\[(?P<item_type>.+)\])', type_name)
47+
match = re.match(r'(typing\.)?(?:\w+)(?:\[(?P<item_type>.+)\])', type_name)
4848
return match['item_type'].lstrip().rstrip() if match else None
4949

5050

@@ -64,7 +64,7 @@ def _get_subvar_type(type_name: str) -> Optional[str]:
6464
The dictionary value type or None if no match found.
6565
"""
6666
match = re.match(
67-
'(typing\.)?(?:\w+)(?:\[\s*(?:\w+)\s*,\s*(?P<value_type>.+)\])',
67+
r'(typing\.)?(?:\w+)(?:\[\s*(?:\w+)\s*,\s*(?P<value_type>.+)\])',
6868
type_name)
6969
return match['value_type'].lstrip().rstrip() if match else None
7070

sdk/python/kfp/dsl/placeholders_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def test_valid(self, placeholder_obj: placeholders.IfPresentPlaceholder,
299299
def test_only_single_element_ifpresent_inside_concat_outer(self):
300300
with self.assertRaisesRegex(
301301
ValueError,
302-
f'Please use a single element for `then` and `else_` only\.'):
302+
r'Please use a single element for `then` and `else_` only\.'):
303303
placeholders.ConcatPlaceholder([
304304
'b',
305305
placeholders.IfPresentPlaceholder(
@@ -309,7 +309,7 @@ def test_only_single_element_ifpresent_inside_concat_outer(self):
309309
def test_only_single_element_ifpresent_inside_concat_recursive(self):
310310
with self.assertRaisesRegex(
311311
ValueError,
312-
f'Please use a single element for `then` and `else_` only\.'):
312+
r'Please use a single element for `then` and `else_` only\.'):
313313
placeholders.ConcatPlaceholder([
314314
'a',
315315
placeholders.ConcatPlaceholder([
@@ -323,7 +323,7 @@ def test_only_single_element_ifpresent_inside_concat_recursive(self):
323323

324324
with self.assertRaisesRegex(
325325
ValueError,
326-
f'Please use a single element for `then` and `else_` only\.'):
326+
r'Please use a single element for `then` and `else_` only\.'):
327327
placeholders.ConcatPlaceholder([
328328
'a',
329329
placeholders.ConcatPlaceholder([
@@ -341,7 +341,7 @@ def test_only_single_element_ifpresent_inside_concat_recursive(self):
341341
def test_only_single_element_in_nested_ifpresent_inside_concat(self):
342342
with self.assertRaisesRegex(
343343
ValueError,
344-
f'Please use a single element for `then` and `else_` only\.'):
344+
r'Please use a single element for `then` and `else_` only\.'):
345345
dsl.ConcatPlaceholder([
346346
'my-prefix-',
347347
dsl.IfPresentPlaceholder(
@@ -357,7 +357,7 @@ def test_recursive_nested_placeholder_validation_does_not_exit_when_first_valid_
357357
self):
358358
with self.assertRaisesRegex(
359359
ValueError,
360-
f'Please use a single element for `then` and `else_` only\.'):
360+
r'Please use a single element for `then` and `else_` only\.'):
361361
dsl.ConcatPlaceholder([
362362
'my-prefix-',
363363
dsl.IfPresentPlaceholder(
@@ -371,7 +371,7 @@ def test_only_single_element_in_nested_ifpresent_inside_concat_with_outer_ifpres
371371
self):
372372
with self.assertRaisesRegex(
373373
ValueError,
374-
f'Please use a single element for `then` and `else_` only\.'):
374+
r'Please use a single element for `then` and `else_` only\.'):
375375
dsl.IfPresentPlaceholder(
376376
input_name='input_1',
377377
then=dsl.ConcatPlaceholder([
@@ -386,7 +386,7 @@ def test_only_single_element_in_nested_ifpresent_inside_concat_with_outer_ifpres
386386
def test_valid_then_but_invalid_else(self):
387387
with self.assertRaisesRegex(
388388
ValueError,
389-
f'Please use a single element for `then` and `else_` only\.'):
389+
r'Please use a single element for `then` and `else_` only\.'):
390390
dsl.ConcatPlaceholder([
391391
'my-prefix-',
392392
dsl.IfPresentPlaceholder(

sdk/python/kfp/dsl/tasks_group_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def foo() -> str:
7474
def my_pipeline(string: str):
7575
with self.assertWarnsRegex(
7676
DeprecationWarning,
77-
'dsl\.Condition is deprecated\. Please use dsl\.If instead\.'
77+
r'dsl\.Condition is deprecated\. Please use dsl\.If instead\.'
7878
):
7979
with dsl.Condition(string == 'text'):
8080
foo()

sdk/python/kfp/dsl/types/type_annotations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def get_short_type_name(type_name: str) -> str:
227227
Returns:
228228
The short form type name or the original name if pattern doesn't match.
229229
"""
230-
match = re.match('(typing\.)?(?P<type>\w+)(?:\[.+\])?', type_name)
230+
match = re.match(r'(typing\.)?(?P<type>\w+)(?:\[.+\])?', type_name)
231231
return match['type'] if match else type_name
232232

233233

sdk/python/kfp/local/config_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_validate_success(self):
7070
def test_validate_fail(self):
7171
with self.assertRaisesRegex(
7272
RuntimeError,
73-
f"Local environment not initialized. Please run 'kfp\.local\.init\(\)' before executing tasks locally\."
73+
r"Local environment not initialized. Please run 'kfp\.local\.init\(\)' before executing tasks locally\."
7474
):
7575
config.LocalExecutionConfig.validate()
7676

test/sample-test/sample_test_launcher.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def _compile(self):
9292
for file in list_of_files:
9393
# matching by .py or .ipynb, there will be yaml ( compiled ) files in the folder.
9494
# if you rerun the test suite twice, the test suite will fail
95-
m = re.match(self._test_name + '\.(py|ipynb)$', file)
95+
m = re.match(self._test_name + r'\.(py|ipynb)$', file)
9696
if m:
9797
file_name, ext_name = os.path.splitext(file)
9898
if self._is_notebook is not None:
@@ -242,14 +242,14 @@ def __init__(self,
242242
def _injection(self):
243243
"""Sample-specific image injection into yaml file."""
244244
subs = { # Tag can look like 1.0.0-rc.3, so we need both "-" and "." in the regex.
245-
'gcr\.io/ml-pipeline/ml-pipeline/ml-pipeline-local-confusion-matrix:(\w+|[.-])+':
245+
r'gcr\.io/ml-pipeline/ml-pipeline/ml-pipeline-local-confusion-matrix:(\w+|[.-])+':
246246
self._local_confusionmatrix_image,
247-
'gcr\.io/ml-pipeline/ml-pipeline/ml-pipeline-local-roc:(\w+|[.-])+':
247+
r'gcr\.io/ml-pipeline/ml-pipeline/ml-pipeline-local-roc:(\w+|[.-])+':
248248
self._local_roc_image
249249
}
250250
if self._test_name == 'xgboost_training_cm':
251251
subs.update({
252-
'gcr\.io/ml-pipeline/ml-pipeline-gcp:(\w|[.-])+':
252+
r'gcr\.io/ml-pipeline/ml-pipeline-gcp:(\w|[.-])+':
253253
self._dataproc_gcp_image
254254
})
255255

test/sample-test/unittests/utils_tests.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ def tearDown(self) -> None:
4848
def test_file_injection(self):
4949
"""Test file_injection function."""
5050
subs = {
51-
'gcr\.io/ml-pipeline/ml-pipeline-local-confusion-matrix:\w+':'gcr.io/ml-pipeline/LOCAL_CONFUSION_MATRIX_IMAGE',
52-
'gcr\.io/ml-pipeline/ml-pipeline-dataproc-analyze:\w+':'gcr.io/ml-pipeline/DATAPROC_ANALYZE_IMAGE',
53-
'gcr\.io/ml-pipeline/ml-pipeline-dataproc-create-cluster:\w+':'gcr.io/ml-pipeline/DATAPROC_CREATE_IMAGE',
54-
'gcr\.io/ml-pipeline/ml-pipeline-dataproc-delete-cluster:\w+':'gcr.io/ml-pipeline/DATAPROC_DELETE_IMAGE',
51+
r'gcr\.io/ml-pipeline/ml-pipeline-local-confusion-matrix:\w+':'gcr.io/ml-pipeline/LOCAL_CONFUSION_MATRIX_IMAGE',
52+
r'gcr\.io/ml-pipeline/ml-pipeline-dataproc-analyze:\w+':'gcr.io/ml-pipeline/DATAPROC_ANALYZE_IMAGE',
53+
r'gcr\.io/ml-pipeline/ml-pipeline-dataproc-create-cluster:\w+':'gcr.io/ml-pipeline/DATAPROC_CREATE_IMAGE',
54+
r'gcr\.io/ml-pipeline/ml-pipeline-dataproc-delete-cluster:\w+':'gcr.io/ml-pipeline/DATAPROC_DELETE_IMAGE',
5555
}
5656
utils.file_injection(
5757
os.path.join(_WORK_DIR, 'test_file_injection.yaml'),
@@ -64,4 +64,4 @@ def test_file_injection(self):
6464
with open(os.path.join(_WORK_DIR,
6565
'test_file_injection.yaml'), 'r') as f:
6666
injected = yaml.safe_load(f)
67-
self.assertEqual(golden, injected)
67+
self.assertEqual(golden, injected)

0 commit comments

Comments
 (0)