pyimportparse
A rust crate to parse python imports (ignoring the rest of the code).
Motivation:
- For fun/interest.
- Lack of other tool:
- Presently RustPython/Parser does not support Python 3.12+.
- Presently Ruff Python Parser is not published publicly as a crate.
Use with care. I've run the parser over the Django codebase and the results suggests that all imports were successfully parsed. However, there could still be cases where the parser does not behave correctly.
use ;
let code = r#"
import a
from b import c
from .d import (e, f)
from ..g import *
if TYPE_CHECKING:
import h
def foo():
import i
"#;
let imports = parse_imports.unwrap;
assert_eq!;