@@ -1903,7 +1903,7 @@ def initialize_jupyter_notebook(
1903
1903
self ,
1904
1904
dest_notebook_name : str ,
1905
1905
source_notebook_path : str ,
1906
- variable_name : str = 'ANALYSIS_FILES ' ,
1906
+ variable_name : str = 'DATA_FILES ' ,
1907
1907
cell_to_modify : int = 0 ,
1908
1908
) -> None :
1909
1909
"""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(
1913
1913
Params:
1914
1914
- dest_notebook_name: name of the JupyterNotebook you want to write (do not include file paths).
1915
1915
- 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 ")
1917
1917
- cell_to_modify: which cell in the JupyterNotebook you want to add the data call to (0-indexed).
1918
1918
(This will not overwrite any cells, just appends.)
1919
1919
By default, the data listing will happen in the FIRST cell.
@@ -1942,16 +1942,16 @@ def initialize_jupyter_notebook(
1942
1942
self .publish ('_IPS_MONITOR' , 'PORTAL_REGISTER_NOTEBOOK' , event_data )
1943
1943
self ._send_monitor_event ('IPS_PORTAL_REGISTER_NOTEBOOK' , f'URL = { url } ' )
1944
1944
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 ):
1946
1946
"""Add data file to JupyterHub directory, and reference it in the notebook.
1947
1947
1948
1948
This function assumes that a notebook has already been created with intialize_jupyter_notebook. Using this function does not call the IPS Portal.
1949
1949
1950
1950
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.
1952
1952
- timestamp: label to assign to the data (currently must be a floating point value)
1953
1953
- 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)
1955
1955
- index: optional index of the IPS notebook cell. If not provided, the IPS Framework will attempt to automatically find the cell it created,
1956
1956
which should work for every usecase where you don't anticipate modifying the notebook until after the run is complete.
1957
1957
"""
@@ -1960,16 +1960,16 @@ def add_data_file_to_notebook(self, state_file_path: str, timestamp: float, note
1960
1960
# TODO generic exception
1961
1961
raise Exception ('Unable to initialize base JupyterHub dir' )
1962
1962
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 )
1965
1965
# 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 )
1967
1967
1968
1968
if replace :
1969
1969
# first try to remove the reference from the Jupyter Notebook
1970
1970
filename_to_remove = remove_last_data_file_from_notebook (f'{ self ._jupyterhub_dir } { notebook_name } ' , index )
1971
1971
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
1973
1973
file_to_remove = os .path .join (self ._jupyterhub_dir , 'data' , filename_to_remove )
1974
1974
shutil .rmtree (file_to_remove , ignore_errors = True )
1975
1975
0 commit comments