From 6d85d7a0d17ad50941e4e7a720194074cb13467f Mon Sep 17 00:00:00 2001 From: William Chargin Date: Mon, 30 Nov 2020 18:47:33 -0800 Subject: [PATCH 1/4] ci: upgrade Black to v20.8b1, drop Python 2.7/3.5, and disable check Summary: See #4406. Subsequent commits will re-run Black with the new settings and new version (these commits will be ignored for blame purposes), and then another commit will re-enable enforcement. wchargin-branch: black-20x-no27-no35 --- .github/workflows/ci.yml | 5 +++-- pyproject.toml | 4 +--- tensorboard/pip_package/requirements_dev.txt | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76da1741f1..d156104c75 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: # flake8 should run on each Python version that we target, # because the errors and warnings can differ due to language # changes, and we want to catch them all. - python_version: ['3.5', '3.7'] + python_version: ['3.6', '3.7'] steps: - uses: actions/checkout@v1 - uses: actions/setup-python@v1 @@ -65,7 +65,8 @@ jobs: - run: pip freeze --all - name: 'Lint Python code for style with Black' # You can run `black .` to fix all Black complaints. - run: black --check --diff . + # TODO(#4406): Re-enable this check. + run: black --check --diff . || true lint-rust: runs-on: ubuntu-16.04 diff --git a/pyproject.toml b/pyproject.toml index cc5891c6fb..74ff519048 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,3 @@ [tool.black] line-length = 80 -# TODO(@wchargin): Drop `py35` here once we drop support for Python 3.5 -# and aren't affected by . -target-version = ["py27", "py35", "py36", "py37", "py38"] +target-version = ["py36", "py37", "py38"] diff --git a/tensorboard/pip_package/requirements_dev.txt b/tensorboard/pip_package/requirements_dev.txt index cd4679cde8..853ce23ff9 100644 --- a/tensorboard/pip_package/requirements_dev.txt +++ b/tensorboard/pip_package/requirements_dev.txt @@ -23,7 +23,7 @@ boto3==1.9.86 moto==1.3.7 # For linting -black==19.10b0; python_version >= "3.6" +black==20.8b1; python_version >= "3.6" flake8==3.7.8 yamllint==1.17.0 From f14d4833bb7f0dd0d5e5510e32d53e343e959fb8 Mon Sep 17 00:00:00 2001 From: TensorBoard Gardener Date: Mon, 30 Nov 2020 18:47:46 -0800 Subject: [PATCH 2/4] black: reformat after dropping Python 2.7 and 3.5 Summary: This is a clean run of Black 19.10b0 after removing `py27` and `py35` from the list of target versions in `pyproject.toml`. See #4406. wchargin-branch: black-20x-no27-no35 --- .../backend/event_processing/data_provider.py | 6 ++-- .../event_processing/event_accumulator.py | 2 +- .../event_accumulator_test.py | 12 +++---- .../plugin_event_accumulator_test.py | 16 ++++----- tensorboard/backend/http_util.py | 4 +-- tensorboard/backend/json_util_test.py | 2 +- .../tensorflow_stub/io/gfile_s3_test.py | 16 ++++----- .../compat/tensorflow_stub/io/gfile_test.py | 16 ++++----- tensorboard/data/dispatching_provider_test.py | 6 ++-- tensorboard/data/grpc_provider.py | 2 +- tensorboard/data/provider.py | 10 +++--- .../tensorboard_plugin_example/plugin.py | 2 +- tensorboard/plugin_util.py | 2 +- tensorboard/plugin_util_test.py | 34 +++++++++---------- tensorboard/plugins/base_plugin.py | 4 +-- .../debugger_v2/debug_data_provider.py | 4 +-- .../plugins/graph/graphs_plugin_test.py | 2 +- .../plugins/hparams/hparams_minimal_demo.py | 6 ++-- tensorboard/plugins/image/images_demo.py | 4 +-- tensorboard/plugins/text/summary_test.py | 6 ++-- tensorboard/plugins/text/text_demo.py | 2 +- tensorboard/tools/diagnose_tensorboard.py | 22 ++++++------ tensorboard/uploader/auth.py | 2 +- tensorboard/uploader/exporter.py | 32 ++++++++--------- tensorboard/uploader/exporter_test.py | 2 +- tensorboard/uploader/uploader_subcommand.py | 12 +++---- 26 files changed, 112 insertions(+), 116 deletions(-) diff --git a/tensorboard/backend/event_processing/data_provider.py b/tensorboard/backend/event_processing/data_provider.py index 473e04e01d..1a33441da1 100644 --- a/tensorboard/backend/event_processing/data_provider.py +++ b/tensorboard/backend/event_processing/data_provider.py @@ -129,7 +129,7 @@ def read_scalars( experiment_id, plugin_name, downsample=None, - run_tag_filter=None + run_tag_filter=None, ): self._validate_context(ctx) self._validate_experiment_id(experiment_id) @@ -156,7 +156,7 @@ def read_tensors( experiment_id, plugin_name, downsample=None, - run_tag_filter=None + run_tag_filter=None, ): self._validate_context(ctx) self._validate_experiment_id(experiment_id) @@ -313,7 +313,7 @@ def read_blob_sequences( experiment_id, plugin_name, downsample=None, - run_tag_filter=None + run_tag_filter=None, ): self._validate_context(ctx) self._validate_experiment_id(experiment_id) diff --git a/tensorboard/backend/event_processing/event_accumulator.py b/tensorboard/backend/event_processing/event_accumulator.py index 56d2be8132..5143acc0ae 100644 --- a/tensorboard/backend/event_processing/event_accumulator.py +++ b/tensorboard/backend/event_processing/event_accumulator.py @@ -778,7 +778,7 @@ def _ExpiredPerTag(value): self.most_recent_wall_time, event.step, event.wall_time, - *expired_per_type + *expired_per_type, ) logger.warning(purge_msg) diff --git a/tensorboard/backend/event_processing/event_accumulator_test.py b/tensorboard/backend/event_processing/event_accumulator_test.py index 180a562018..d30cfb6e45 100644 --- a/tensorboard/backend/event_processing/event_accumulator_test.py +++ b/tensorboard/backend/event_processing/event_accumulator_test.py @@ -785,12 +785,12 @@ def testTFSummaryImage(self): accumulator.Reload() tags = [ - u"1/images/image", - u"2/images/image/0", - u"2/images/image/1", - u"3/images/image/0", - u"3/images/image/1", - u"3/images/image/2", + "1/images/image", + "2/images/image/0", + "2/images/image/1", + "3/images/image/0", + "3/images/image/1", + "3/images/image/2", ] self.assertTagsEqual( diff --git a/tensorboard/backend/event_processing/plugin_event_accumulator_test.py b/tensorboard/backend/event_processing/plugin_event_accumulator_test.py index f315695a06..98ac612228 100644 --- a/tensorboard/backend/event_processing/plugin_event_accumulator_test.py +++ b/tensorboard/backend/event_processing/plugin_event_accumulator_test.py @@ -401,8 +401,8 @@ def testNewStyleScalarSummary(self): tags = [ graph_metadata.RUN_GRAPH_NAME, - u"accuracy/scalar_summary", - u"xent/scalar_summary", + "accuracy/scalar_summary", + "xent/scalar_summary", ] self.assertTagsEqual( accumulator.Tags(), @@ -445,9 +445,9 @@ def testNewStyleAudioSummary(self): tags = [ graph_metadata.RUN_GRAPH_NAME, - u"1/one/audio_summary", - u"2/two/audio_summary", - u"3/three/audio_summary", + "1/one/audio_summary", + "2/two/audio_summary", + "3/three/audio_summary", ] self.assertTagsEqual( accumulator.Tags(), @@ -488,9 +488,9 @@ def testNewStyleImageSummary(self): tags = [ graph_metadata.RUN_GRAPH_NAME, - u"1/images/image_summary", - u"2/images/image_summary", - u"3/images/image_summary", + "1/images/image_summary", + "2/images/image_summary", + "3/images/image_summary", ] self.assertTagsEqual( accumulator.Tags(), diff --git a/tensorboard/backend/http_util.py b/tensorboard/backend/http_util.py index 28838cd2a7..59ff73f70e 100644 --- a/tensorboard/backend/http_util.py +++ b/tensorboard/backend/http_util.py @@ -232,7 +232,7 @@ def Respond( "data:", # used by What-If tool for image sprites. "blob:", - *_CSP_IMG_DOMAINS_WHITELIST + *_CSP_IMG_DOMAINS_WHITELIST, ), "object-src 'none'", "style-src %s" @@ -243,7 +243,7 @@ def Respond( "data:", # inline styles: Polymer templates + d3 uses inline styles. "'unsafe-inline'", - *_CSP_STYLE_DOMAINS_WHITELIST + *_CSP_STYLE_DOMAINS_WHITELIST, ), "connect-src %s" % _create_csp_string("'self'", *_CSP_CONNECT_DOMAINS_WHITELIST), diff --git a/tensorboard/backend/json_util_test.py b/tensorboard/backend/json_util_test.py index e0d030be52..b2e745b30d 100644 --- a/tensorboard/backend/json_util_test.py +++ b/tensorboard/backend/json_util_test.py @@ -69,7 +69,7 @@ def testSet_turnsIntoSortedList(self): def testByteString_turnsIntoUnicodeString(self): self.assertEqual( - json_util.Cleanse(b"\xc2\xa3"), u"\u00a3" + json_util.Cleanse(b"\xc2\xa3"), "\u00a3" ) # is # sterling diff --git a/tensorboard/compat/tensorflow_stub/io/gfile_s3_test.py b/tensorboard/compat/tensorflow_stub/io/gfile_s3_test.py index 67a9dbf18c..675f59fa16 100644 --- a/tensorboard/compat/tensorflow_stub/io/gfile_s3_test.py +++ b/tensorboard/compat/tensorflow_stub/io/gfile_s3_test.py @@ -156,10 +156,8 @@ def testRead(self): @mock_s3 def testReadLines(self): - ckpt_lines = ( - [u"\n"] + [u"line {}\n".format(i) for i in range(10)] + [u" "] - ) - ckpt_content = u"".join(ckpt_lines) + ckpt_lines = ["\n"] + ["line {}\n".format(i) for i in range(10)] + [" "] + ckpt_content = "".join(ckpt_lines) temp_dir = self._CreateDeepS3Structure(ckpt_content=ckpt_content) ckpt_path = self._PathJoin(temp_dir, "model.ckpt") with gfile.GFile(ckpt_path, "r") as f: @@ -193,7 +191,7 @@ def testReadWithOffset(self): def testWrite(self): temp_dir = self._CreateDeepS3Structure() ckpt_path = os.path.join(temp_dir, "model2.ckpt") - ckpt_content = u"asdfasdfasdffoobarbuzz" + ckpt_content = "asdfasdfasdffoobarbuzz" with gfile.GFile(ckpt_path, "w") as f: f.write(ckpt_content) with gfile.GFile(ckpt_path, "r") as f: @@ -204,9 +202,9 @@ def testWrite(self): def testOverwrite(self): temp_dir = self._CreateDeepS3Structure() ckpt_path = os.path.join(temp_dir, "model2.ckpt") - ckpt_content = u"asdfasdfasdffoobarbuzz" + ckpt_content = "asdfasdfasdffoobarbuzz" with gfile.GFile(ckpt_path, "w") as f: - f.write(u"original") + f.write("original") with gfile.GFile(ckpt_path, "w") as f: f.write(ckpt_content) with gfile.GFile(ckpt_path, "r") as f: @@ -217,7 +215,7 @@ def testOverwrite(self): def testWriteMultiple(self): temp_dir = self._CreateDeepS3Structure() ckpt_path = os.path.join(temp_dir, "model2.ckpt") - ckpt_content = u"asdfasdfasdffoobarbuzz" * 5 + ckpt_content = "asdfasdfasdffoobarbuzz" * 5 with gfile.GFile(ckpt_path, "w") as f: for i in range(0, len(ckpt_content), 3): f.write(ckpt_content[i : i + 3]) @@ -232,7 +230,7 @@ def testWriteMultiple(self): def testWriteEmpty(self): temp_dir = self._CreateDeepS3Structure() ckpt_path = os.path.join(temp_dir, "model2.ckpt") - ckpt_content = u"" + ckpt_content = "" with gfile.GFile(ckpt_path, "w") as f: f.write(ckpt_content) with gfile.GFile(ckpt_path, "r") as f: diff --git a/tensorboard/compat/tensorflow_stub/io/gfile_test.py b/tensorboard/compat/tensorflow_stub/io/gfile_test.py index af2e825151..d751861f6b 100644 --- a/tensorboard/compat/tensorflow_stub/io/gfile_test.py +++ b/tensorboard/compat/tensorflow_stub/io/gfile_test.py @@ -151,15 +151,15 @@ def testReadLines(self): # the underlying byte offsets (counting \r). Multibyte characters would # similarly cause desynchronization. raw_ckpt_lines = ( - [u"\r\n"] + [u"line {}\r\n".format(i) for i in range(10)] + [u" "] + ["\r\n"] + ["line {}\r\n".format(i) for i in range(10)] + [" "] ) expected_ckpt_lines = ( # without \r - [u"\n"] + [u"line {}\n".format(i) for i in range(10)] + [u" "] + ["\n"] + ["line {}\n".format(i) for i in range(10)] + [" "] ) # Write out newlines as given (i.e., \r\n) regardless of OS, so as to # test translation on read. with io.open(ckpt_path, "w", newline="") as f: - data = u"".join(raw_ckpt_lines) + data = "".join(raw_ckpt_lines) f.write(data) with gfile.GFile(ckpt_path, "r") as f: f.buff_chunk_size = 4 # Test buffering by reducing chunk size @@ -194,7 +194,7 @@ def testWrite(self): temp_dir = self.get_temp_dir() self._CreateDeepDirectoryStructure(temp_dir) ckpt_path = os.path.join(temp_dir, "model2.ckpt") - ckpt_content = u"asdfasdfasdffoobarbuzz" + ckpt_content = "asdfasdfasdffoobarbuzz" with gfile.GFile(ckpt_path, "w") as f: f.write(ckpt_content) with open(ckpt_path, "r") as f: @@ -205,9 +205,9 @@ def testOverwrite(self): temp_dir = self.get_temp_dir() self._CreateDeepDirectoryStructure(temp_dir) ckpt_path = os.path.join(temp_dir, "model2.ckpt") - ckpt_content = u"asdfasdfasdffoobarbuzz" + ckpt_content = "asdfasdfasdffoobarbuzz" with gfile.GFile(ckpt_path, "w") as f: - f.write(u"original") + f.write("original") with gfile.GFile(ckpt_path, "w") as f: f.write(ckpt_content) with open(ckpt_path, "r") as f: @@ -218,7 +218,7 @@ def testWriteMultiple(self): temp_dir = self.get_temp_dir() self._CreateDeepDirectoryStructure(temp_dir) ckpt_path = os.path.join(temp_dir, "model2.ckpt") - ckpt_content = u"asdfasdfasdffoobarbuzz" * 5 + ckpt_content = "asdfasdfasdffoobarbuzz" * 5 with gfile.GFile(ckpt_path, "w") as f: for i in range(0, len(ckpt_content), 3): f.write(ckpt_content[i : i + 3]) @@ -233,7 +233,7 @@ def testWriteEmpty(self): temp_dir = self.get_temp_dir() self._CreateDeepDirectoryStructure(temp_dir) ckpt_path = os.path.join(temp_dir, "model2.ckpt") - ckpt_content = u"" + ckpt_content = "" with gfile.GFile(ckpt_path, "w") as f: f.write(ckpt_content) with open(ckpt_path, "r") as f: diff --git a/tensorboard/data/dispatching_provider_test.py b/tensorboard/data/dispatching_provider_test.py index 35ce4dcb11..6004261852 100644 --- a/tensorboard/data/dispatching_provider_test.py +++ b/tensorboard/data/dispatching_provider_test.py @@ -74,7 +74,7 @@ def read_scalars( experiment_id, plugin_name, downsample=None, - run_tag_filter=None + run_tag_filter=None, ): self._validate_eid(experiment_id) if run_tag_filter is None: @@ -113,7 +113,7 @@ def read_tensors( experiment_id, plugin_name, downsample=None, - run_tag_filter=None + run_tag_filter=None, ): raise NotImplementedError() @@ -143,7 +143,7 @@ def read_blob_sequences( experiment_id, plugin_name, downsample=None, - run_tag_filter=None + run_tag_filter=None, ): self._validate_eid(experiment_id) if run_tag_filter is None: diff --git a/tensorboard/data/grpc_provider.py b/tensorboard/data/grpc_provider.py index 28ead050bc..a1e6d5f440 100644 --- a/tensorboard/data/grpc_provider.py +++ b/tensorboard/data/grpc_provider.py @@ -103,7 +103,7 @@ def read_scalars( experiment_id, plugin_name, downsample=None, - run_tag_filter=None + run_tag_filter=None, ): with timing.log_latency("build request"): req = data_provider_pb2.ReadScalarsRequest() diff --git a/tensorboard/data/provider.py b/tensorboard/data/provider.py index 657b325f10..09fb3e3e6b 100644 --- a/tensorboard/data/provider.py +++ b/tensorboard/data/provider.py @@ -211,7 +211,7 @@ def read_scalars( experiment_id, plugin_name, downsample=None, - run_tag_filter=None + run_tag_filter=None, ): """Read values from scalar time series. @@ -274,7 +274,7 @@ def read_tensors( experiment_id, plugin_name, downsample=None, - run_tag_filter=None + run_tag_filter=None, ): """Read values from tensor time series. @@ -335,7 +335,7 @@ def read_blob_sequences( experiment_id, plugin_name, downsample=None, - run_tag_filter=None + run_tag_filter=None, ): """Read values from blob sequence time series. @@ -484,7 +484,7 @@ def __init__( max_wall_time, plugin_content, description, - display_name + display_name, ): self._max_step = max_step self._max_wall_time = max_wall_time @@ -761,7 +761,7 @@ def __init__( max_length, plugin_content, description, - display_name + display_name, ): super(BlobSequenceTimeSeries, self).__init__( max_step=max_step, diff --git a/tensorboard/examples/plugins/example_basic/tensorboard_plugin_example/plugin.py b/tensorboard/examples/plugins/example_basic/tensorboard_plugin_example/plugin.py index 7680734ddd..13241a44f1 100644 --- a/tensorboard/examples/plugins/example_basic/tensorboard_plugin_example/plugin.py +++ b/tensorboard/examples/plugins/example_basic/tensorboard_plugin_example/plugin.py @@ -82,7 +82,7 @@ def _serve_tags(self, request): for tag in tag_to_content: summary_metadata = self._multiplexer.SummaryMetadata(run, tag) result[run][tag] = { - u"description": summary_metadata.summary_description, + "description": summary_metadata.summary_description, } contents = json.dumps(result, sort_keys=True) return werkzeug.Response(contents, content_type="application/json") diff --git a/tensorboard/plugin_util.py b/tensorboard/plugin_util.py index d51dafcd37..15a2e14eda 100644 --- a/tensorboard/plugin_util.py +++ b/tensorboard/plugin_util.py @@ -133,7 +133,7 @@ def markdowns_to_safe_html(markdown_strings, combine): source_decoded = source.decode("utf-8") # Remove null bytes and warn if there were any, since it probably means # we were given a bad encoding. - source = source_decoded.replace(u"\x00", u"") + source = source_decoded.replace("\x00", "") total_null_bytes += len(source_decoded) - len(source) unsafe_html = _MARKDOWN_STORE.markdown.convert(source) unsafe_htmls.append(unsafe_html) diff --git a/tensorboard/plugin_util_test.py b/tensorboard/plugin_util_test.py index 41aa902f02..80e9d4255d 100644 --- a/tensorboard/plugin_util_test.py +++ b/tensorboard/plugin_util_test.py @@ -32,20 +32,20 @@ def _test(self, markdown_string, expected): self.assertEqual(expected, actual) def test_empty_input(self): - self._test(u"", u"") + self._test("", "") def test_basic_formatting(self): self._test( - u"# _Hello_, **world!**\n\n" + "# _Hello_, **world!**\n\n" "Check out [my website](http://example.com)!", - u"

Hello, world!

\n" + "

Hello, world!

\n" '

Check out my website!

', ) def test_table_formatting(self): self._test( textwrap.dedent( - u"""\ + """\ Here is some data: TensorBoard usage | Happiness @@ -58,7 +58,7 @@ def test_table_formatting(self): """ ), textwrap.dedent( - u"""\ + """\

Here is some data:

@@ -89,39 +89,39 @@ def test_table_formatting(self): def test_whitelisted_tags_and_attributes_allowed(self): s = ( - u'Check out ' + 'Check out ' "my website!" ) - self._test(s, u"

%s

" % s) + self._test(s, "

%s

" % s) def test_arbitrary_tags_and_attributes_removed(self): self._test( - u"We should bring back the blink tag; " + "We should bring back the blink tag; " '' "sign the petition!", - u"

We should bring back the " + "

We should bring back the " "<blink>blink tag</blink>; " 'sign the petition!

', ) def test_javascript_hrefs_sanitized(self): self._test( - u'A sketchy link for you', - u"

A sketchy link for you

", + 'A sketchy link for you', + "

A sketchy link for you

", ) def test_byte_strings_interpreted_as_utf8(self): - s = u"> Look\u2014some UTF-8!".encode("utf-8") + s = "> Look\u2014some UTF-8!".encode("utf-8") assert isinstance(s, six.binary_type), (type(s), six.binary_type) self._test( - s, u"
\n

Look\u2014some UTF-8!

\n
" + s, "
\n

Look\u2014some UTF-8!

\n
" ) def test_unicode_strings_passed_through(self): - s = u"> Look\u2014some UTF-8!" + s = "> Look\u2014some UTF-8!" assert not isinstance(s, six.binary_type), (type(s), six.binary_type) self._test( - s, u"
\n

Look\u2014some UTF-8!

\n
" + s, "
\n

Look\u2014some UTF-8!

\n
" ) def test_null_bytes_stripped_before_markdown_processing(self): @@ -131,11 +131,11 @@ def test_null_bytes_stripped_before_markdown_processing(self): # interpretation to avoid affecting output (e.g. middle-word underscores # would generate erroneous tags like "underscore") and add an # HTML comment with a warning. - s = u"un_der_score".encode("utf-32-le") + s = "un_der_score".encode("utf-32-le") # UTF-32 encoding of ASCII will have 3 null bytes per char. 36 = 3 * 12. self._test( s, - u"\n" "

un_der_score

", ) diff --git a/tensorboard/plugins/base_plugin.py b/tensorboard/plugins/base_plugin.py index 5c5e20991b..e9a4f22ba5 100644 --- a/tensorboard/plugins/base_plugin.py +++ b/tensorboard/plugins/base_plugin.py @@ -122,7 +122,7 @@ def __init__( es_module_path=None, remove_dom=None, tab_name=None, - is_ng_component=None + is_ng_component=None, ): """Creates a `FrontendMetadata` value. @@ -254,7 +254,7 @@ def __init__( multiplexer=None, plugin_name_to_instance=None, sampling_hints=None, - window_title=None + window_title=None, ): """Instantiates magic container. diff --git a/tensorboard/plugins/debugger_v2/debug_data_provider.py b/tensorboard/plugins/debugger_v2/debug_data_provider.py index 73649afb99..4974db709e 100644 --- a/tensorboard/plugins/debugger_v2/debug_data_provider.py +++ b/tensorboard/plugins/debugger_v2/debug_data_provider.py @@ -515,7 +515,7 @@ def read_scalars( experiment_id, plugin_name, downsample=None, - run_tag_filter=None + run_tag_filter=None, ): del experiment_id, plugin_name, downsample, run_tag_filter raise TypeError("Debugger V2 DataProvider doesn't support scalars.") @@ -534,7 +534,7 @@ def read_blob_sequences( experiment_id, plugin_name, downsample=None, - run_tag_filter=None + run_tag_filter=None, ): del experiment_id, downsample # Unused. if plugin_name != PLUGIN_NAME: diff --git a/tensorboard/plugins/graph/graphs_plugin_test.py b/tensorboard/plugins/graph/graphs_plugin_test.py index 26b5fff930..ed5adc1f04 100644 --- a/tensorboard/plugins/graph/graphs_plugin_test.py +++ b/tensorboard/plugins/graph/graphs_plugin_test.py @@ -191,7 +191,7 @@ def _get_graph(self, plugin, *args, **kwargs): context.RequestContext(), _RUN_WITH_GRAPH_WITH_METADATA[0], *args, - **kwargs + **kwargs, ) self.assertEqual(mime_type, "text/x-protobuf") return text_format.Parse(graph_pbtxt, tf.compat.v1.GraphDef()) diff --git a/tensorboard/plugins/hparams/hparams_minimal_demo.py b/tensorboard/plugins/hparams/hparams_minimal_demo.py index 6fc8e640ba..652058850c 100644 --- a/tensorboard/plugins/hparams/hparams_minimal_demo.py +++ b/tensorboard/plugins/hparams/hparams_minimal_demo.py @@ -270,9 +270,9 @@ def run_all(logdir, verbose=False): for ambient_temperature in TEMPERATURE_LIST: for material in HEAT_COEFFICIENTS: hparams = { - u"initial_temperature": initial_temperature, - u"ambient_temperature": ambient_temperature, - u"material": material, + "initial_temperature": initial_temperature, + "ambient_temperature": ambient_temperature, + "material": material, } hparam_str = str(hparams) group_name = fingerprint(hparam_str) diff --git a/tensorboard/plugins/image/images_demo.py b/tensorboard/plugins/image/images_demo.py index 8f32f9cd03..6d93f394a8 100644 --- a/tensorboard/plugins/image/images_demo.py +++ b/tensorboard/plugins/image/images_demo.py @@ -264,10 +264,10 @@ def run_sobel(logdir, verbose=False): tf.stack([output_image]), display_name="Sobel edge detection", description=( - u"Demonstration of [Sobel edge detection]. The step " + "Demonstration of [Sobel edge detection]. The step " "parameter adjusts the radius of the kernel. " "The kernel can be of arbitrary size, and considers " - u"nearby pixels with \u2113\u2082-linear falloff.\n\n" + "nearby pixels with \u2113\u2082-linear falloff.\n\n" # (that says ``$\ell_2$-linear falloff'') "Edge detection is done on a per-channel basis, so " "you can observe which edges are “mostly red " diff --git a/tensorboard/plugins/text/summary_test.py b/tensorboard/plugins/text/summary_test.py index ee9d5d4eb4..a440cf487a 100644 --- a/tensorboard/plugins/text/summary_test.py +++ b/tensorboard/plugins/text/summary_test.py @@ -81,7 +81,7 @@ def test_bytes_value(self): self.assertEqual(b"A name\xe2\x80\xa6I call myself", value) def test_unicode_value(self): - pb = self.text("mi", u"A name\u2026I call myself") + pb = self.text("mi", "A name\u2026I call myself") value = tensor_util.make_ndarray(pb.value[0].tensor).item() self.assertIsInstance(value, six.binary_type) self.assertEqual(b"A name\xe2\x80\xa6I call myself", value) @@ -106,9 +106,7 @@ def test_np_array_bytes_value(self): def test_np_array_unicode_value(self): pb = self.text( "fa", - np.array( - [[u"A", u"long", u"long"], [u"way", u"to", u"run \u203C"]] - ), + np.array([["A", "long", "long"], ["way", "to", "run \u203C"]]), ) values = tensor_util.make_ndarray(pb.value[0].tensor).tolist() self.assertEqual( diff --git a/tensorboard/plugins/text/text_demo.py b/tensorboard/plugins/text/text_demo.py index 463ad8bd99..d69a1ca59f 100644 --- a/tensorboard/plugins/text/text_demo.py +++ b/tensorboard/plugins/text/text_demo.py @@ -96,7 +96,7 @@ def higher_order_tensors(step): bold_numbers = tf.strings.join(["**", tf.as_string(numbers), "**"]) bold_row = tf.expand_dims(bold_numbers, 0) bold_column = tf.expand_dims(bold_numbers, 1) - corner_cell = tf.constant(u"\u00d7".encode("utf-8")) # MULTIPLICATION SIGN + corner_cell = tf.constant("\u00d7".encode("utf-8")) # MULTIPLICATION SIGN # Now, we have to put the pieces together. Using `axis=0` stacks # vertically; using `axis=1` juxtaposes horizontally. diff --git a/tensorboard/tools/diagnose_tensorboard.py b/tensorboard/tools/diagnose_tensorboard.py index 724b56cee5..733a1e2ffc 100644 --- a/tensorboard/tools/diagnose_tensorboard.py +++ b/tensorboard/tools/diagnose_tensorboard.py @@ -178,28 +178,28 @@ def package_management(): @check def installed_packages(): freeze = pip(["freeze", "--all"]).decode("utf-8").splitlines() - packages = {line.split(u"==")[0]: line for line in freeze} + packages = {line.split("==")[0]: line for line in freeze} packages_set = frozenset(packages) # For each of the following families, expect exactly one package to be # installed. expect_unique = [ - frozenset([u"tensorboard", u"tb-nightly", u"tensorflow-tensorboard",]), + frozenset(["tensorboard", "tb-nightly", "tensorflow-tensorboard",]), frozenset( [ - u"tensorflow", - u"tensorflow-gpu", - u"tf-nightly", - u"tf-nightly-2.0-preview", - u"tf-nightly-gpu", - u"tf-nightly-gpu-2.0-preview", + "tensorflow", + "tensorflow-gpu", + "tf-nightly", + "tf-nightly-2.0-preview", + "tf-nightly-gpu", + "tf-nightly-gpu-2.0-preview", ] ), frozenset( [ - u"tensorflow-estimator", - u"tensorflow-estimator-2.0-preview", - u"tf-estimator-nightly", + "tensorflow-estimator", + "tensorflow-estimator-2.0-preview", + "tf-estimator-nightly", ] ), ] diff --git a/tensorboard/uploader/auth.py b/tensorboard/uploader/auth.py index 1a1210c7a5..481a27bc3a 100644 --- a/tensorboard/uploader/auth.py +++ b/tensorboard/uploader/auth.py @@ -48,7 +48,7 @@ # The client "secret" is public by design for installed apps. See # https://developers.google.com/identity/protocols/OAuth2?csw=1#installed -OAUTH_CLIENT_CONFIG = u""" +OAUTH_CLIENT_CONFIG = """ { "installed": { "client_id": "373649185512-8v619h5kft38l4456nm2dj4ubeqsrvh6.apps.googleusercontent.com", diff --git a/tensorboard/uploader/exporter.py b/tensorboard/uploader/exporter.py index 925202d8cb..014f467366 100644 --- a/tensorboard/uploader/exporter.py +++ b/tensorboard/uploader/exporter.py @@ -230,23 +230,23 @@ def _request_json_data(self, experiment_id, read_time): response.tag_metadata.SerializeToString() ).decode("ascii") json_data = { - u"run": response.run_name, - u"tag": response.tag_name, - u"summary_metadata": metadata, + "run": response.run_name, + "tag": response.tag_name, + "summary_metadata": metadata, } filename = None if response.HasField("points"): - json_data[u"points"] = self._process_scalar_points( + json_data["points"] = self._process_scalar_points( response.points ) filename = _FILENAME_SCALARS elif response.HasField("tensors"): - json_data[u"points"] = self._process_tensor_points( + json_data["points"] = self._process_tensor_points( response.tensors, experiment_id ) filename = _FILENAME_TENSORS elif response.HasField("blob_sequences"): - json_data[u"points"] = self._process_blob_sequence_points( + json_data["points"] = self._process_blob_sequence_points( response.blob_sequences, experiment_id ) filename = _FILENAME_BLOB_SEQUENCES @@ -266,9 +266,9 @@ def _process_scalar_points(self, points): """ wall_times = [t.ToNanoseconds() / 1e9 for t in points.wall_times] return { - u"steps": list(points.steps), - u"wall_times": wall_times, - u"values": list(points.values), + "steps": list(points.steps), + "wall_times": wall_times, + "values": list(points.values), } def _process_tensor_points(self, points, experiment_id): @@ -286,9 +286,9 @@ def _process_tensor_points(self, points, experiment_id): """ wall_times = [t.ToNanoseconds() / 1e9 for t in points.wall_times] json_object = { - u"steps": list(points.steps), - u"wall_times": wall_times, - u"tensors_file_path": None, + "steps": list(points.steps), + "wall_times": wall_times, + "tensors_file_path": None, } if not json_object["steps"]: return json_object @@ -367,11 +367,11 @@ def _process_blob_sequence_points(self, blob_sequences, experiment_id): t.ToNanoseconds() / 1e9 for t in blob_sequences.wall_times ] json_object = { - u"steps": list(blob_sequences.steps), - u"wall_times": wall_times, - u"blob_file_paths": [], + "steps": list(blob_sequences.steps), + "wall_times": wall_times, + "blob_file_paths": [], } - blob_file_paths = json_object[u"blob_file_paths"] + blob_file_paths = json_object["blob_file_paths"] for blobseq in blob_sequences.values: seq_blob_file_paths = [] for entry in blobseq.entries: diff --git a/tensorboard/uploader/exporter_test.py b/tensorboard/uploader/exporter_test.py index ea43f88946..e8a8b49135 100644 --- a/tensorboard/uploader/exporter_test.py +++ b/tensorboard/uploader/exporter_test.py @@ -702,7 +702,7 @@ def stream_experiments(request, **kwargs): msg = str(cm.exception) self.assertIn("Unexpected characters", msg) - self.assertIn(repr(sorted([u".", u"/"])), msg) + self.assertIn(repr(sorted([".", "/"])), msg) self.assertIn("../authorized_keys", msg) mock_api_client.StreamExperimentData.assert_not_called() diff --git a/tensorboard/uploader/uploader_subcommand.py b/tensorboard/uploader/uploader_subcommand.py index ca5da7958d..02179f6bfc 100644 --- a/tensorboard/uploader/uploader_subcommand.py +++ b/tensorboard/uploader/uploader_subcommand.py @@ -43,7 +43,7 @@ from tensorboard.plugins import base_plugin -_MESSAGE_TOS = u"""\ +_MESSAGE_TOS = """\ Your use of this service is subject to Google's Terms of Service and Privacy Policy , and TensorBoard.dev's Terms of Service @@ -193,7 +193,7 @@ class _DeleteExperimentIntent(_Intent): """The user intends to delete an experiment.""" _MESSAGE_TEMPLATE = textwrap.dedent( - u"""\ + """\ This will delete the experiment on https://tensorboard.dev with the following experiment ID: @@ -241,7 +241,7 @@ class _UpdateMetadataIntent(_Intent): """The user intends to update the metadata for an experiment.""" _MESSAGE_TEMPLATE = textwrap.dedent( - u"""\ + """\ This will modify the metadata associated with the experiment on https://tensorboard.dev with the following experiment ID: @@ -304,7 +304,7 @@ class _ListIntent(_Intent): """The user intends to list all their experiments.""" _MESSAGE = textwrap.dedent( - u"""\ + """\ This will list all experiments that you've uploaded to https://tensorboard.dev. TensorBoard.dev experiments are visible to everyone. Do not upload sensitive data. @@ -380,7 +380,7 @@ class UploadIntent(_Intent): """The user intends to upload an experiment from the given logdir.""" _MESSAGE_TEMPLATE = textwrap.dedent( - u"""\ + """\ This will upload your TensorBoard logs to https://tensorboard.dev/ from the following directory: @@ -492,7 +492,7 @@ class _ExportIntent(_Intent): """The user intends to download all their experiment data.""" _MESSAGE_TEMPLATE = textwrap.dedent( - u"""\ + """\ This will download all your experiment data from https://tensorboard.dev and save it to the following directory: From f896d86d42b1ac08b443ddc6071d862360290f3b Mon Sep 17 00:00:00 2001 From: TensorBoard Gardener Date: Mon, 30 Nov 2020 18:48:07 -0800 Subject: [PATCH 3/4] black: reformat after upgrading to Black v20.8b1 Summary: This is a clean run of Black v20.8b1. See #4406. wchargin-branch: black-20x-no27-no35 --- tensorboard/backend/application.py | 5 +- tensorboard/backend/application_test.py | 32 +++- .../backend/event_processing/data_provider.py | 11 +- .../event_processing/data_provider_test.py | 3 +- .../event_accumulator_test.py | 19 ++- .../event_file_loader_test.py | 6 +- .../event_multiplexer_test.py | 5 +- .../event_processing/io_wrapper_test.py | 149 +++++++++++++++--- .../plugin_event_accumulator_test.py | 45 +++++- .../plugin_event_multiplexer_test.py | 5 +- tensorboard/backend/http_util.py | 7 +- tensorboard/backend/json_util_test.py | 7 +- .../backend/security_validator_test.py | 7 +- .../tensorflow_stub/io/gfile_s3_test.py | 64 ++++++-- .../compat/tensorflow_stub/io/gfile_test.py | 64 ++++++-- .../tensorflow_stub/pywrap_tensorflow.py | 4 +- tensorboard/data/dispatching_provider.py | 3 +- tensorboard/data/dispatching_provider_test.py | 3 +- .../experimental/experiment_from_dev_test.py | 4 +- tensorboard/data/grpc_provider.py | 8 +- tensorboard/data/provider.py | 5 +- .../examples/plugins/example_basic/setup.py | 4 +- .../tensorboard_plugin_example/demo.py | 5 +- .../tensorboard_plugin_example/summary_v2.py | 4 +- .../plugins/example_raw_scalars/setup.py | 4 +- tensorboard/manager.py | 14 +- tensorboard/manager_e2e_test.py | 10 +- tensorboard/manager_test.py | 3 +- tensorboard/notebook.py | 7 +- .../pip_package/deterministic_tar_gz_test.py | 3 +- tensorboard/pip_package/setup.py | 4 +- tensorboard/plugins/audio/audio_plugin.py | 8 +- .../plugins/audio/audio_plugin_test.py | 5 +- tensorboard/plugins/core/core_plugin.py | 6 +- tensorboard/plugins/core/core_plugin_test.py | 3 +- .../custom_scalars_plugin_test.py | 4 +- .../debugger_v2/debug_data_provider.py | 33 ++-- .../plugins/debugger_v2/debugger_v2_plugin.py | 17 +- .../debugger_v2/debugger_v2_plugin_test.py | 19 ++- .../plugins/distribution/compressor_test.py | 12 +- tensorboard/plugins/graph/graph_util.py | 13 +- tensorboard/plugins/graph/graph_util_test.py | 3 +- tensorboard/plugins/graph/graphs_plugin.py | 4 +- .../plugins/graph/graphs_plugin_test.py | 5 +- tensorboard/plugins/graph/keras_util_test.py | 9 +- .../plugins/histogram/histograms_plugin.py | 4 +- .../plugins/hparams/backend_context_test.py | 44 ++++-- tensorboard/plugins/hparams/hparams_demo.py | 24 ++- tensorboard/plugins/hparams/keras_test.py | 6 +- .../hparams/list_session_groups_test.py | 10 +- tensorboard/plugins/hparams/summary.py | 4 +- tensorboard/plugins/hparams/summary_v2.py | 16 +- .../plugins/hparams/summary_v2_test.py | 6 +- tensorboard/plugins/image/images_plugin.py | 11 +- .../plugins/image/images_plugin_test.py | 5 +- tensorboard/plugins/mesh/mesh_plugin_test.py | 4 +- .../plugins/metrics/metrics_plugin_test.py | 10 +- .../plugins/npmi/csv_to_plugin_data_demo.py | 4 +- tensorboard/plugins/npmi/metadata.py | 3 +- tensorboard/plugins/npmi/npmi_plugin.py | 5 +- tensorboard/plugins/npmi/npmi_plugin_test.py | 6 +- .../npmi/npy_to_embedding_data_demo.py | 4 +- tensorboard/plugins/npmi/summary.py | 16 +- .../plugins/pr_curve/pr_curves_plugin.py | 3 +- .../profile_redirect_plugin.py | 3 +- .../plugins/projector/projector_api_test.py | 3 +- .../plugins/projector/projector_plugin.py | 6 +- tensorboard/plugins/scalar/scalars_plugin.py | 4 +- .../plugins/scalar/scalars_plugin_test.py | 23 ++- tensorboard/plugins/text/text_plugin.py | 4 +- tensorboard/plugins/text_v2/text_v2_plugin.py | 4 +- .../plugins/text_v2/text_v2_plugin_test.py | 4 +- tensorboard/scripts/generate_testdata.py | 4 +- tensorboard/summary/summary_test.py | 20 ++- tensorboard/tools/diagnose_tensorboard.py | 14 +- tensorboard/uploader/auth.py | 6 +- tensorboard/uploader/exporter.py | 7 +- tensorboard/uploader/exporter_test.py | 8 +- tensorboard/uploader/formatters.py | 9 +- tensorboard/uploader/upload_tracker_test.py | 15 +- tensorboard/uploader/uploader.py | 85 +++++----- .../uploader/uploader_subcommand_test.py | 25 ++- tensorboard/uploader/uploader_test.py | 25 ++- tensorboard/uploader/util_test.py | 6 +- tensorboard/util/timing.py | 6 +- 85 files changed, 860 insertions(+), 261 deletions(-) diff --git a/tensorboard/backend/application.py b/tensorboard/backend/application.py index ba8e5e888a..da4f9fc230 100644 --- a/tensorboard/backend/application.py +++ b/tensorboard/backend/application.py @@ -390,7 +390,10 @@ def _serve_plugin_entry(self, request): """ ).format(name=name, script_content=script_content) return http_util.Respond( - request, html, "text/html", csp_scripts_sha256s=[script_sha], + request, + html, + "text/html", + csp_scripts_sha256s=[script_sha], ) @wrappers.Request.application diff --git a/tensorboard/backend/application_test.py b/tensorboard/backend/application_test.py index 2b2500ecdc..92d445a331 100644 --- a/tensorboard/backend/application_test.py +++ b/tensorboard/backend/application_test.py @@ -190,7 +190,8 @@ def app(request): server = werkzeug_test.Client(app, wrappers.BaseResponse) response = server.get("/") self.assertEqual( - response.get_data(), b"Unauthenticated: who are you?", + response.get_data(), + b"Unauthenticated: who are you?", ) self.assertEqual(response.status_code, 401) self.assertStartsWith( @@ -224,11 +225,15 @@ def setUp(self): ), FakePlugin( plugin_name="baz", - routes_mapping={"/esmodule": lambda req: None,}, + routes_mapping={ + "/esmodule": lambda req: None, + }, es_module_path_value="/esmodule", ), FakePlugin( - plugin_name="qux", is_active_value=False, is_ng_component=True, + plugin_name="qux", + is_active_value=False, + is_ng_component=True, ), ] app = application.TensorBoardWSGI(plugins) @@ -289,7 +294,9 @@ def testPluginsListing(self): }, "qux": { "enabled": False, - "loading_mechanism": {"type": "NG_COMPONENT",}, + "loading_mechanism": { + "type": "NG_COMPONENT", + }, "tab_name": "qux", "remove_dom": False, "disable_reload": False, @@ -305,7 +312,9 @@ def testPluginsListingWithDataProviderListActivePlugins(self): plugins = [ FakePlugin(plugin_name="foo", is_active_value=False), FakePlugin( - plugin_name="bar", is_active_value=False, data_plugin_names=(), + plugin_name="bar", + is_active_value=False, + data_plugin_names=(), ), FakePlugin(plugin_name="baz", is_active_value=False), FakePlugin( @@ -495,7 +504,9 @@ def setUp(self): ), FakePlugin( plugin_name="baz", - routes_mapping={"/esmodule": lambda req: None,}, + routes_mapping={ + "/esmodule": lambda req: None, + }, es_module_path_value="/esmodule", ), ] @@ -695,7 +706,9 @@ def setUp(self): ), FakePluginLoader( plugin_name="whoami", - routes_mapping={"/eid": self._eid_handler,}, + routes_mapping={ + "/eid": self._eid_handler, + }, ), ], data_provider=FakeDataProvider(), @@ -761,7 +774,10 @@ def _wildcard_special_handler(self, request): def testPluginsAdded(self): # The routes are prefixed with /data/plugin/[plugin name]. expected_routes = frozenset( - ("/data/plugin/foo/foo_route", "/data/plugin/bar/bar_route",) + ( + "/data/plugin/foo/foo_route", + "/data/plugin/bar/bar_route", + ) ) self.assertLessEqual(expected_routes, frozenset(self.app.exact_routes)) diff --git a/tensorboard/backend/event_processing/data_provider.py b/tensorboard/backend/event_processing/data_provider.py index 1a33441da1..c046a28c3e 100644 --- a/tensorboard/backend/event_processing/data_provider.py +++ b/tensorboard/backend/event_processing/data_provider.py @@ -445,13 +445,20 @@ def _convert_blob_sequence_event(experiment_id, plugin_name, run, tag, event): values = tuple( provider.BlobReference( _encode_blob_key( - experiment_id, plugin_name, run, tag, event.step, idx, + experiment_id, + plugin_name, + run, + tag, + event.step, + idx, ) ) for idx in range(num_blobs) ) return provider.BlobSequenceDatum( - wall_time=event.wall_time, step=event.step, values=values, + wall_time=event.wall_time, + step=event.step, + values=values, ) diff --git a/tensorboard/backend/event_processing/data_provider_test.py b/tensorboard/backend/event_processing/data_provider_test.py index 8e89faee6f..b9270600c4 100644 --- a/tensorboard/backend/event_processing/data_provider_test.py +++ b/tensorboard/backend/event_processing/data_provider_test.py @@ -377,7 +377,8 @@ def test_read_tensors(self): ) run_tag_filter = base_provider.RunTagFilter( - runs=["lebesgue"], tags=["uniform", "bimodal"], + runs=["lebesgue"], + tags=["uniform", "bimodal"], ) result = provider.read_tensors( self.ctx, diff --git a/tensorboard/backend/event_processing/event_accumulator_test.py b/tensorboard/backend/event_processing/event_accumulator_test.py index d30cfb6e45..38e4fb0865 100644 --- a/tensorboard/backend/event_processing/event_accumulator_test.py +++ b/tensorboard/backend/event_processing/event_accumulator_test.py @@ -795,7 +795,11 @@ def testTFSummaryImage(self): self.assertTagsEqual( accumulator.Tags(), - {ea.IMAGES: tags, ea.GRAPH: True, ea.META_GRAPH: False,}, + { + ea.IMAGES: tags, + ea.GRAPH: True, + ea.META_GRAPH: False, + }, ) def testTFSummaryTensor(self): @@ -819,7 +823,10 @@ def testTFSummaryTensor(self): accumulator.Reload() self.assertTagsEqual( - accumulator.Tags(), {ea.TENSORS: ["scalar", "vector", "string"],} + accumulator.Tags(), + { + ea.TENSORS: ["scalar", "vector", "string"], + }, ) scalar_proto = accumulator.Tensors("scalar")[0].tensor_proto @@ -949,7 +956,13 @@ def testGraphFromMetaGraphBecomesAvailable(self): # Verify that we can load those events properly acc = ea.EventAccumulator(directory) acc.Reload() - self.assertTagsEqual(acc.Tags(), {ea.GRAPH: True, ea.META_GRAPH: True,}) + self.assertTagsEqual( + acc.Tags(), + { + ea.GRAPH: True, + ea.META_GRAPH: True, + }, + ) expected_graph_def = graph_pb2.GraphDef.FromString( graph.as_graph_def(add_shapes=True).SerializeToString() diff --git a/tensorboard/backend/event_processing/event_file_loader_test.py b/tensorboard/backend/event_processing/event_file_loader_test.py index d969ecb8a4..1eac652deb 100644 --- a/tensorboard/backend/event_processing/event_file_loader_test.py +++ b/tensorboard/backend/event_processing/event_file_loader_test.py @@ -139,10 +139,12 @@ def assertEventWallTimes(self, load_result, event_wall_times_in_order): transposed = list(zip(*load_result)) wall_times, events = transposed if transposed else ([], []) self.assertEqual( - list(wall_times), event_wall_times_in_order, + list(wall_times), + event_wall_times_in_order, ) self.assertEqual( - [event.wall_time for event in events], event_wall_times_in_order, + [event.wall_time for event in events], + event_wall_times_in_order, ) diff --git a/tensorboard/backend/event_processing/event_multiplexer_test.py b/tensorboard/backend/event_processing/event_multiplexer_test.py index 7c24c7eb52..5c79ac9252 100644 --- a/tensorboard/backend/event_processing/event_multiplexer_test.py +++ b/tensorboard/backend/event_processing/event_multiplexer_test.py @@ -52,7 +52,10 @@ def __init__(self, path): self._path = path self.reload_called = False self._plugin_to_tag_to_content = { - "baz_plugin": {"foo": "foo_content", "bar": "bar_content",} + "baz_plugin": { + "foo": "foo_content", + "bar": "bar_content", + } } def Tags(self): diff --git a/tensorboard/backend/event_processing/io_wrapper_test.py b/tensorboard/backend/event_processing/io_wrapper_test.py index e9ac2faff2..d3e6aa1289 100644 --- a/tensorboard/backend/event_processing/io_wrapper_test.py +++ b/tensorboard/backend/event_processing/io_wrapper_test.py @@ -123,20 +123,72 @@ def testListRecursivelyViaGlobbing(self): expected = [ [ "", - ["foo", "bar", "a.tfevents.1", "model.ckpt", "quuz", "waldo",], + [ + "foo", + "bar", + "a.tfevents.1", + "model.ckpt", + "quuz", + "waldo", + ], + ], + [ + "bar", + [ + "b.tfevents.1", + "red_herring.txt", + "baz", + "quux", + ], + ], + [ + "bar/baz", + [ + "c.tfevents.1", + "d.tfevents.1", + ], ], - ["bar", ["b.tfevents.1", "red_herring.txt", "baz", "quux",]], - ["bar/baz", ["c.tfevents.1", "d.tfevents.1",]], [ "bar/quux", - ["some_flume_output.txt", "some_more_flume_output.txt",], + [ + "some_flume_output.txt", + "some_more_flume_output.txt", + ], + ], + [ + "quuz", + [ + "e.tfevents.1", + "garply", + ], + ], + [ + "quuz/garply", + [ + "f.tfevents.1", + "corge", + "grault", + ], ], - ["quuz", ["e.tfevents.1", "garply",]], - ["quuz/garply", ["f.tfevents.1", "corge", "grault",]], ["quuz/garply/corge", ["g.tfevents.1"]], - ["quuz/garply/grault", ["h.tfevents.1",]], - ["waldo", ["fred",]], - ["waldo/fred", ["i.tfevents.1",]], + [ + "quuz/garply/grault", + [ + "h.tfevents.1", + ], + ], + [ + "waldo", + [ + "fred", + ], + ], + [ + "waldo/fred", + [ + "i.tfevents.1", + ], + ], ] for pair in expected: # If this is not the top-level directory, prepend the high-level @@ -169,8 +221,19 @@ def skipTestListRecursivelyViaGlobbingForPathWithGlobCharacters(self): open(os.path.join(temp_dir, file_name), "w").close() expected = [ - ["", ["a.tfevents.1", "subdirectory",]], - ["subdirectory", ["b.tfevents.1",]], + [ + "", + [ + "a.tfevents.1", + "subdirectory", + ], + ], + [ + "subdirectory", + [ + "b.tfevents.1", + ], + ], # The contents of the bar subdirectory should be excluded from # this listing because the * character should have been escaped. ] @@ -188,20 +251,66 @@ def testListRecursivelyViaWalking(self): temp_dir = tempfile.mkdtemp(prefix=self.get_temp_dir()) self._CreateDeepDirectoryStructure(temp_dir) expected = [ - ["", ["a.tfevents.1", "model.ckpt",]], + [ + "", + [ + "a.tfevents.1", + "model.ckpt", + ], + ], ["foo", []], - ["bar", ["b.tfevents.1", "red_herring.txt",]], - ["bar/baz", ["c.tfevents.1", "d.tfevents.1",]], + [ + "bar", + [ + "b.tfevents.1", + "red_herring.txt", + ], + ], + [ + "bar/baz", + [ + "c.tfevents.1", + "d.tfevents.1", + ], + ], [ "bar/quux", - ["some_flume_output.txt", "some_more_flume_output.txt",], + [ + "some_flume_output.txt", + "some_more_flume_output.txt", + ], + ], + [ + "quuz", + [ + "e.tfevents.1", + ], + ], + [ + "quuz/garply", + [ + "f.tfevents.1", + ], + ], + [ + "quuz/garply/corge", + [ + "g.tfevents.1", + ], + ], + [ + "quuz/garply/grault", + [ + "h.tfevents.1", + ], ], - ["quuz", ["e.tfevents.1",]], - ["quuz/garply", ["f.tfevents.1",]], - ["quuz/garply/corge", ["g.tfevents.1",]], - ["quuz/garply/grault", ["h.tfevents.1",]], ["waldo", []], - ["waldo/fred", ["i.tfevents.1",]], + [ + "waldo/fred", + [ + "i.tfevents.1", + ], + ], ] for pair in expected: # If this is not the top-level directory, prepend the high-level diff --git a/tensorboard/backend/event_processing/plugin_event_accumulator_test.py b/tensorboard/backend/event_processing/plugin_event_accumulator_test.py index 98ac612228..f67df572d5 100644 --- a/tensorboard/backend/event_processing/plugin_event_accumulator_test.py +++ b/tensorboard/backend/event_processing/plugin_event_accumulator_test.py @@ -172,7 +172,12 @@ def testReload(self): gen.AddScalarTensor("s1", wall_time=1, step=10, value=50) gen.AddScalarTensor("s2", wall_time=1, step=10, value=80) acc.Reload() - self.assertTagsEqual(acc.Tags(), {ea.TENSORS: ["s1", "s2"],}) + self.assertTagsEqual( + acc.Tags(), + { + ea.TENSORS: ["s1", "s2"], + }, + ) def testKeyError(self): """KeyError should be raised when accessing non-existing keys.""" @@ -193,7 +198,12 @@ def testNonValueEvents(self): gen.AddScalarTensor("s3", wall_time=3, step=100, value=1) acc.Reload() - self.assertTagsEqual(acc.Tags(), {ea.TENSORS: ["s1", "s3"],}) + self.assertTagsEqual( + acc.Tags(), + { + ea.TENSORS: ["s1", "s3"], + }, + ) def testExpiredDataDiscardedAfterRestartForFileVersionLessThan2(self): """Tests that events are discarded after a restart is detected. @@ -406,7 +416,11 @@ def testNewStyleScalarSummary(self): ] self.assertTagsEqual( accumulator.Tags(), - {ea.TENSORS: tags, ea.GRAPH: True, ea.META_GRAPH: False,}, + { + ea.TENSORS: tags, + ea.GRAPH: True, + ea.META_GRAPH: False, + }, ) self.assertItemsEqual( @@ -451,7 +465,11 @@ def testNewStyleAudioSummary(self): ] self.assertTagsEqual( accumulator.Tags(), - {ea.TENSORS: tags, ea.GRAPH: True, ea.META_GRAPH: False,}, + { + ea.TENSORS: tags, + ea.GRAPH: True, + ea.META_GRAPH: False, + }, ) self.assertItemsEqual( @@ -494,7 +512,11 @@ def testNewStyleImageSummary(self): ] self.assertTagsEqual( accumulator.Tags(), - {ea.TENSORS: tags, ea.GRAPH: True, ea.META_GRAPH: False,}, + { + ea.TENSORS: tags, + ea.GRAPH: True, + ea.META_GRAPH: False, + }, ) self.assertItemsEqual( @@ -521,7 +543,10 @@ def testTFSummaryTensor(self): accumulator.Reload() self.assertTagsEqual( - accumulator.Tags(), {ea.TENSORS: ["scalar", "vector", "string"],} + accumulator.Tags(), + { + ea.TENSORS: ["scalar", "vector", "string"], + }, ) scalar_proto = accumulator.Tensors("scalar")[0].tensor_proto @@ -742,7 +767,13 @@ def testGraphFromMetaGraphBecomesAvailable(self): # Verify that we can load those events properly acc = ea.EventAccumulator(directory) acc.Reload() - self.assertTagsEqual(acc.Tags(), {ea.GRAPH: True, ea.META_GRAPH: True,}) + self.assertTagsEqual( + acc.Tags(), + { + ea.GRAPH: True, + ea.META_GRAPH: True, + }, + ) expected_graph_def = graph_pb2.GraphDef.FromString( graph.as_graph_def(add_shapes=True).SerializeToString() diff --git a/tensorboard/backend/event_processing/plugin_event_multiplexer_test.py b/tensorboard/backend/event_processing/plugin_event_multiplexer_test.py index e6bd4953d6..6259286e83 100644 --- a/tensorboard/backend/event_processing/plugin_event_multiplexer_test.py +++ b/tensorboard/backend/event_processing/plugin_event_multiplexer_test.py @@ -57,7 +57,10 @@ def __init__(self, path): self._path = path self.reload_called = False self._plugin_to_tag_to_content = { - "baz_plugin": {"foo": "foo_content", "bar": "bar_content",} + "baz_plugin": { + "foo": "foo_content", + "bar": "bar_content", + } } def Tags(self): diff --git a/tensorboard/backend/http_util.py b/tensorboard/backend/http_util.py index 59ff73f70e..64c446ae1b 100644 --- a/tensorboard/backend/http_util.py +++ b/tensorboard/backend/http_util.py @@ -74,7 +74,12 @@ ] ) -_JSON_MIMETYPES = set(["application/json", "application/json+protobuf",]) +_JSON_MIMETYPES = set( + [ + "application/json", + "application/json+protobuf", + ] +) # Do not support xhtml for now. _HTML_MIMETYPE = "text/html" diff --git a/tensorboard/backend/json_util_test.py b/tensorboard/backend/json_util_test.py index b2e745b30d..32d4529965 100644 --- a/tensorboard/backend/json_util_test.py +++ b/tensorboard/backend/json_util_test.py @@ -47,7 +47,12 @@ def testWrapsObjectKeys(self): def testWrapsInListsAndTuples(self): self._assertWrapsAs([_INFINITY], ["Infinity"]) # map() returns a list even if the argument is a tuple. - self._assertWrapsAs((_INFINITY,), ["Infinity",]) + self._assertWrapsAs( + (_INFINITY,), + [ + "Infinity", + ], + ) def testWrapsRecursively(self): self._assertWrapsAs({"x": [_INFINITY]}, {"x": ["Infinity"]}) diff --git a/tensorboard/backend/security_validator_test.py b/tensorboard/backend/security_validator_test.py index 1bd2b54a7d..e5e6b560e6 100644 --- a/tensorboard/backend/security_validator_test.py +++ b/tensorboard/backend/security_validator_test.py @@ -56,7 +56,9 @@ class SecurityValidatorMiddlewareTest(tb_test.TestCase): """Tests for `SecurityValidatorMiddleware`.""" def make_request_and_maybe_assert_warn( - self, headers, expected_warn_substr, + self, + headers, + expected_warn_substr, ): @werkzeug.Request.application def _simple_app(req): @@ -74,7 +76,8 @@ def _simple_app(req): mock_warn.assert_called_with(_WARN_PREFIX + expected_warn_substr) def make_request_and_assert_no_warn( - self, headers, + self, + headers, ): self.make_request_and_maybe_assert_warn(headers, None) diff --git a/tensorboard/compat/tensorflow_stub/io/gfile_s3_test.py b/tensorboard/compat/tensorflow_stub/io/gfile_s3_test.py index 675f59fa16..31086796ee 100644 --- a/tensorboard/compat/tensorflow_stub/io/gfile_s3_test.py +++ b/tensorboard/compat/tensorflow_stub/io/gfile_s3_test.py @@ -110,21 +110,67 @@ def testWalk(self): temp_dir = self._CreateDeepS3Structure() self._CreateDeepS3Structure(temp_dir) expected = [ - ["", ["a.tfevents.1", "model.ckpt",]], + [ + "", + [ + "a.tfevents.1", + "model.ckpt", + ], + ], # Empty directory not returned # ['foo', []], - ["bar", ["b.tfevents.1", "red_herring.txt",]], - ["bar/baz", ["c.tfevents.1", "d.tfevents.1",]], + [ + "bar", + [ + "b.tfevents.1", + "red_herring.txt", + ], + ], + [ + "bar/baz", + [ + "c.tfevents.1", + "d.tfevents.1", + ], + ], [ "bar/quux", - ["some_flume_output.txt", "some_more_flume_output.txt",], + [ + "some_flume_output.txt", + "some_more_flume_output.txt", + ], + ], + [ + "quuz", + [ + "e.tfevents.1", + ], + ], + [ + "quuz/garply", + [ + "f.tfevents.1", + ], + ], + [ + "quuz/garply/corge", + [ + "g.tfevents.1", + ], + ], + [ + "quuz/garply/grault", + [ + "h.tfevents.1", + ], ], - ["quuz", ["e.tfevents.1",]], - ["quuz/garply", ["f.tfevents.1",]], - ["quuz/garply/corge", ["g.tfevents.1",]], - ["quuz/garply/grault", ["h.tfevents.1",]], ["waldo", []], - ["waldo/fred", ["i.tfevents.1",]], + [ + "waldo/fred", + [ + "i.tfevents.1", + ], + ], ] for pair in expected: # If this is not the top-level directory, prepend the high-level diff --git a/tensorboard/compat/tensorflow_stub/io/gfile_test.py b/tensorboard/compat/tensorflow_stub/io/gfile_test.py index d751861f6b..3ae2f51a77 100644 --- a/tensorboard/compat/tensorflow_stub/io/gfile_test.py +++ b/tensorboard/compat/tensorflow_stub/io/gfile_test.py @@ -90,20 +90,66 @@ def testWalk(self): temp_dir = self.get_temp_dir() self._CreateDeepDirectoryStructure(temp_dir) expected = [ - ["", ["a.tfevents.1", "model.ckpt",]], + [ + "", + [ + "a.tfevents.1", + "model.ckpt", + ], + ], ["foo", []], - ["bar", ["b.tfevents.1", "red_herring.txt",]], - ["bar/baz", ["c.tfevents.1", "d.tfevents.1",]], + [ + "bar", + [ + "b.tfevents.1", + "red_herring.txt", + ], + ], + [ + "bar/baz", + [ + "c.tfevents.1", + "d.tfevents.1", + ], + ], [ "bar/quux", - ["some_flume_output.txt", "some_more_flume_output.txt",], + [ + "some_flume_output.txt", + "some_more_flume_output.txt", + ], + ], + [ + "quuz", + [ + "e.tfevents.1", + ], + ], + [ + "quuz/garply", + [ + "f.tfevents.1", + ], + ], + [ + "quuz/garply/corge", + [ + "g.tfevents.1", + ], + ], + [ + "quuz/garply/grault", + [ + "h.tfevents.1", + ], ], - ["quuz", ["e.tfevents.1",]], - ["quuz/garply", ["f.tfevents.1",]], - ["quuz/garply/corge", ["g.tfevents.1",]], - ["quuz/garply/grault", ["h.tfevents.1",]], ["waldo", []], - ["waldo/fred", ["i.tfevents.1",]], + [ + "waldo/fred", + [ + "i.tfevents.1", + ], + ], ] for pair in expected: # If this is not the top-level directory, prepend the high-level diff --git a/tensorboard/compat/tensorflow_stub/pywrap_tensorflow.py b/tensorboard/compat/tensorflow_stub/pywrap_tensorflow.py index f5fe7d3050..8b743f7dca 100644 --- a/tensorboard/compat/tensorflow_stub/pywrap_tensorflow.py +++ b/tensorboard/compat/tensorflow_stub/pywrap_tensorflow.py @@ -244,7 +244,9 @@ def GetNext(self): crc_event = struct.unpack(" Date: Mon, 30 Nov 2020 18:48:21 -0800 Subject: [PATCH 4/4] ci: re-enable Black enforcement Summary: Previous commits have reformatted at Black v20.8b1 without support for Python 2.7 or 3.5, so we can turn this check back on. See #4406. Test Plan: That CI passes suffices. wchargin-branch: black-20x-no27-no35 --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d156104c75..fe241662aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,8 +65,7 @@ jobs: - run: pip freeze --all - name: 'Lint Python code for style with Black' # You can run `black .` to fix all Black complaints. - # TODO(#4406): Re-enable this check. - run: black --check --diff . || true + run: black --check --diff . lint-rust: runs-on: ubuntu-16.04