Skip to content

Notebook parser extracts imports #6

@Yumeseeker

Description

@Yumeseeker

Description

Write a function that takes a Jupyter Notebook as input and extracts all imported libraries from code cells.

Requirements:

Read the notebook using nbformat
Iterate over all code cells
Identify import statements of the form import x and from x import y
Return a list of unique library names

Notes:

Use Python's ast module for parsing rather than regex where possible
Reference index_notebooks.py in the main PaleoPAL repo for how they handle this — specifically _names_defined_used() and IMPORT_RE
Write the algorithm as comments before implementing
Test manually on a few notebooks from PaleoBooks before automating

Acceptance Criteria:

Given a notebook, the function returns the correct list of top-level library names
Handles edge cases like import numpy as np, from pylipd import LiPD, and cells with Jupyter magics (%, !)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions