From cfb490a1766e4d97eb8ca3167aa59b2219739bc5 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 29 Mar 2022 00:08:14 +0000 Subject: [PATCH] chore(python): use black==22.3.0 (#359) Source-Link: https://github.com/googleapis/synthtool/commit/6fab84af09f2cf89a031fd8671d1def6b2931b11 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:7cffbc10910c3ab1b852c05114a08d374c195a81cdec1d4a67a1d129331d0bfe --- dlp/snippets/custom_infotype.py | 9 ++++-- dlp/snippets/deid.py | 37 +++++++++++++++++------- dlp/snippets/deid_test.py | 9 ++++-- dlp/snippets/inspect_content.py | 10 +++++-- dlp/snippets/inspect_content_test.py | 2 +- dlp/snippets/metadata.py | 5 ++-- dlp/snippets/noxfile.py | 4 +-- dlp/snippets/redact.py | 18 +++++++++--- dlp/snippets/redact_test.py | 9 ++++-- dlp/snippets/risk.py | 39 ++++++++++++++++++-------- dlp/snippets/risk_test.py | 42 +++++++++++++++++++++++----- dlp/snippets/triggers.py | 4 ++- 12 files changed, 139 insertions(+), 49 deletions(-) diff --git a/dlp/snippets/custom_infotype.py b/dlp/snippets/custom_infotype.py index 338576c3a5d9..9ecc993f76a7 100644 --- a/dlp/snippets/custom_infotype.py +++ b/dlp/snippets/custom_infotype.py @@ -408,7 +408,8 @@ def inspect_string_custom_omit_overlap(project, content_string): # [START dlp_omit_name_if_also_email] def omit_name_if_also_email( - project, content_string, + project, + content_string, ): """Matches PERSON_NAME and EMAIL_ADDRESS, but not both. @@ -731,7 +732,8 @@ def inspect_string_multiple_rules(project, content_string): # [START dlp_inspect_with_medical_record_number_custom_regex_detector] def inspect_with_medical_record_number_custom_regex_detector( - project, content_string, + project, + content_string, ): """Uses the Data Loss Prevention API to analyze string with medical record number custom regex detector @@ -793,7 +795,8 @@ def inspect_with_medical_record_number_custom_regex_detector( # [START dlp_inspect_with_medical_record_number_w_custom_hotwords] def inspect_with_medical_record_number_w_custom_hotwords( - project, content_string, + project, + content_string, ): """Uses the Data Loss Prevention API to analyze string with medical record number custom regex detector, with custom hotwords rules to boost finding diff --git a/dlp/snippets/deid.py b/dlp/snippets/deid.py index 5d79064d7af2..0f745e0ac104 100644 --- a/dlp/snippets/deid.py +++ b/dlp/snippets/deid.py @@ -85,7 +85,9 @@ def deidentify_with_mask( # [START dlp_deidentify_redact] def deidentify_with_redact( - project, input_str, info_types, + project, + input_str, + info_types, ): """Uses the Data Loss Prevention API to deidentify sensitive data in a string by redacting matched input values. @@ -135,7 +137,10 @@ def deidentify_with_redact( # [START dlp_deidentify_replace] def deidentify_with_replace( - project, input_str, info_types, replacement_str="REPLACEMENT_STR", + project, + input_str, + info_types, + replacement_str="REPLACEMENT_STR", ): """Uses the Data Loss Prevention API to deidentify sensitive data in a string by replacing matched input values with a value you specify. @@ -471,7 +476,11 @@ def reidentify_with_fpe( # [START dlp_reidentify_deterministic] def reidentify_with_deterministic( - project, input_str, surrogate_type=None, key_name=None, wrapped_key=None, + project, + input_str, + surrogate_type=None, + key_name=None, + wrapped_key=None, ): """Re-identifies content that was previously de-identified through deterministic encryption. Args: @@ -949,7 +958,8 @@ def deidentify_with_replace_infotype(project, item, info_types): default=["FIRST_NAME", "LAST_NAME", "EMAIL_ADDRESS"], ) mask_parser.add_argument( - "project", help="The Google Cloud project id to use as a parent resource.", + "project", + help="The Google Cloud project id to use as a parent resource.", ) mask_parser.add_argument("item", help="The string to deidentify.") mask_parser.add_argument( @@ -982,7 +992,8 @@ def deidentify_with_replace_infotype(project, item, info_types): default=["FIRST_NAME", "LAST_NAME", "EMAIL_ADDRESS"], ) replace_parser.add_argument( - "project", help="The Google Cloud project id to use as a parent resource.", + "project", + help="The Google Cloud project id to use as a parent resource.", ) replace_parser.add_argument("item", help="The string to deidentify.") replace_parser.add_argument( @@ -1004,7 +1015,8 @@ def deidentify_with_replace_infotype(project, item, info_types): default=["FIRST_NAME", "LAST_NAME", "EMAIL_ADDRESS"], ) fpe_parser.add_argument( - "project", help="The Google Cloud project id to use as a parent resource.", + "project", + help="The Google Cloud project id to use as a parent resource.", ) fpe_parser.add_argument( "item", @@ -1046,7 +1058,8 @@ def deidentify_with_replace_infotype(project, item, info_types): "Encryption (FPE).", ) reid_parser.add_argument( - "project", help="The Google Cloud project id to use as a parent resource.", + "project", + help="The Google Cloud project id to use as a parent resource.", ) reid_parser.add_argument( "item", @@ -1086,7 +1099,8 @@ def deidentify_with_replace_infotype(project, item, info_types): help="Deidentify dates in a CSV file by pseudorandomly shifting them.", ) date_shift_parser.add_argument( - "project", help="The Google Cloud project id to use as a parent resource.", + "project", + help="The Google Cloud project id to use as a parent resource.", ) date_shift_parser.add_argument( "input_csv_file", @@ -1149,7 +1163,8 @@ def deidentify_with_replace_infotype(project, item, info_types): default=["FIRST_NAME", "LAST_NAME", "EMAIL_ADDRESS"], ) replace_with_infotype_parser.add_argument( - "project", help="The Google Cloud project id to use as a parent resource.", + "project", + help="The Google Cloud project id to use as a parent resource.", ) replace_with_infotype_parser.add_argument( "item", @@ -1207,5 +1222,7 @@ def deidentify_with_replace_infotype(project, item, info_types): ) elif args.content == "replace_with_infotype": deidentify_with_replace_infotype( - args.project, item=args.item, info_types=args.info_types, + args.project, + item=args.item, + info_types=args.info_types, ) diff --git a/dlp/snippets/deid_test.py b/dlp/snippets/deid_test.py index a2b66efd2f0c..5e3325803dde 100644 --- a/dlp/snippets/deid_test.py +++ b/dlp/snippets/deid_test.py @@ -81,7 +81,10 @@ def test_deidentify_with_mask_masking_character_specified(capsys): def test_deidentify_with_mask_masking_number_specified(capsys): deid.deidentify_with_mask( - GCLOUD_PROJECT, HARMFUL_STRING, ["US_SOCIAL_SECURITY_NUMBER"], number_to_mask=7, + GCLOUD_PROJECT, + HARMFUL_STRING, + ["US_SOCIAL_SECURITY_NUMBER"], + number_to_mask=7, ) out, _ = capsys.readouterr() @@ -278,7 +281,9 @@ def test_reidentify_free_text_with_fpe_using_surrogate(capsys): def test_deidentify_with_replace_infotype(capsys): url_to_redact = "https://cloud.google.com" deid.deidentify_with_replace_infotype( - GCLOUD_PROJECT, "My favorite site is " + url_to_redact, ["URL"], + GCLOUD_PROJECT, + "My favorite site is " + url_to_redact, + ["URL"], ) out, _ = capsys.readouterr() diff --git a/dlp/snippets/inspect_content.py b/dlp/snippets/inspect_content.py index 4b048727de56..ce7633e77a99 100644 --- a/dlp/snippets/inspect_content.py +++ b/dlp/snippets/inspect_content.py @@ -24,7 +24,9 @@ # [START dlp_inspect_string_basic] def inspect_string_basic( - project, content_string, info_types=["PHONE_NUMBER"], + project, + content_string, + info_types=["PHONE_NUMBER"], ): """Uses the Data Loss Prevention API to analyze strings for protected data. Args: @@ -1197,7 +1199,8 @@ def callback(message): help="The Google Cloud project id of the target Datastore.", ) parser_datastore.add_argument( - "kind", help='The kind of the Datastore entity to inspect, e.g. "Person".', + "kind", + help='The kind of the Datastore entity to inspect, e.g. "Person".', ) parser_datastore.add_argument( "topic_id", @@ -1273,7 +1276,8 @@ def callback(message): "bigquery", help="Inspect files on Google BigQuery." ) parser_bigquery.add_argument( - "bigquery_project", help="The Google Cloud project id of the target table.", + "bigquery_project", + help="The Google Cloud project id of the target table.", ) parser_bigquery.add_argument( "dataset_id", help="The ID of the target BigQuery dataset." diff --git a/dlp/snippets/inspect_content_test.py b/dlp/snippets/inspect_content_test.py index e77d3aee872b..645143e35edf 100644 --- a/dlp/snippets/inspect_content_test.py +++ b/dlp/snippets/inspect_content_test.py @@ -159,7 +159,7 @@ def bigquery_project(): except google.api_core.exceptions.Conflict: table = bigquery_client.get_table(table) - rows_to_insert = [(u"Gary Smith", u"My email is gary@example.com")] + rows_to_insert = [("Gary Smith", "My email is gary@example.com")] bigquery_client.insert_rows(table, rows_to_insert) diff --git a/dlp/snippets/metadata.py b/dlp/snippets/metadata.py index 0a3b4380f35d..0782a6a059e8 100644 --- a/dlp/snippets/metadata.py +++ b/dlp/snippets/metadata.py @@ -46,7 +46,7 @@ def list_info_types(language_code=None, result_filter=None): print("Info types:") for info_type in response.info_types: print( - u"{name}: {display_name}".format( + "{name}: {display_name}".format( name=info_type.name, display_name=info_type.display_name ) ) @@ -58,7 +58,8 @@ def list_info_types(language_code=None, result_filter=None): if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__) parser.add_argument( - "--language_code", help="The BCP-47 language code to use, e.g. 'en-US'.", + "--language_code", + help="The BCP-47 language code to use, e.g. 'en-US'.", ) parser.add_argument( "--filter", diff --git a/dlp/snippets/noxfile.py b/dlp/snippets/noxfile.py index 85f5836dba3a..25f87a215d4c 100644 --- a/dlp/snippets/noxfile.py +++ b/dlp/snippets/noxfile.py @@ -29,7 +29,7 @@ # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING -BLACK_VERSION = "black==19.10b0" +BLACK_VERSION = "black==22.3.0" # Copy `noxfile_config.py` to your directory and modify it instead. @@ -253,7 +253,7 @@ def py(session: nox.sessions.Session) -> None: def _get_repo_root() -> Optional[str]: - """ Returns the root folder of the project. """ + """Returns the root folder of the project.""" # Get root of this repository. Assume we don't have directories nested deeper than 10 items. p = Path(os.getcwd()) for i in range(10): diff --git a/dlp/snippets/redact.py b/dlp/snippets/redact.py index d99eee529b49..867224a4e5de 100644 --- a/dlp/snippets/redact.py +++ b/dlp/snippets/redact.py @@ -30,7 +30,12 @@ def redact_image( - project, filename, output_filename, info_types, min_likelihood=None, mime_type=None, + project, + filename, + output_filename, + info_types, + min_likelihood=None, + mime_type=None, ): """Uses the Data Loss Prevention API to redact protected data in an image. Args: @@ -122,7 +127,9 @@ def redact_image( def redact_image_all_text( - project, filename, output_filename, + project, + filename, + output_filename, ): """Uses the Data Loss Prevention API to redact all text in an image. @@ -184,7 +191,8 @@ def redact_image_all_text( ) common_args_parser.add_argument("filename", help="The path to the file to inspect.") common_args_parser.add_argument( - "output_filename", help="The path to which the redacted image will be written.", + "output_filename", + help="The path to which the redacted image will be written.", ) parser = argparse.ArgumentParser(description=__doc__) @@ -246,5 +254,7 @@ def redact_image_all_text( ) elif args.content == "all_text": redact_image_all_text( - args.project, args.filename, args.output_filename, + args.project, + args.filename, + args.output_filename, ) diff --git a/dlp/snippets/redact_test.py b/dlp/snippets/redact_test.py index a6f85e33745d..0cce514eb1a6 100644 --- a/dlp/snippets/redact_test.py +++ b/dlp/snippets/redact_test.py @@ -36,7 +36,10 @@ def test_redact_image_file(tempdir, capsys): output_filepath = os.path.join(tempdir, "redacted.png") redact.redact_image( - GCLOUD_PROJECT, test_filepath, output_filepath, ["FIRST_NAME", "EMAIL_ADDRESS"], + GCLOUD_PROJECT, + test_filepath, + output_filepath, + ["FIRST_NAME", "EMAIL_ADDRESS"], ) out, _ = capsys.readouterr() @@ -48,7 +51,9 @@ def test_redact_image_all_text(tempdir, capsys): output_filepath = os.path.join(tempdir, "redacted.png") redact.redact_image_all_text( - GCLOUD_PROJECT, test_filepath, output_filepath, + GCLOUD_PROJECT, + test_filepath, + output_filepath, ) out, _ = capsys.readouterr() diff --git a/dlp/snippets/risk.py b/dlp/snippets/risk.py index a630eee260d8..7070d06e50cb 100644 --- a/dlp/snippets/risk.py +++ b/dlp/snippets/risk.py @@ -95,7 +95,8 @@ def callback(message): results = job.risk_details.numerical_stats_result print( "Value Range: [{}, {}]".format( - results.min_value.integer_value, results.max_value.integer_value, + results.min_value.integer_value, + results.max_value.integer_value, ) ) prev_value = None @@ -684,7 +685,8 @@ def callback(message): numerical_parser = subparsers.add_parser("numerical", help="") numerical_parser.add_argument( - "project", help="The Google Cloud project id to use as a parent resource.", + "project", + help="The Google Cloud project id to use as a parent resource.", ) numerical_parser.add_argument( "table_project_id", @@ -695,7 +697,8 @@ def callback(message): ) numerical_parser.add_argument("table_id", help="The id of the table to inspect.") numerical_parser.add_argument( - "column_name", help="The name of the column to compute risk metrics for.", + "column_name", + help="The name of the column to compute risk metrics for.", ) numerical_parser.add_argument( "topic_id", @@ -714,7 +717,8 @@ def callback(message): categorical_parser = subparsers.add_parser("categorical", help="") categorical_parser.add_argument( - "project", help="The Google Cloud project id to use as a parent resource.", + "project", + help="The Google Cloud project id to use as a parent resource.", ) categorical_parser.add_argument( "table_project_id", @@ -725,7 +729,8 @@ def callback(message): ) categorical_parser.add_argument("table_id", help="The id of the table to inspect.") categorical_parser.add_argument( - "column_name", help="The name of the column to compute risk metrics for.", + "column_name", + help="The name of the column to compute risk metrics for.", ) categorical_parser.add_argument( "topic_id", @@ -747,7 +752,8 @@ def callback(message): help="Computes the k-anonymity of a column set in a Google BigQuery" "table.", ) k_anonymity_parser.add_argument( - "project", help="The Google Cloud project id to use as a parent resource.", + "project", + help="The Google Cloud project id to use as a parent resource.", ) k_anonymity_parser.add_argument( "table_project_id", @@ -767,7 +773,9 @@ def callback(message): "job completion notifications.", ) k_anonymity_parser.add_argument( - "quasi_ids", nargs="+", help="A set of columns that form a composite key.", + "quasi_ids", + nargs="+", + help="A set of columns that form a composite key.", ) k_anonymity_parser.add_argument( "--timeout", @@ -780,7 +788,8 @@ def callback(message): help="Computes the l-diversity of a column set in a Google BigQuery" "table.", ) l_diversity_parser.add_argument( - "project", help="The Google Cloud project id to use as a parent resource.", + "project", + help="The Google Cloud project id to use as a parent resource.", ) l_diversity_parser.add_argument( "table_project_id", @@ -800,10 +809,13 @@ def callback(message): "job completion notifications.", ) l_diversity_parser.add_argument( - "sensitive_attribute", help="The column to measure l-diversity relative to.", + "sensitive_attribute", + help="The column to measure l-diversity relative to.", ) l_diversity_parser.add_argument( - "quasi_ids", nargs="+", help="A set of columns that form a composite key.", + "quasi_ids", + nargs="+", + help="A set of columns that form a composite key.", ) l_diversity_parser.add_argument( "--timeout", @@ -817,7 +829,8 @@ def callback(message): "BigQuery table.", ) k_map_parser.add_argument( - "project", help="The Google Cloud project id to use as a parent resource.", + "project", + help="The Google Cloud project id to use as a parent resource.", ) k_map_parser.add_argument( "table_project_id", @@ -835,7 +848,9 @@ def callback(message): "job completion notifications.", ) k_map_parser.add_argument( - "quasi_ids", nargs="+", help="A set of columns that form a composite key.", + "quasi_ids", + nargs="+", + help="A set of columns that form a composite key.", ) k_map_parser.add_argument( "-t", diff --git a/dlp/snippets/risk_test.py b/dlp/snippets/risk_test.py index 75a1fb7cc484..d6231117c116 100644 --- a/dlp/snippets/risk_test.py +++ b/dlp/snippets/risk_test.py @@ -116,14 +116,42 @@ def bigquery_project(): except google.api_core.exceptions.Conflict: harmful_table = bigquery_client.get_table(harmful_table) - rows_to_insert = [(u"Gary Smith", u"My email is gary@example.com")] + rows_to_insert = [("Gary Smith", "My email is gary@example.com")] harmful_rows_to_insert = [ - (u"Gandalf", u"(123) 456-7890", "4231 5555 6781 9876", 27, "Male", "US",), - (u"Dumbledore", u"(313) 337-1337", "6291 8765 1095 7629", 27, "Male", "US",), - (u"Joe", u"(452) 123-1234", "3782 2288 1166 3030", 35, "Male", "US"), - (u"James", u"(567) 890-1234", "8291 3627 8250 1234", 19, "Male", "US"), - (u"Marie", u"(452) 123-1234", "8291 3627 8250 1234", 35, "Female", "US",), - (u"Carrie", u"(567) 890-1234", "2253 5218 4251 4526", 35, "Female", "US",), + ( + "Gandalf", + "(123) 456-7890", + "4231 5555 6781 9876", + 27, + "Male", + "US", + ), + ( + "Dumbledore", + "(313) 337-1337", + "6291 8765 1095 7629", + 27, + "Male", + "US", + ), + ("Joe", "(452) 123-1234", "3782 2288 1166 3030", 35, "Male", "US"), + ("James", "(567) 890-1234", "8291 3627 8250 1234", 19, "Male", "US"), + ( + "Marie", + "(452) 123-1234", + "8291 3627 8250 1234", + 35, + "Female", + "US", + ), + ( + "Carrie", + "(567) 890-1234", + "2253 5218 4251 4526", + 35, + "Female", + "US", + ), ] bigquery_client.insert_rows(table, rows_to_insert) diff --git a/dlp/snippets/triggers.py b/dlp/snippets/triggers.py index 0070da3cd773..dae75c2d5008 100644 --- a/dlp/snippets/triggers.py +++ b/dlp/snippets/triggers.py @@ -245,7 +245,9 @@ def delete_trigger(project, trigger_id): help="The maximum number of findings to report; 0 = no maximum.", ) parser_create.add_argument( - "--auto_populate_timespan", type=bool, help="Limit scan to new content only.", + "--auto_populate_timespan", + type=bool, + help="Limit scan to new content only.", ) parser_list = subparsers.add_parser("list", help="List all triggers.")