Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 66da951

Browse files
authoredAug 16, 2019
Send the user's Python version to Segment (streamlit#1212)
* Move widget-related messages out of BackMsg.proto * Clear up protobuf/__init__.py . No need for all the crap we had there. * Send python_version to client * Large refactor so generated proto files have right Python path * Add __init__py to proto/ * Add useless comment to /proto/__init__py * Rename __init__py to __init__.py * Remove FixMe from Makefile.
1 parent 0da9882 commit 66da951

File tree

6 files changed

+46
-30
lines changed

6 files changed

+46
-30
lines changed
 

‎Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ wheel:
106106
# cd lib ; python setup.py bdist_wheel sdist
107107

108108
clean:
109-
@echo FIXME: This needs to be fixed!
110109
cd lib; rm -rf build dist .eggs *.egg-info
111110
find . -name '*.pyc' -type f -delete || true
112111
find . -name __pycache__ -type d -delete || true

‎frontend/src/App.jsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,22 @@ class App extends PureComponent {
184184
*/
185185
handleInitialize(initializeMsg) {
186186
SessionInfo.current = new SessionInfo({
187-
streamlitVersion: initializeMsg.streamlitVersion,
187+
streamlitVersion: initializeMsg.environmentInfo.streamlitVersion,
188+
pythonVersion: initializeMsg.environmentInfo.pythonVersion,
188189
installationId: initializeMsg.userInfo.installationId,
189190
authorEmail: initializeMsg.userInfo.email,
190191
})
191192

192193
MetricsManager.current.initialize({
193-
gatherUsageStats: initializeMsg.gatherUsageStats,
194+
gatherUsageStats: initializeMsg.config.gatherUsageStats,
194195
})
195196

196-
MetricsManager.current.enqueue('createReport')
197+
MetricsManager.current.enqueue('createReport', {
198+
pythonVersion: SessionInfo.current.pythonVersion,
199+
})
197200

198201
this.setState({
199-
sharingEnabled: initializeMsg.sharingEnabled,
202+
sharingEnabled: initializeMsg.config.sharingEnabled,
200203
})
201204

202205
const initialState = initializeMsg.sessionState

‎frontend/src/lib/SessionInfo.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
interface Args {
88
streamlitVersion: string;
9+
pythonVersion: string;
910
installationId: string;
1011
authorEmail: string;
1112
}
1213

1314

1415
export class SessionInfo {
1516
public readonly streamlitVersion: string;
17+
public readonly pythonVersion: string;
1618
public readonly installationId: string;
1719
public readonly authorEmail: string;
1820

@@ -36,8 +38,11 @@ export class SessionInfo {
3638
SessionInfo.singleton = sm
3739
}
3840

39-
public constructor({streamlitVersion, installationId, authorEmail}: Args) {
41+
public constructor({
42+
streamlitVersion, pythonVersion, installationId, authorEmail,
43+
}: Args) {
4044
this.streamlitVersion = streamlitVersion
45+
this.pythonVersion = pythonVersion
4146
this.installationId = installationId
4247
this.authorEmail = authorEmail
4348
}

‎lib/streamlit/ReportSession.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright 2019 Streamlit Inc. All rights reserved.
22
# -*- coding: utf-8 -*-
33
from enum import Enum
4+
import sys
45

56
import tornado.gen
67
import tornado.ioloop
@@ -314,22 +315,25 @@ def _maybe_enqueue_initialize_message(self):
314315
msg = ForwardMsg()
315316
imsg = msg.initialize
316317

317-
imsg.sharing_enabled = (
318+
imsg.config.sharing_enabled = (
318319
config.get_option('global.sharingMode') != 'off')
319320
LOGGER.debug(
320321
'New browser connection: sharing_enabled=%s',
321-
msg.initialize.sharing_enabled)
322+
imsg.config.sharing_enabled)
322323

323-
imsg.gather_usage_stats = (
324+
imsg.config.gather_usage_stats = (
324325
config.get_option('browser.gatherUsageStats'))
325326
LOGGER.debug(
326327
'New browser connection: gather_usage_stats=%s',
327-
msg.initialize.gather_usage_stats)
328+
imsg.config.gather_usage_stats)
329+
330+
imsg.environment_info.streamlit_version = __version__
331+
imsg.environment_info.python_version = (
332+
'.'.join(map(str, sys.version_info)))
328333

329-
imsg.streamlit_version = __version__
330334
imsg.session_state.run_on_save = self._run_on_save
331-
imsg.session_state.report_is_running = \
332-
self._state == ReportSessionState.REPORT_IS_RUNNING
335+
imsg.session_state.report_is_running = (
336+
self._state == ReportSessionState.REPORT_IS_RUNNING)
333337

334338
imsg.user_info.installation_id = __installation_id__
335339
imsg.user_info.email = Credentials.get_current().activation.email

‎lib/tests/streamlit/ReportQueue_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# their general type.
1414

1515
INIT_MSG = ForwardMsg()
16-
INIT_MSG.initialize.sharing_enabled = True
16+
INIT_MSG.initialize.config.sharing_enabled = True
1717

1818
TEXT_DELTA_MSG1 = ForwardMsg()
1919
TEXT_DELTA_MSG1.delta.new_element.text.body = 'text1'
@@ -44,7 +44,7 @@ def test_simple_enqueue(self):
4444
queue = rq.flush()
4545
self.assertTrue(rq.is_empty())
4646
self.assertEqual(len(queue), 1)
47-
self.assertTrue(queue[0].initialize.sharing_enabled)
47+
self.assertTrue(queue[0].initialize.config.sharing_enabled)
4848

4949
def test_enqueue_two(self):
5050
rq = ReportQueue()
@@ -57,7 +57,7 @@ def test_enqueue_two(self):
5757

5858
queue = rq.flush()
5959
self.assertEqual(len(queue), 2)
60-
self.assertTrue(queue[0].initialize.sharing_enabled)
60+
self.assertTrue(queue[0].initialize.config.sharing_enabled)
6161
self.assertEqual(queue[1].delta.id, 0)
6262
self.assertEqual(queue[1].delta.new_element.text.body, 'text1')
6363

@@ -75,7 +75,7 @@ def test_enqueue_three(self):
7575

7676
queue = rq.flush()
7777
self.assertEqual(len(queue), 3)
78-
self.assertTrue(queue[0].initialize.sharing_enabled)
78+
self.assertTrue(queue[0].initialize.config.sharing_enabled)
7979
self.assertEqual(queue[1].delta.id, 0)
8080
self.assertEqual(queue[1].delta.new_element.text.body, 'text1')
8181
self.assertEqual(queue[2].delta.id, 1)
@@ -95,7 +95,7 @@ def test_replace_element(self):
9595

9696
queue = rq.flush()
9797
self.assertEqual(len(queue), 2)
98-
self.assertTrue(queue[0].initialize.sharing_enabled)
98+
self.assertTrue(queue[0].initialize.config.sharing_enabled)
9999
self.assertEqual(queue[1].delta.id, 0)
100100
self.assertEqual(queue[1].delta.new_element.text.body, 'text2')
101101

@@ -116,7 +116,7 @@ def test_simple_add_rows(self):
116116

117117
queue = rq.flush()
118118
self.assertEqual(len(queue), 3)
119-
self.assertTrue(queue[0].initialize.sharing_enabled)
119+
self.assertTrue(queue[0].initialize.config.sharing_enabled)
120120
self.assertEqual(queue[1].delta.id, 0)
121121
self.assertEqual(queue[1].delta.new_element.text.body, 'text1')
122122
self.assertEqual(queue[2].delta.id, 1)
@@ -144,7 +144,7 @@ def test_add_rows_rerun(self):
144144

145145
queue = rq.flush()
146146
self.assertEqual(len(queue), 3)
147-
self.assertTrue(queue[0].initialize.sharing_enabled)
147+
self.assertTrue(queue[0].initialize.config.sharing_enabled)
148148
self.assertEqual(queue[1].delta.id, 0)
149149
self.assertEqual(queue[1].delta.new_element.text.body, 'text1')
150150
self.assertEqual(queue[2].delta.id, 1)

‎proto/streamlit/proto/Initialize.proto

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,29 @@ import "streamlit/proto/SessionState.proto";
66
// It contains streamlit configuration data, and the session state
77
// that existed at the time of connection.
88
message Initialize {
9+
UserInfo user_info = 1;
10+
Config config = 2;
11+
EnvironmentInfo environment_info = 3;
12+
13+
// The session state at the time the connection was established
14+
SessionState session_state = 4;
15+
}
16+
17+
message Config {
918
// True if saving is properly configured.
1019
bool sharing_enabled = 1;
1120

12-
// If true, tells Streamlit to log datpoints for our own stats when the user
13-
// performs certain actions.
21+
// See config option "browser.gatherUsageStats".
1422
bool gather_usage_stats = 2;
1523

16-
// Python streamlit version.
17-
string streamlit_version = 3;
18-
19-
// The session state at the time the connection
20-
// was established
21-
SessionState session_state = 5;
22-
23-
UserInfo user_info = 6;
2424
}
2525

2626
message UserInfo {
2727
string installation_id = 1;
2828
string email = 2;
2929
}
30+
31+
message EnvironmentInfo {
32+
string streamlit_version = 1;
33+
string python_version = 2;
34+
}

0 commit comments

Comments
 (0)
Failed to load comments.