@@ -65,7 +65,7 @@ def check_nbextension(files, user=False, prefix=None, nbextensions_dir=None, sys
6565 files : list(paths)
6666 a list of relative paths within nbextensions.
6767 user : bool [default: False]
68- Whether to check the user's .ipython /nbextensions directory.
68+ Whether to check the user's .jupyter /nbextensions directory.
6969 Otherwise check a system-wide install (e.g. /usr/local/share/jupyter/nbextensions).
7070 prefix : str [optional]
7171 Specify install prefix, if it should differ from default (e.g. /usr/local).
@@ -322,7 +322,7 @@ def _set_nbextension_state(section, require, state,
322322 state : bool
323323 The state in which to leave the extension
324324 user : bool [default: False]
325- Whether to check the user's .ipython /nbextensions directory.
325+ Whether to check the user's .jupyter /nbextensions directory.
326326 Otherwise check a system-wide install (e.g. /usr/local/share/jupyter/nbextensions).
327327 sys_prefix : bool [default: False]
328328 Install into the sys.prefix, i.e. environment
@@ -905,7 +905,20 @@ def start(self):
905905
906906
907907def _should_copy (src , dest , logger = None ):
908- """Should a file be copied?"""
908+ """Should a file be copied, if it doesn't exist, or is newer?
909+
910+ Returns whether the file needs to be updated.
911+
912+ Parameters
913+ ----------
914+
915+ src : string
916+ A path that should exist from which to copy a file
917+ src : string
918+ A path that might exist to which to copy a file
919+ logger : Jupyter logger [optional]
920+ Logger instance to use
921+ """
909922 if not os .path .exists (dest ):
910923 return True
911924 if os .stat (src ).st_mtime - os .stat (dest ).st_mtime > 1e-6 :
@@ -920,23 +933,56 @@ def _should_copy(src, dest, logger=None):
920933
921934
922935def _maybe_copy (src , dest , logger = None ):
923- """Copy a file if it needs updating."""
936+ """Copy a file if it needs updating.
937+
938+ Parameters
939+ ----------
940+
941+ src : string
942+ A path that should exist from which to copy a file
943+ src : string
944+ A path that might exist to which to copy a file
945+ logger : Jupyter logger [optional]
946+ Logger instance to use
947+ """
924948 if _should_copy (src , dest , logger = logger ):
925949 if logger :
926950 logger .info ("Copying: %s -> %s" % (src , dest ))
927951 shutil .copy2 (src , dest )
928952
929953
930954def _safe_is_tarfile (path ):
931- """Safe version of is_tarfile, return False on IOError."""
955+ """Safe version of is_tarfile, return False on IOError.
956+
957+ Returns whether the file exists and is a tarfile.
958+
959+ Parameters
960+ ----------
961+
962+ path : string
963+ A path that might not exist and or be a tarfile
964+ """
932965 try :
933966 return tarfile .is_tarfile (path )
934967 except IOError :
935968 return False
936969
937970
938971def _get_nbextension_dir (user = False , sys_prefix = False , prefix = None , nbextensions_dir = None ):
939- """Return the nbextension directory specified"""
972+ """Return the nbextension directory specified
973+
974+ Parameters
975+ ----------
976+
977+ user : bool [default: False]
978+ Get the user's .jupyter/nbextensions directory
979+ sys_prefix : bool [default: False]
980+ Get sys.prefix, i.e. ~/.envs/my-env/share/jupyter/nbextensions
981+ prefix : str [optional]
982+ Get custom prefix
983+ nbextensions_dir : str [optional]
984+ Get what you put in
985+ """
940986 if sum (map (bool , [user , prefix , nbextensions_dir , sys_prefix ])) > 1 :
941987 raise ArgumentConflict ("cannot specify more than one of user, sys_prefix, prefix, or nbextensions_dir" )
942988 if user :
@@ -953,7 +999,10 @@ def _get_nbextension_dir(user=False, sys_prefix=False, prefix=None, nbextensions
953999
9541000
9551001def _nbextension_dirs ():
956- """The possible locations of nbextensions."""
1002+ """The possible locations of nbextensions.
1003+
1004+ Returns a list of known base extension locations
1005+ """
9571006 return [
9581007 pjoin (jupyter_data_dir (), u'nbextensions' ),
9591008 pjoin (ENV_JUPYTER_PATH [0 ], u'nbextensions' ),
@@ -962,6 +1011,18 @@ def _nbextension_dirs():
9621011
9631012
9641013def _get_config_dir (user = False , sys_prefix = False ):
1014+ """Get the location of config files for the current context
1015+
1016+ Returns the string to the enviornment
1017+
1018+ Parameters
1019+ ----------
1020+
1021+ user : bool [default: False]
1022+ Get the user's .jupyter config directory
1023+ sys_prefix : bool [default: False]
1024+ Get sys.prefix, i.e. ~/.envs/my-env/etc/jupyter
1025+ """
9651026 if user and sys_prefix :
9661027 raise ArgumentConflict ("Cannot specify more than one of user or sys_prefix" )
9671028 if user :
@@ -974,6 +1035,22 @@ def _get_config_dir(user=False, sys_prefix=False):
9741035
9751036
9761037def _get_nbextension_metadata (package ):
1038+ """Get the list of nbextension paths associated with a python package.
1039+
1040+ Returns a tuple of (the module, [{
1041+ 'section': 'notebook',
1042+ 'src': 'mockextension',
1043+ 'dest': '_mockdestination',
1044+ 'require': '_mockdestination/index'
1045+ }])
1046+
1047+ Parameters
1048+ ----------
1049+
1050+ package : str
1051+ Importable Python package (no dotted-notation!) exposing the
1052+ magic-named `_jupyter_nbextension_paths` function
1053+ """
9771054 m = __import__ (package )
9781055 if not hasattr (m , '_jupyter_nbextension_paths' ):
9791056 raise KeyError ('The Python package {} is not a valid nbextension' .format (package ))
@@ -982,17 +1059,39 @@ def _get_nbextension_metadata(package):
9821059
9831060
9841061def _read_config_data (user = False , sys_prefix = False ):
1062+ """Get the config for the current context
1063+
1064+ Returns the string to the enviornment
1065+
1066+ Parameters
1067+ ----------
1068+
1069+ user : bool [default: False]
1070+ Get the user's .jupyter config directory
1071+ sys_prefix : bool [default: False]
1072+ Get sys.prefix, i.e. ~/.envs/my-env/etc/jupyter
1073+ """
9851074 config_dir = _get_config_dir (user = user , sys_prefix = sys_prefix )
9861075 config_man = BaseJSONConfigManager (config_dir = config_dir )
9871076 return config_man .get ('jupyter_notebook_config' )
9881077
9891078
9901079def _write_config_data (data , user = False , sys_prefix = False ):
1080+ """Update the config for the current context
1081+
1082+ Parameters
1083+ ----------
1084+ data : object
1085+ An object which can be accepted by ConfigManager.update
1086+ user : bool [default: False]
1087+ Get the user's .jupyter config directory
1088+ sys_prefix : bool [default: False]
1089+ Get sys.prefix, i.e. ~/.envs/my-env/etc/jupyter
1090+ """
9911091 config_dir = _get_config_dir (user = user , sys_prefix = sys_prefix )
9921092 config_man = BaseJSONConfigManager (config_dir = config_dir )
9931093 config_man .update ('jupyter_notebook_config' , data )
994-
1094+
9951095
9961096if __name__ == '__main__' :
9971097 main ()
998-
0 commit comments