Skip to content

Commit cd8f8d7

Browse files
authored
Remove the demoify function (#490)
Summary: We don’t support the demo mode at all, nor do we have any plans to. This function is complicating our logic and getting in the way of things that we actually want to do, so out it goes. Note that this commit does not remove “demo mode” entirely: the router still has `demoMode`, and I didn’t go through and remove all of its uses. (But that’s not a bad idea, and there are only a handful.) Test Plan: I tested that the image and audio dashboards still properly load images and audio. Changes to the test are not tested, as we don’t run tests. wchargin-branch: remove-demoify
1 parent a8f6d02 commit cd8f8d7

File tree

6 files changed

+17
-63
lines changed

6 files changed

+17
-63
lines changed

tensorboard/components/tf_backend/backend.ts

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ limitations under the License.
1616
import {compareTagNames} from '../vz-sorting/sorting.js';
1717
import {RequestManager} from './requestManager.js';
1818
import {getRouter} from './router.js';
19-
import {demoify, queryEncoder} from './urlPathHelpers.js';
2019

2120
export type RunToTag = {
2221
[run: string]: string[];

tensorboard/components/tf_backend/router.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515

16-
import {demoify, queryEncoder} from './urlPathHelpers.js';
16+
import {queryEncoder} from './urlPathHelpers.js';
1717

1818
export type RunTagUrlFn = (tag: string, run: string) => string;
1919

@@ -35,19 +35,13 @@ export interface Router {
3535
* @param demoMode {boolean} Whether to modify urls for filesystem demo usage.
3636
*/
3737
export function createRouter(dataDir = 'data', demoMode = false): Router {
38-
var clean = demoMode ? demoify : (x) => x;
3938
if (dataDir[dataDir.length - 1] === '/') {
4039
dataDir = dataDir.slice(0, dataDir.length - 1);
4140
}
4241
function standardRoute(route: string, demoExtension = '.json'):
4342
((tag: string, run: string) => string) {
4443
return function(tag: string, run: string): string {
45-
var url =
46-
dataDir + '/' + route + clean(queryEncoder({tag: tag, run: run}));
47-
if (demoMode) {
48-
url += demoExtension;
49-
}
50-
return url;
44+
return dataDir + '/' + route + queryEncoder({tag: tag, run: run});
5145
};
5246
}
5347
function pluginRoute(pluginName: string, route: string): string {
@@ -56,7 +50,7 @@ export function createRouter(dataDir = 'data', demoMode = false): Router {
5650
function pluginRunTagRoute(pluginName: string, route: string):
5751
((tag: string, run: string) => string) {
5852
const base = pluginRoute(pluginName, route);
59-
return (tag, run) => base + clean(queryEncoder({tag, run}));
53+
return (tag, run) => base + queryEncoder({tag, run});
6054
}
6155
return {
6256
logdir: () => dataDir + '/logdir',

tensorboard/components/tf_backend/test/backendTests.ts

+4-15
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,13 @@ limitations under the License.
1616
import {filterTags, getRuns, getTags, RunToTag, TYPES} from '../backend.js';
1717
import {RequestManager} from '../requestManager.js';
1818
import {createRouter, setRouter} from '../router.js';
19-
import {BAD_CHARACTERS, demoify, queryEncoder} from '../urlPathHelpers.js';
19+
import {queryEncoder} from '../urlPathHelpers.js';
2020

2121
describe('urlPathHelpers', () => {
22-
it('demoify works as expected', () => {
23-
const demoified = demoify(BAD_CHARACTERS);
24-
let allClean = '';
25-
for (let i = 0; i < BAD_CHARACTERS.length; i++) {
26-
allClean += '_';
27-
}
28-
chai.assert.equal(demoified, allClean, 'cleaning the BAD_CHARACTERS works');
29-
chai.assert.equal(demoify('foozod'), 'foozod', 'doesnt change safe string');
30-
chai.assert.equal(demoify('foo zod (2)'), 'foo_zod__2_', 'simple case');
31-
});
32-
33-
it('queryEncoder works with demoify on spaces and parens', () => {
22+
it('queryEncoder works on spaces and parens', () => {
3423
const params = {foo: 'something with spaces and (parens)'};
35-
const actual = demoify(queryEncoder(params));
36-
const expected = '_foo_something_with_spaces_and__28parens_29';
24+
const actual = queryEncoder(params);
25+
const expected = 'something+with+spaces+and+%28parens%29';
3726
chai.assert.equal(actual, expected);
3827
});
3928
});

tensorboard/components/tf_backend/urlPathHelpers.ts

-12
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
15-
export const BAD_CHARACTERS = '#%&{}\\/<>*? $!\'":@+`|=() ';
16-
/** Cleanup a url so that it can be loaded from a filesystem. */
17-
export function demoify(s) {
18-
// for consistency with python's urllib.urlencode
19-
s = s.replace(new RegExp('%20', 'g'), '+');
20-
for (let i = 0; i < BAD_CHARACTERS.length; i++) {
21-
const c = BAD_CHARACTERS[i];
22-
s = s.replace(new RegExp('\\' + c, 'g'), '_');
23-
}
24-
return s;
25-
}
26-
2715
export function queryEncoder(params?: any): string {
2816
// It's important that the keys be sorted, so we always grab the right file
2917
// if we are talking to the backend generated by serialze_tensorboard.py

tensorboard/plugins/audio/tf_audio_dashboard/tf-audio-loader.html

+5-13
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@
118118
import {getRouter} from "../tf-backend/router.js";
119119
import {formatDate} from '../tf-card-heading/util.js';
120120
import {runsColorScale} from "../tf-color-scale/colorScale.js";
121-
import * as urlPathHelpers from "../tf-backend/urlPathHelpers.js";
122121

123122
Polymer({
124123
is: "tf-audio-loader",
@@ -235,19 +234,12 @@
235234
// The route lacks GET parameters. Just use ours.
236235
query = '?' + query;
237236
}
238-
if (getRouter().isDemoMode()) {
239-
query = urlPathHelpers.demoify(query);
240-
}
241237

242-
let individualAudioURL = route + query;
243-
if (getRouter().isDemoMode()) {
244-
individualAudioURL += '.png';
245-
} else {
246-
// Include wall_time just to disambiguate the URL and force
247-
// the browser to reload the audio when the URL changes. The
248-
// backend doesn't care about the value.
249-
individualAudioURL += `&ts=${audioMetadata.wall_time}`;
250-
}
238+
// Include wall_time just to disambiguate the URL and force
239+
// the browser to reload the audio when the URL changes. The
240+
// backend doesn't care about the value.
241+
const individualAudioURL = `${route}${query}&ts=${audioMetadata.wall_time}`;
242+
251243
return {
252244
wall_time: formatDate(new Date(audioMetadata.wall_time * 1000)),
253245
step: audioMetadata.step,

tensorboard/plugins/image/tf_image_dashboard/tf-image-loader.html

+5-13
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@
185185
import {getRouter} from "../tf-backend/router.js";
186186
import {formatDate} from '../tf-card-heading/util.js';
187187
import {runsColorScale} from "../tf-color-scale/colorScale.js";
188-
import * as urlPathHelpers from "../tf-backend/urlPathHelpers.js";
189188

190189
Polymer({
191190
is: "tf-image-loader",
@@ -330,19 +329,12 @@
330329
// The route lacks GET parameters. Just use ours.
331330
query = '?' + query;
332331
}
333-
if (getRouter().isDemoMode()) {
334-
query = urlPathHelpers.demoify(query);
335-
}
336332

337-
let individualImageUrl = route + query;
338-
if (getRouter().isDemoMode()) {
339-
individualImageUrl += '.png';
340-
} else {
341-
// Include wall_time just to disambiguate the URL and force
342-
// the browser to reload the image when the URL changes. The
343-
// backend doesn't care about the value.
344-
individualImageUrl += `&ts=${imageMetadata.wall_time}`;
345-
}
333+
// Include wall_time just to disambiguate the URL and force
334+
// the browser to reload the image when the URL changes. The
335+
// backend doesn't care about the value.
336+
const individualImageUrl = `${route}${query}&ts=${imageMetadata.wall_time}`;
337+
346338
return {
347339
width: imageMetadata.width,
348340
height: imageMetadata.height,

0 commit comments

Comments
 (0)