Package: headergen
HeaderGenHeaderGen is a tool-based approach to enhance the comprehension and navigation of undocumented Python based Jupyter notebooks by automatically creating a narrative structure in the notebook.Data scientists build an ML-based solution notebook by first preparing the data, then extracting key features, and then creating and training the model. HeaderGen leverages the implicit narrative structure of an ML notebook to add structural headers as annotations to the notebook.Install HeaderGenpip install headergenFeaturesAutomated Markdown Header Insertion:Through a taxonomy for machine-learning operations, HeaderGen annotates code cells with relevant markdown headers.Function Call Taxonomy:Methodically classifies function calls based on a machine-learning operations taxonomy.Advanced Call Graph Analysis:Enhances PyCG framework with flow-sensitivity and external library return-type resolution.Precision in External Libraries:capability to accurately resolve function return types from external libraries using typestubs.Syntax Pattern Matching:Employs type data for pattern matching.CLI UsagegenerateCommand:Generate the HeaderGen annotated notebook in the current directory. Note that the caches will be created the first time HeaderGen is run.headergengenerate-i/path/to/input.ipynbGenerate a JSON metadata file that includes various analysis information, use the --json_output or -j flag.headergengenerate-i/path/to/input.ipynb-o/path/to/output/-jtypesCommand:Run type inference on the file and fetch type information.headergentypes-i/path/to/input.ipynbGenerate a JSON file with type information, use the --json_output or -j flag.headergentypes-i/path/to/input.ipynb-o/path/to/output/-jserverCommand:Starting the server is straightforward:headergen serverThis will start the Uvicorn server listening on host 0.0.0.0 and port 54068.get_analysis_notebook Endpoint:This endpoint returns the analysis of the specified notebook or python script as a JSON response containing analysis data like cell_callsites and block_mapping.Example using curl:curl "http://0.0.0.0:54068/get_analysis_notebook?file_path=/absolute/path/to/your/file.ipynb"get_types Endpoint:This endpoint returns type information of the specified notebook or python script as a JSON response.Example using curl:curl "http://0.0.0.0:54068/get_types?file_path=/absolute/path/to/your/file.ipynb"generate_annotated_notebook Endpoint:This endpoint returns the annotated notebook based on the analysis. The response will be a file download.Example using curl:curl "http://0.0.0.0:54068/generate_annotated_notebook?file_path=/absolute/path/to/your/file.ipynb" --output annotated_file.ipynbFolder Structurecallsites-jupyternb-micro-benchmark: Micro benchmarkcallsites-jupyternb-real-world-benchmark: Real-world benchmarkevaluation: Contains manual header annotation and user study resultsframework_models: Function calls to ML Taxonomy mappingtypestub-database: Type-stbs for ML librariesheadergen: Source code of HeaderGenpycg_extended: Source code of extended PyCGheadergen-extension: Jupyter notebook plugin for HGheadergen_output: Folder where the generated notebooks from the docker container are stored1. Build containerGet source filesgit clone --recursive
git submodule update --init --recursive
git pull --recurse-submodulesLinuxdocker build -t headergen .
docker run -v {$PWD}/headergen_output:/headergen_output -it headergen bashWindowsdocker build -t headergen .
docker run -v "%cd%"/headergen_output:/headergen_output -it headergen bash2. Run HeaderGen benchmarks from inside contatinerOutput generated from the following commands, such as annotated notebooks, reports, callsites, headers, etc, are stored in the local folderheadergen_outputafter the following commands are done executing.Micro Benchmark (generates a csv file with results)make ROOT_PATH=/app/HeaderGen microbenchReal-world Benchmark (generates annotated notebooks and csv file that reproduce table 2)make ROOT_PATH=/app/HeaderGen realworldbenchBoth Benchmarksmake ROOT_PATH=/app/HeaderGen allClean generated outputmake cleanThis repo contains code for the paper"Enhancing Comprehension and Navigation in Jupyter Notebooks with Static Analysis"published at theSANER Conference 2023.