| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d788d18 commit a58eeff
46 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,7 @@ | |||
| 14 | 14 | LOG_FORMAT = "%(asctime)s UTC - %(levelname)s - %(name)s - %(message)s" | |
| 15 | 15 | queue_handler = None | |
| 16 | 16 | ||
| 17 | + | ||
| 17 | 18 | def add_arguments(parser): | |
| 18 | 19 | parser.description = "Daemon" | |
| 19 | 20 | ||
@@ -47,16 +48,19 @@ class TemporaryQueueHandler(logging.Handler): | |||
| 47 | 48 | Later the messages are pushed back to the RPC client as a notification. | |
| 48 | 49 | Once the RPC channel is up, we'll stop queuing messages and sending id directly. | |
| 49 | 50 | """ | |
| 51 | + | ||
| 50 | 52 | def __init__(self): | |
| 51 | 53 | logging.Handler.__init__(self) | |
| 52 | 54 | self.queue = [] | |
| 53 | 55 | self.server = None | |
| 56 | + | ||
| 54 | 57 | def set_server(self, server): | |
| 55 | 58 | # Send everything that has beeen queued until now. | |
| 56 | 59 | self.server = server | |
| 57 | 60 | for msg in self.queue: | |
| 58 | 61 | self.server._endpoint.notify("log", msg) | |
| 59 | 62 | self.queue = [] | |
| 63 | + | ||
| 60 | 64 | def emit(self, record): | |
| 61 | 65 | data = {"level": record.levelname, "msg": self.format(record)} | |
| 62 | 66 | # If we don't have the server, then queue it and send it later. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -128,4 +128,3 @@ def redirect_output(stdout_handler, stderr_handler): | |||
| 128 | 128 | _stderr_redirector = sys.stderr = IORedirector( | |
| 129 | 129 | "stderr", sys.stderr, sys._vsc_err_buffer_, True | |
| 130 | 130 | ) | |
| 131 | - | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -67,7 +67,9 @@ class PythonDaemon(MethodDispatcher): | |||
| 67 | 67 | """ | |
| 68 | 68 | ||
| 69 | 69 | def __init__(self, rx, tx): | |
| 70 | - self.log = logging.getLogger("{0}.{1}".format(self.__class__.__module__,self.__class__.__name__)) | ||
| 70 | + self.log = logging.getLogger( | ||
| 71 | + "{0}.{1}".format(self.__class__.__module__, self.__class__.__name__) | ||
| 72 | + ) | ||
| 71 | 73 | self._jsonrpc_stream_reader = JsonRpcStreamReader(rx) | |
| 72 | 74 | self._jsonrpc_stream_writer = JsonRpcStreamWriter(tx) | |
| 73 | 75 | self._endpoint = Endpoint( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,22 +4,25 @@ | |||
| 4 | 4 | import argparse | |
| 5 | 5 | import time | |
| 6 | 6 | ||
| 7 | + | ||
| 7 | 8 | def main(): | |
| 8 | - print('hello from dummy jupyter') | ||
| 9 | + print("hello from dummy jupyter") | ||
| 9 | 10 | parser = argparse.ArgumentParser() | |
| 10 | - parser.add_argument('--version', type=bool, default=False, const=True, nargs='?') | ||
| 11 | - parser.add_argument('notebook', type=bool, default=False, const=True, nargs='?') | ||
| 12 | - parser.add_argument('--no-browser', type=bool, default=False, const=True, nargs='?') | ||
| 13 | - parser.add_argument('--notebook-dir', default='') | ||
| 14 | - parser.add_argument('--config', default='') | ||
| 11 | + parser.add_argument("--version", type=bool, default=False, const=True, nargs="?") | ||
| 12 | + parser.add_argument("notebook", type=bool, default=False, const=True, nargs="?") | ||
| 13 | + parser.add_argument("--no-browser", type=bool, default=False, const=True, nargs="?") | ||
| 14 | + parser.add_argument("--notebook-dir", default="") | ||
| 15 | + parser.add_argument("--config", default="") | ||
| 15 | 16 | results = parser.parse_args() | |
| 16 | - if (results.version): | ||
| 17 | - print('1.1.dummy') | ||
| 17 | + if results.version: | ||
| 18 | + print("1.1.dummy") | ||
| 18 | 19 | else: | |
| 19 | - print('http://localhost:8888/?token=012f08663a68e279fe0a5335e0b5dfe44759ddcccf0b3a56') | ||
| 20 | + print( | ||
| 21 | + "http://localhost:8888/?token=012f08663a68e279fe0a5335e0b5dfe44759ddcccf0b3a56" | ||
| 22 | + ) | ||
| 20 | 23 | time.sleep(5) | |
| 21 | - raise Exception('Dummy is dead') | ||
| 24 | + raise Exception("Dummy is dead") | ||
| 22 | 25 | ||
| 23 | 26 | ||
| 24 | - if __name__ == '__main__': | ||
| 27 | + if __name__ == "__main__": | ||
| 25 | 28 | main() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,9 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | 9 | specs = jupyter_client.kernelspec.KernelSpecManager().get_all_specs() | |
| 10 | - all_specs = { | ||
| 11 | - "kernelspecs": specs | ||
| 12 | - } | ||
| 10 | + all_specs = {"kernelspecs": specs} | ||
| 13 | 11 | ||
| 14 | 12 | sys.stdout.write(json.dumps(all_specs)) | |
| 15 | 13 | sys.stdout.flush() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,31 +8,31 @@ | |||
| 8 | 8 | ||
| 9 | 9 | # In IJupyterVariables.getValue this '_VSCode_JupyterTestValue' will be replaced with the json stringified value of the target variable | |
| 10 | 10 | # Indexes off of _VSCODE_targetVariable need to index types that are part of IJupyterVariable | |
| 11 | - _VSCODE_targetVariable = _VSCODE_json.loads('_VSCode_JupyterTestValue') | ||
| 11 | + _VSCODE_targetVariable = _VSCODE_json.loads("""_VSCode_JupyterTestValue""") | ||
| 12 | 12 | ||
| 13 | 13 | # First check to see if we are a supported type, this prevents us from adding types that are not supported | |
| 14 | 14 | # and also keeps our types in sync with what the variable explorer says that we support | |
| 15 | - if _VSCODE_targetVariable['type'] not in _VSCode_supportsDataExplorer: | ||
| 15 | + if _VSCODE_targetVariable["type"] not in _VSCode_supportsDataExplorer: | ||
| 16 | 16 | del _VSCode_supportsDataExplorer | |
| 17 | 17 | print(_VSCODE_json.dumps(_VSCODE_targetVariable)) | |
| 18 | 18 | del _VSCODE_targetVariable | |
| 19 | 19 | else: | |
| 20 | 20 | del _VSCode_supportsDataExplorer | |
| 21 | - _VSCODE_evalResult = eval(_VSCODE_targetVariable['name']) | ||
| 21 | + _VSCODE_evalResult = eval(_VSCODE_targetVariable["name"]) | ||
| 22 | 22 | ||
| 23 | 23 | # Figure out shape if not already there. Use the shape to compute the row count | |
| 24 | - if (hasattr(_VSCODE_evalResult, 'shape')): | ||
| 24 | + if hasattr(_VSCODE_evalResult, "shape"): | ||
| 25 | 25 | try: | |
| 26 | 26 | # Get a bit more restrictive with exactly what we want to count as a shape, since anything can define it | |
| 27 | 27 | if isinstance(_VSCODE_evalResult.shape, tuple): | |
| 28 | - _VSCODE_targetVariable['rowCount'] = _VSCODE_evalResult.shape[0] | ||
| 28 | + _VSCODE_targetVariable["rowCount"] = _VSCODE_evalResult.shape[0] | ||
| 29 | 29 | except TypeError: | |
| 30 | - _VSCODE_targetVariable['rowCount'] = 0 | ||
| 31 | - elif (hasattr(_VSCODE_evalResult, '__len__')): | ||
| 30 | + _VSCODE_targetVariable["rowCount"] = 0 | ||
| 31 | + elif hasattr(_VSCODE_evalResult, "__len__"): | ||
| 32 | 32 | try: | |
| 33 | - _VSCODE_targetVariable['rowCount'] = len(_VSCODE_evalResult) | ||
| 33 | + _VSCODE_targetVariable["rowCount"] = len(_VSCODE_evalResult) | ||
| 34 | 34 | except TypeError: | |
| 35 | - _VSCODE_targetVariable['rowCount'] = 0 | ||
| 35 | + _VSCODE_targetVariable["rowCount"] = 0 | ||
| 36 | 36 | ||
| 37 | 37 | # Turn the eval result into a df | |
| 38 | 38 | _VSCODE_df = _VSCODE_evalResult | |
@@ -43,16 +43,18 @@ | |||
| 43 | 43 | elif isinstance(_VSCODE_evalResult, dict): | |
| 44 | 44 | _VSCODE_evalResult = _VSCODE_pd.Series(_VSCODE_evalResult) | |
| 45 | 45 | _VSCODE_df = _VSCODE_pd.Series.to_frame(_VSCODE_evalResult) | |
| 46 | - elif _VSCODE_targetVariable['type'] == 'ndarray': | ||
| 46 | + elif _VSCODE_targetVariable["type"] == "ndarray": | ||
| 47 | 47 | _VSCODE_df = _VSCODE_pd.DataFrame(_VSCODE_evalResult) | |
| 48 | 48 | ||
| 49 | 49 | # If any rows, use pandas json to convert a single row to json. Extract | |
| 50 | 50 | # the column names and types from the json so we match what we'll fetch when | |
| 51 | 51 | # we ask for all of the rows | |
| 52 | - if _VSCODE_targetVariable['rowCount']: | ||
| 52 | + if _VSCODE_targetVariable["rowCount"]: | ||
| 53 | 53 | try: | |
| 54 | 54 | _VSCODE_row = _VSCODE_df.iloc[0:1] | |
| 55 | - _VSCODE_json_row = _VSCODE_pd_json.to_json(None, _VSCODE_row, date_format='iso') | ||
| 55 | + _VSCODE_json_row = _VSCODE_pd_json.to_json( | ||
| 56 | + None, _VSCODE_row, date_format="iso" | ||
| 57 | + ) | ||
| 56 | 58 | _VSCODE_columnNames = list(_VSCODE_json.loads(_VSCODE_json_row)) | |
| 57 | 59 | del _VSCODE_row | |
| 58 | 60 | del _VSCODE_json_row | |
@@ -62,24 +64,24 @@ | |||
| 62 | 64 | _VSCODE_columnNames = list(_VSCODE_df) | |
| 63 | 65 | ||
| 64 | 66 | # Compute the index column. It may have been renamed | |
| 65 | - _VSCODE_indexColumn = _VSCODE_df.index.name if _VSCODE_df.index.name else 'index' | ||
| 67 | + _VSCODE_indexColumn = _VSCODE_df.index.name if _VSCODE_df.index.name else "index" | ||
| 66 | 68 | _VSCODE_columnTypes = list(_VSCODE_df.dtypes) | |
| 67 | 69 | del _VSCODE_df | |
| 68 | 70 | ||
| 69 | 71 | # Make sure the index column exists | |
| 70 | 72 | if _VSCODE_indexColumn not in _VSCODE_columnNames: | |
| 71 | 73 | _VSCODE_columnNames.insert(0, _VSCODE_indexColumn) | |
| 72 | - _VSCODE_columnTypes.insert(0, 'int64') | ||
| 74 | + _VSCODE_columnTypes.insert(0, "int64") | ||
| 73 | 75 | ||
| 74 | 76 | # Then loop and generate our output json | |
| 75 | 77 | _VSCODE_columns = [] | |
| 76 | 78 | for _VSCODE_n in range(0, len(_VSCODE_columnNames)): | |
| 77 | 79 | _VSCODE_column_type = _VSCODE_columnTypes[_VSCODE_n] | |
| 78 | 80 | _VSCODE_column_name = str(_VSCODE_columnNames[_VSCODE_n]) | |
| 79 | 81 | _VSCODE_colobj = {} | |
| 80 | - _VSCODE_colobj['key'] = _VSCODE_column_name | ||
| 81 | - _VSCODE_colobj['name'] = _VSCODE_column_name | ||
| 82 | - _VSCODE_colobj['type'] = str(_VSCODE_column_type) | ||
| 82 | + _VSCODE_colobj["key"] = _VSCODE_column_name | ||
| 83 | + _VSCODE_colobj["name"] = _VSCODE_column_name | ||
| 84 | + _VSCODE_colobj["type"] = str(_VSCODE_column_type) | ||
| 83 | 85 | _VSCODE_columns.append(_VSCODE_colobj) | |
| 84 | 86 | del _VSCODE_column_name | |
| 85 | 87 | del _VSCODE_column_type | |
@@ -88,12 +90,11 @@ | |||
| 88 | 90 | del _VSCODE_columnTypes | |
| 89 | 91 | ||
| 90 | 92 | # Save this in our target | |
| 91 | - _VSCODE_targetVariable['columns'] = _VSCODE_columns | ||
| 92 | - _VSCODE_targetVariable['indexColumn'] = _VSCODE_indexColumn | ||
| 93 | + _VSCODE_targetVariable["columns"] = _VSCODE_columns | ||
| 94 | + _VSCODE_targetVariable["indexColumn"] = _VSCODE_indexColumn | ||
| 93 | 95 | del _VSCODE_columns | |
| 94 | 96 | del _VSCODE_indexColumn | |
| 95 | 97 | ||
| 96 | - | ||
| 97 | 98 | # Transform this back into a string | |
| 98 | 99 | print(_VSCODE_json.dumps(_VSCODE_targetVariable)) | |
| 99 | 100 | del _VSCODE_targetVariable | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,13 +5,13 @@ | |||
| 5 | 5 | ||
| 6 | 6 | # In IJupyterVariables.getValue this '_VSCode_JupyterTestValue' will be replaced with the json stringified value of the target variable | |
| 7 | 7 | # Indexes off of _VSCODE_targetVariable need to index types that are part of IJupyterVariable | |
| 8 | - _VSCODE_targetVariable = _VSCODE_json.loads('_VSCode_JupyterTestValue') | ||
| 9 | - _VSCODE_evalResult = eval(_VSCODE_targetVariable['name']) | ||
| 8 | + _VSCODE_targetVariable = _VSCODE_json.loads("""_VSCode_JupyterTestValue""") | ||
| 9 | + _VSCODE_evalResult = eval(_VSCODE_targetVariable["name"]) | ||
| 10 | 10 | ||
| 11 | 11 | # _VSCode_JupyterStartRow and _VSCode_JupyterEndRow should be replaced dynamically with the literals | |
| 12 | 12 | # for our start and end rows | |
| 13 | 13 | _VSCODE_startRow = max(_VSCode_JupyterStartRow, 0) | |
| 14 | - _VSCODE_endRow = min(_VSCode_JupyterEndRow, _VSCODE_targetVariable['rowCount']) | ||
| 14 | + _VSCODE_endRow = min(_VSCode_JupyterEndRow, _VSCODE_targetVariable["rowCount"]) | ||
| 15 | 15 | ||
| 16 | 16 | # Assume we have a dataframe. If not, turn our eval result into a dataframe | |
| 17 | 17 | _VSCODE_df = _VSCODE_evalResult | |
@@ -22,15 +22,17 @@ | |||
| 22 | 22 | elif isinstance(_VSCODE_evalResult, dict): | |
| 23 | 23 | _VSCODE_evalResult = _VSCODE_pd.Series(_VSCODE_evalResult) | |
| 24 | 24 | _VSCODE_df = _VSCODE_pd.Series.to_frame(_VSCODE_evalResult) | |
| 25 | - elif _VSCODE_targetVariable['type'] == 'ndarray': | ||
| 25 | + elif _VSCODE_targetVariable["type"] == "ndarray": | ||
| 26 | 26 | _VSCODE_df = _VSCODE_pd.DataFrame(_VSCODE_evalResult) | |
| 27 | 27 | # If not a known type, then just let pandas handle it. | |
| 28 | - elif not (hasattr(_VSCODE_df, 'iloc')): | ||
| 28 | + elif not (hasattr(_VSCODE_df, "iloc")): | ||
| 29 | 29 | _VSCODE_df = _VSCODE_pd.DataFrame(_VSCODE_evalResult) | |
| 30 | 30 | ||
| 31 | 31 | # Turn into JSON using pandas. We use pandas because it's about 3 orders of magnitude faster to turn into JSON | |
| 32 | 32 | _VSCODE_rows = _VSCODE_df.iloc[_VSCODE_startRow:_VSCODE_endRow] | |
| 33 | - _VSCODE_result = _VSCODE_pd_json.to_json(None, _VSCODE_rows, orient='table', date_format='iso') | ||
| 33 | + _VSCODE_result = _VSCODE_pd_json.to_json( | ||
| 34 | + None, _VSCODE_rows, orient="table", date_format="iso" | ||
| 35 | + ) | ||
| 34 | 36 | print(_VSCODE_result) | |
| 35 | 37 | ||
| 36 | 38 | # Cleanup our variables | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,13 +8,21 @@ | |||
| 8 | 8 | _VSCode_supportsDataExplorer = "['list', 'Series', 'dict', 'ndarray', 'DataFrame']" | |
| 9 | 9 | ||
| 10 | 10 | # who_ls is a Jupyter line magic to fetch currently defined vars | |
| 11 | - _VSCode_JupyterVars = _VSCODE_get_ipython().run_line_magic('who_ls', '') | ||
| 11 | + _VSCode_JupyterVars = _VSCODE_get_ipython().run_line_magic("who_ls", "") | ||
| 12 | 12 | ||
| 13 | 13 | _VSCode_output = [] | |
| 14 | 14 | for _VSCode_var in _VSCode_JupyterVars: | |
| 15 | 15 | try: | |
| 16 | 16 | _VSCode_type = type(eval(_VSCode_var)) | |
| 17 | - _VSCode_output.append({'name': _VSCode_var, 'type': _VSCode_type.__name__, 'size': _VSCODE_getsizeof(_VSCode_var), 'supportsDataExplorer': _VSCode_type.__name__ in _VSCode_supportsDataExplorer }) | ||
| 17 | + _VSCode_output.append( | ||
| 18 | + { | ||
| 19 | + "name": _VSCode_var, | ||
| 20 | + "type": _VSCode_type.__name__, | ||
| 21 | + "size": _VSCODE_getsizeof(_VSCode_var), | ||
| 22 | + "supportsDataExplorer": _VSCode_type.__name__ | ||
| 23 | + in _VSCode_supportsDataExplorer, | ||
| 24 | + } | ||
| 25 | + ) | ||
| 18 | 26 | del _VSCode_type | |
| 19 | 27 | del _VSCode_var | |
| 20 | 28 | except: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments