imports

package
v0.0.0-...-e238554 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package imports provides automatic detection of Python package imports.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectRequirements

func DetectRequirements(code string) string

DetectRequirements analyzes Python code and returns a requirements.txt string containing all detected third-party packages.

The function: 1. Parses import statements from the code 2. Filters out standard library modules 3. Maps module names to pip package names (e.g., PIL -> Pillow) 4. Returns a newline-separated list of packages

If no third-party packages are detected, an empty string is returned.

func GetPackageName

func GetPackageName(module string) string

GetPackageName returns the pip package name for a given Python module. If no mapping exists, the module name is returned as-is (works for most packages).

func IsStdlib

func IsStdlib(module string) bool

IsStdlib returns true if the module name is part of the Python standard library.

func MergeRequirements

func MergeRequirements(detected, userProvided string) string

MergeRequirements merges auto-detected requirements with user-provided ones. User-provided requirements take precedence (appear first, may have version pins).

func ParseImports

func ParseImports(code string) []string

ParseImports extracts all imported module names from Python code. It handles: - import X - import X as Y - import X, Y, Z - from X import Y - from X.submodule import Y

It ignores imports inside string literals and comments.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL