Skip to content

Commit 563d678

Browse files
committed
jupyter API - use more consistent naming patterns
Signed-off-by: Lance-Drane <[email protected]>
1 parent 6c47475 commit 563d678

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

examples-proposed/004-time-loop/sim/input_dir/basic.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
"outputs": [],
99
"source": [
1010
"# Notebook template, the IPS Framework will add a cell before this one\n",
11-
"# defining ANALYSIS_FILES as a list of state file paths.\n",
11+
"# defining DATA_FILES as a list of state file paths.\n",
1212
"\n",
1313
"# In this example, this notebook is generated during the time loop.\n",
1414
"\n",
1515
"mapping = {}\n",
16-
"for file in ANALYSIS_FILES:\n",
16+
"for file in DATA_FILES:\n",
1717
" with open(file, 'rb') as f:\n",
1818
" mapping[file] = f.read()\n",
1919
"print(mapping)\n"

examples-proposed/004-time-loop/sim/input_dir/bokeh-plots.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"outputs": [],
99
"source": [
1010
"# Notebook template, the IPS Framework will add a cell before this one\n",
11-
"# defining ANALYSIS_FILES as a list of state file paths.\n",
11+
"# defining DATA_FILES as a list of state file paths.\n",
1212
"\n",
1313
"# In this example, this notebook is only generated at the end of the run.\n",
1414
"\n",
@@ -21,10 +21,10 @@
2121
"\n",
2222
"DATA = []\n",
2323
"# create DATA list, will depend on user input type (i.e. 'hdf5', 'json')\n",
24-
"for file in ANALYSIS_FILES:\n",
24+
"for file in DATA_FILES:\n",
2525
" with open(file, 'rb') as f:\n",
2626
" DATA.append(json.load(f))\n",
27-
"x = [float(f.rpartition('/')[2]) for f in ANALYSIS_FILES]\n",
27+
"x = [float(f.rpartition('/')[2]) for f in DATA_FILES]\n",
2828
"\n",
2929
"COLORS = ['red', 'green', 'blue']\n",
3030
"\n",

ipsframework/services.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,7 @@ def initialize_jupyter_notebook(
19031903
self,
19041904
dest_notebook_name: str,
19051905
source_notebook_path: str,
1906-
variable_name: str = 'ANALYSIS_FILES',
1906+
variable_name: str = 'DATA_FILES',
19071907
cell_to_modify: int = 0,
19081908
) -> None:
19091909
"""Loads a notebook from source_notebook_path, adds a cell to load the data, and then saves it to source_notebook_path. Will also try to register the notebook with the IPS Portal, if available.
@@ -1913,7 +1913,7 @@ def initialize_jupyter_notebook(
19131913
Params:
19141914
- dest_notebook_name: name of the JupyterNotebook you want to write (do not include file paths).
19151915
- source_notebook_path: location you want to load the source notebook from
1916-
- variable_name: name of the variable you want to load files from (default: "ANALYSIS_FILES")
1916+
- variable_name: name of the variable you want to load files from (default: "DATA_FILES")
19171917
- cell_to_modify: which cell in the JupyterNotebook you want to add the data call to (0-indexed).
19181918
(This will not overwrite any cells, just appends.)
19191919
By default, the data listing will happen in the FIRST cell.
@@ -1942,16 +1942,16 @@ def initialize_jupyter_notebook(
19421942
self.publish('_IPS_MONITOR', 'PORTAL_REGISTER_NOTEBOOK', event_data)
19431943
self._send_monitor_event('IPS_PORTAL_REGISTER_NOTEBOOK', f'URL = {url}')
19441944

1945-
def add_data_file_to_notebook(self, state_file_path: str, timestamp: float, notebook_name: str, replace: bool = False, index: Optional[int] = None):
1945+
def add_data_file_to_notebook(self, data_file_path: str, timestamp: float, notebook_name: str, replace: bool = False, index: Optional[int] = None):
19461946
"""Add data file to JupyterHub directory, and reference it in the notebook.
19471947
19481948
This function assumes that a notebook has already been created with intialize_jupyter_notebook. Using this function does not call the IPS Portal.
19491949
19501950
Params:
1951-
- state_file_path: location of the current state file we want to copy to the Jupyter directory
1951+
- data_file_path: location of the current data file we want to copy to the Jupyter directory. This will usually be a state file.
19521952
- timestamp: label to assign to the data (currently must be a floating point value)
19531953
- notebook_name: name of notebook which will be modified. Note that this path is relative to the JupyterHub directory.
1954-
- replace: If True, replace the last data file added with the new data file. If False, simply append the new data file.
1954+
- replace: If True, replace the last data file added with the new data file. If False, simply append the new data file. (default: False)
19551955
- index: optional index of the IPS notebook cell. If not provided, the IPS Framework will attempt to automatically find the cell it created,
19561956
which should work for every usecase where you don't anticipate modifying the notebook until after the run is complete.
19571957
"""
@@ -1960,16 +1960,16 @@ def add_data_file_to_notebook(self, state_file_path: str, timestamp: float, note
19601960
# TODO generic exception
19611961
raise Exception('Unable to initialize base JupyterHub dir')
19621962

1963-
data_file_name = f'{timestamp}_{os.path.basename(state_file_path)}'
1964-
jupyter_data_dir = os.path.join(self._jupyterhub_dir, 'data', data_file_name)
1963+
data_file_name = f'{timestamp}_{os.path.basename(data_file_path)}'
1964+
jupyter_data_file = os.path.join(self._jupyterhub_dir, 'data', data_file_name)
19651965
# this may raise an OSError, it is the responsibility of the caller to handle it.
1966-
shutil.copyfile(state_file_path, jupyter_data_dir)
1966+
shutil.copyfile(data_file_path, jupyter_data_file)
19671967

19681968
if replace:
19691969
# first try to remove the reference from the Jupyter Notebook
19701970
filename_to_remove = remove_last_data_file_from_notebook(f'{self._jupyterhub_dir}{notebook_name}', index)
19711971
if filename_to_remove is not None:
1972-
# now remove the state file from the filesyste,
1972+
# now remove the state file from the filesystem
19731973
file_to_remove = os.path.join(self._jupyterhub_dir, 'data', filename_to_remove)
19741974
shutil.rmtree(file_to_remove, ignore_errors=True)
19751975

0 commit comments

Comments
 (0)