Skip to content

Commit ff5d2b4

Browse files
authored
cleanup: fix badly dedented strings (#3049)
Summary: Fixes #3034. These are artifacts of a global indentation change, which didn’t touch strings because that changes the AST. In most cases, such changes to the AST are fine, so we reindent the strings to be consistent with their surroundings. This diff is almost entirely whitespace. Test Plan: The following Python 3.8 script now only surfaces false positives: ```python import ast import glob def main(): for filename in glob.glob("tensorboard/**/*.py", recursive=True): with open(filename) as infile: source = infile.read() sourcelines = source.splitlines() module = ast.parse(source, filename=filename) strings = [x for x in ast.walk(module) if isinstance(x, ast.Str)] for node in strings: base = _indent_of(sourcelines[node.lineno - 1]) if node.lineno == node.end_lineno: # Rule out false positives on single-line strings with # literal "\n" escape sequences. continue lines = node.s.splitlines() if len(lines) <= 1: continue if any(_indent_of(x) < base for x in lines[1:] if x.strip()): print("%s:%d:%s" % (filename, node.lineno, _preview(lines))) def _indent_of(line): n = 0 for c in line: if c != " ": break n += 1 return n def _preview(lines): joined = " ".join(x.strip() for x in lines if x.strip()) ellipsis = "..." maxlen = 40 if len(joined) <= maxlen: return joined else: return joined[: maxlen - len(ellipsis)] + ellipsis if __name__ == "__main__": main() ``` wchargin-branch: cleanup-string-indent
1 parent daaefca commit ff5d2b4

File tree

32 files changed

+2860
-2771
lines changed

32 files changed

+2860
-2771
lines changed

tensorboard/backend/application.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,10 @@ def _serve_plugin_entry(self, request):
431431

432432
html = textwrap.dedent(
433433
"""
434-
<!DOCTYPE html>
435-
<head><base href="plugin/{name}/" /></head>
436-
<body><script type="module">{script_content}</script></body>
437-
"""
434+
<!DOCTYPE html>
435+
<head><base href="plugin/{name}/" /></head>
436+
<body><script type="module">{script_content}</script></body>
437+
"""
438438
).format(name=name, script_content=script_content)
439439
return http_util.Respond(
440440
request, html, "text/html", csp_scripts_sha256s=[script_sha],

tensorboard/backend/event_processing/db_import_multiplexer_test.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,23 @@ def _get_runs(self):
5656
db = self.db_connection_provider()
5757
cursor = db.execute(
5858
"""
59-
SELECT
60-
Runs.run_name
61-
FROM Runs
62-
ORDER BY Runs.run_name
63-
"""
59+
SELECT
60+
Runs.run_name
61+
FROM Runs
62+
ORDER BY Runs.run_name
63+
"""
6464
)
6565
return [row[0] for row in cursor]
6666

6767
def _get_experiments(self):
6868
db = self.db_connection_provider()
6969
cursor = db.execute(
7070
"""
71-
SELECT
72-
Experiments.experiment_name
73-
FROM Experiments
74-
ORDER BY Experiments.experiment_name
75-
"""
71+
SELECT
72+
Experiments.experiment_name
73+
FROM Experiments
74+
ORDER BY Experiments.experiment_name
75+
"""
7676
)
7777
return [row[0] for row in cursor]
7878

tensorboard/backend/event_processing/reservoir.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,36 @@
2727
class Reservoir(object):
2828
"""A map-to-arrays container, with deterministic Reservoir Sampling.
2929
30-
Items are added with an associated key. Items may be retrieved by key, and
31-
a list of keys can also be retrieved. If size is not zero, then it dictates
32-
the maximum number of items that will be stored with each key. Once there are
33-
more items for a given key, they are replaced via reservoir sampling, such
34-
that each item has an equal probability of being included in the sample.
35-
36-
Deterministic means that for any given seed and bucket size, the sequence of
37-
values that are kept for any given tag will always be the same, and that this
38-
is independent of any insertions on other tags. That is:
39-
40-
>>> separate_reservoir = reservoir.Reservoir(10)
41-
>>> interleaved_reservoir = reservoir.Reservoir(10)
42-
>>> for i in xrange(100):
43-
>>> separate_reservoir.AddItem('key1', i)
44-
>>> for i in xrange(100):
45-
>>> separate_reservoir.AddItem('key2', i)
46-
>>> for i in xrange(100):
47-
>>> interleaved_reservoir.AddItem('key1', i)
48-
>>> interleaved_reservoir.AddItem('key2', i)
49-
50-
separate_reservoir and interleaved_reservoir will be in identical states.
51-
52-
See: https://en.wikipedia.org/wiki/Reservoir_sampling
53-
54-
Adding items has amortized O(1) runtime.
55-
56-
Fields:
57-
always_keep_last: Whether the latest seen sample is always at the
58-
end of the reservoir. Defaults to True.
59-
size: An integer of the maximum number of samples.
30+
Items are added with an associated key. Items may be retrieved by key, and
31+
a list of keys can also be retrieved. If size is not zero, then it dictates
32+
the maximum number of items that will be stored with each key. Once there are
33+
more items for a given key, they are replaced via reservoir sampling, such
34+
that each item has an equal probability of being included in the sample.
35+
36+
Deterministic means that for any given seed and bucket size, the sequence of
37+
values that are kept for any given tag will always be the same, and that this
38+
is independent of any insertions on other tags. That is:
39+
40+
>>> separate_reservoir = reservoir.Reservoir(10)
41+
>>> interleaved_reservoir = reservoir.Reservoir(10)
42+
>>> for i in xrange(100):
43+
>>> separate_reservoir.AddItem('key1', i)
44+
>>> for i in xrange(100):
45+
>>> separate_reservoir.AddItem('key2', i)
46+
>>> for i in xrange(100):
47+
>>> interleaved_reservoir.AddItem('key1', i)
48+
>>> interleaved_reservoir.AddItem('key2', i)
49+
50+
separate_reservoir and interleaved_reservoir will be in identical states.
51+
52+
See: https://en.wikipedia.org/wiki/Reservoir_sampling
53+
54+
Adding items has amortized O(1) runtime.
55+
56+
Fields:
57+
always_keep_last: Whether the latest seen sample is always at the
58+
end of the reservoir. Defaults to True.
59+
size: An integer of the maximum number of samples.
6060
"""
6161

6262
def __init__(self, size, seed=0, always_keep_last=True):

tensorboard/backend/event_processing/sqlite_writer.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ def _maybe_init_user(self):
7474
user_id = self._create_id()
7575
cursor.execute(
7676
"""
77-
INSERT INTO USERS (user_id, user_name, inserted_time)
78-
VALUES (?, ?, ?)
79-
""",
77+
INSERT INTO USERS (user_id, user_name, inserted_time)
78+
VALUES (?, ?, ?)
79+
""",
8080
(user_id, user_name, time.time()),
8181
)
8282
return user_id
@@ -91,9 +91,9 @@ def _maybe_init_experiment(self, experiment_name):
9191
cursor = self._db.cursor()
9292
cursor.execute(
9393
"""
94-
SELECT experiment_id FROM Experiments
95-
WHERE user_id = ? AND experiment_name = ?
96-
""",
94+
SELECT experiment_id FROM Experiments
95+
WHERE user_id = ? AND experiment_name = ?
96+
""",
9797
(user_id, experiment_name),
9898
)
9999
row = cursor.fetchone()
@@ -104,11 +104,11 @@ def _maybe_init_experiment(self, experiment_name):
104104
computed_time = 0
105105
cursor.execute(
106106
"""
107-
INSERT INTO Experiments (
108-
user_id, experiment_id, experiment_name,
109-
inserted_time, started_time, is_watching
110-
) VALUES (?, ?, ?, ?, ?, ?)
111-
""",
107+
INSERT INTO Experiments (
108+
user_id, experiment_id, experiment_name,
109+
inserted_time, started_time, is_watching
110+
) VALUES (?, ?, ?, ?, ?, ?)
111+
""",
112112
(
113113
user_id,
114114
experiment_id,
@@ -131,9 +131,9 @@ def _maybe_init_run(self, experiment_name, run_name):
131131
cursor = self._db.cursor()
132132
cursor.execute(
133133
"""
134-
SELECT run_id FROM Runs
135-
WHERE experiment_id = ? AND run_name = ?
136-
""",
134+
SELECT run_id FROM Runs
135+
WHERE experiment_id = ? AND run_name = ?
136+
""",
137137
(experiment_id, run_name),
138138
)
139139
row = cursor.fetchone()
@@ -144,10 +144,10 @@ def _maybe_init_run(self, experiment_name, run_name):
144144
started_time = 0
145145
cursor.execute(
146146
"""
147-
INSERT INTO Runs (
148-
experiment_id, run_id, run_name, inserted_time, started_time
149-
) VALUES (?, ?, ?, ?, ?)
150-
""",
147+
INSERT INTO Runs (
148+
experiment_id, run_id, run_name, inserted_time, started_time
149+
) VALUES (?, ?, ?, ?, ?)
150+
""",
151151
(experiment_id, run_id, run_name, time.time(), started_time),
152152
)
153153
return run_id
@@ -188,11 +188,11 @@ def _maybe_init_tags(self, run_id, tag_to_metadata):
188188
)
189189
cursor.executemany(
190190
"""
191-
INSERT INTO Tags (
192-
run_id, tag_id, tag_name, inserted_time, display_name, plugin_name,
193-
plugin_data
194-
) VALUES (?, ?, ?, ?, ?, ?, ?)
195-
""",
191+
INSERT INTO Tags (
192+
run_id, tag_id, tag_name, inserted_time, display_name, plugin_name,
193+
plugin_data
194+
) VALUES (?, ?, ?, ?, ?, ?, ?)
195+
""",
196196
new_tag_data,
197197
)
198198
return tag_to_id
@@ -237,10 +237,10 @@ def write_summaries(self, tagged_data, experiment_name, run_name):
237237
)
238238
self._db.executemany(
239239
"""
240-
INSERT OR REPLACE INTO Tensors (
241-
series, step, computed_time, dtype, shape, data
242-
) VALUES (?, ?, ?, ?, ?, ?)
243-
""",
240+
INSERT OR REPLACE INTO Tensors (
241+
series, step, computed_time, dtype, shape, data
242+
) VALUES (?, ?, ?, ?, ?, ?)
243+
""",
244244
tensor_values,
245245
)
246246

tensorboard/examples/plugins/example_raw_scalars/tensorboard_plugin_example_raw_scalars/plugin.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ class ExampleRawScalarsPlugin(base_plugin.TBPlugin):
4848
def __init__(self, context):
4949
"""Instantiates ExampleRawScalarsPlugin.
5050
51-
Args:
52-
context: A base_plugin.TBContext instance.
53-
"""
51+
Args:
52+
context: A base_plugin.TBContext instance.
53+
"""
5454
self._multiplexer = context.multiplexer
5555

5656
def get_plugin_apps(self):
@@ -64,10 +64,10 @@ def get_plugin_apps(self):
6464
def _serve_tags(self, request):
6565
"""Serves run to tag info.
6666
67-
Frontend clients can use the Multiplexer's run+tag structure to request data
68-
for a specific run+tag. Responds with a map of the form:
69-
{runName: [tagName, tagName, ...]}
70-
"""
67+
Frontend clients can use the Multiplexer's run+tag structure to request data
68+
for a specific run+tag. Responds with a map of the form:
69+
{runName: [tagName, tagName, ...]}
70+
"""
7171
run_tag_mapping = self._multiplexer.PluginRunToTagToContent(
7272
_SCALAR_PLUGIN_NAME
7373
)
@@ -81,10 +81,10 @@ def _serve_tags(self, request):
8181
def _serve_static_file(self, request):
8282
"""Returns a resource file from the static asset directory.
8383
84-
Requests from the frontend have a path in this form:
85-
/data/plugin/example_raw_scalars/static/foo
86-
This serves the appropriate asset: ./static/foo.
87-
"""
84+
Requests from the frontend have a path in this form:
85+
/data/plugin/example_raw_scalars/static/foo
86+
This serves the appropriate asset: ./static/foo.
87+
"""
8888
static_path_part = request.path[len(_PLUGIN_DIRECTORY_PATH_PART) :]
8989
res_path = os.path.join(os.path.dirname(__file__), static_path_part)
9090

@@ -97,9 +97,9 @@ def _serve_static_file(self, request):
9797
def is_active(self):
9898
"""Returns whether there is relevant data for the plugin to process.
9999
100-
When there are no runs with scalar data, TensorBoard will hide the plugin
101-
from the main navigation bar.
102-
"""
100+
When there are no runs with scalar data, TensorBoard will hide the plugin
101+
from the main navigation bar.
102+
"""
103103
return bool(
104104
self._multiplexer.PluginRunToTagToContent(_SCALAR_PLUGIN_NAME)
105105
)
@@ -110,20 +110,20 @@ def frontend_metadata(self):
110110
def scalars_impl(self, tag, run):
111111
"""Returns scalar data for the specified tag and run.
112112
113-
For details on how to use tags and runs, see
114-
https://github.com/tensorflow/tensorboard#tags-giving-names-to-data
113+
For details on how to use tags and runs, see
114+
https://github.com/tensorflow/tensorboard#tags-giving-names-to-data
115115
116-
Args:
117-
tag: string
118-
run: string
116+
Args:
117+
tag: string
118+
run: string
119119
120-
Returns:
121-
A list of ScalarEvents - tuples containing 3 numbers describing entries in
122-
the data series.
120+
Returns:
121+
A list of ScalarEvents - tuples containing 3 numbers describing entries in
122+
the data series.
123123
124-
Raises:
125-
errors.NotFoundError: if run+tag pair has no scalar data.
126-
"""
124+
Raises:
125+
errors.NotFoundError: if run+tag pair has no scalar data.
126+
"""
127127
try:
128128
tensor_events = self._multiplexer.Tensors(run, tag)
129129
values = [

0 commit comments

Comments
 (0)