PK9~aJ4jupyter_conf_search/__init__.py"""Utility for searching through jupyter configuration files, using jupyter's path definitions to find their locations dynamically. """ __version__="0.4.3" from .jupyter_conf_search import main PKG2J{//jupyter_conf_search/__main__.pyfrom .jupyter_conf_search import main main() PKe2J4??*jupyter_conf_search/jupyter_conf_search.pyimport jupyter_core.paths as jpaths import glob import os import sys import re def valid_conf_file(file_name): # replace with canonical config validation checker if not os.path.isfile(file_name): return False if os.path.splitext(file_name)[1]=='.py': return True if os.path.splitext(file_name)[1]=='.json': return True canonical_names_regex = re.compile(r"jupyter_(\w*_|)config") def valid_local_conf_file(file_path): file_name = os.path.splitext(os.path.split(file_path)[1])[0] return valid_conf_file(file_path) and canonical_names_regex.match(file_name) def search_jupyter_paths(search_term=''): conf_path_list = [] for dir in jpaths.jupyter_config_path(): conf_path_list.extend(glob.glob(dir+"/**", recursive=True)) conf_file_list = [f for f in conf_path_list if valid_conf_file(f)] local_path_list = glob.glob(os.getcwd()+"/**", recursive=True) conf_file_list.extend([f for f in local_path_list if valid_local_conf_file(f)]) # go through files, # if search term found in file # print name, line_no, content conf_file_list.reverse() for file_name in conf_file_list: if len(search_term)>0: print_indexed_content(file_name=file_name, search_term=search_term) else: print(file_name) def print_indexed_content(file_name='', search_term=''): with open(file_name,"r") as f: if search_term in f.read(): f.seek(0) line_numbers_match = [] for line_no, text in enumerate(f,1): if search_term in text: line_numbers_match.append((line_no,text.strip())) output = ["{}: {}".format(x,y) for x,y in line_numbers_match] print(file_name + "\n" + "\n".join(output),"\n") def main(): if len(sys.argv)==1: search_jupyter_paths() elif len(sys.argv)==2: search_jupyter_paths(sys.argv[1]) else: raise RuntimeError("You can only pass in a single string at this time.") if __name__ == "__main__": main() PK!HX2B4jupyter_conf_search-0.4.3.dist-info/entry_points.txtN+I/N.,()*-,I-J&%g(*`MPK!H;@QP)jupyter_conf_search-0.4.3.dist-info/WHEEL1 0 RZq+D-Dv;_[*7Fp ܦpv/fݞoL(*IPK!HyUX|,jupyter_conf_search-0.4.3.dist-info/METADATAMN@Eh"!8(a=} YQνGgF&^)DvJhD 0H%^]6>4BQ$\0)C:#g<&ly"$WPq$nhXc-PV),SHڣPKg#KݾbrVdu~w i♾2X򌛥#LE7n +n7S-~PK!HyGo^l*jupyter_conf_search-0.4.3.dist-info/RECORDͻr@@>ϲ"R@ $ܢ6 mAS9X؞|ٱM ;6;Ӕei#Dt p9sxS|p X$Ѷmw wt[ wx q.Ik?K'7:Yt=K$*OO56i=|[zr #  -k(ԻE gČDnc3 E5?kǴ(cwbRTlguX GR\ca%|>!@2?VE2Į%Ģ IޗoJ""67mQ~(0tH6|]œ̍%k־e/{/PK9~aJ4jupyter_conf_search/__init__.pyPKG2J{//jupyter_conf_search/__main__.pyPKe2J4??*ojupyter_conf_search/jupyter_conf_search.pyPK!HX2B4 jupyter_conf_search-0.4.3.dist-info/entry_points.txtPK!H;@QP)z jupyter_conf_search-0.4.3.dist-info/WHEELPK!HyUX|, jupyter_conf_search-0.4.3.dist-info/METADATAPK!HyGo^l*^ jupyter_conf_search-0.4.3.dist-info/RECORDPK]