CodeVetter · Repo Unpack · Behavior traces
pypa/pip
Three concrete flows were followed through their implementation: CLI startup, installation, and configuration persistence. Startup creates a command after parsing global options, and the command establishes shared runtime contexts. Installation branches after resolution for reports and dry runs, then prepares, builds, orders, and installs distributions. Configuration mutation selects a file, loads it, changes a parser, saves it, and affects subsequent option parsing.
- Startup: python -m pip removes a leading empty/current-directory sys.path entry, imports cli.main.main(), installs warning logging, invokes autocomplete(), then calls parse_command().
- Startup continuation: parse_command() validates the command or exits for help/version; main() sets locale and calls create_command(), then Command.main() enters contexts, parses options, configures logging, and dispatches through _run_wrapper().
- Install entry: InstallCommand.run() rejects --user with --target, conditionally checks externally managed environments, chooses user-install behavior, and creates the session, target-aware finder, build tracker, and temporary build directory.
- Install resolution: run() calls get_requirements(), constructs WheelCache, preparer, and resolver, then calls resolve(); Resolver collects roots, creates PipProvider and a reporter, and invokes resolvelib with a 200000-round ceiling.
- Install branch: after resolution, --report writes InstallationReport JSON to a file or stdout; --dry-run prints the planned packages and returns before prepare_linked_requirements_more(), wheel building, and installation.
- Install mutation: preparation completes, non-wheel requirements are built, get_installation_order() orders dependencies first, and install_given_reqs() replaces packages individually; each requirement calls install_wheel(), with failed replacement triggering rollback of its previous uninstall.
- Configuration mutation: config set enters ConfigurationCommand.run(), selects one explicit scope or defaults to an existing site file then user scope, loads Configuration, and calls set_name_value() → set_value() → _save_configuration() → save().
- Configuration persistence continuation: save() ensures the parent directory and writes modified parsers; a later command reloads those files in get_default_values(), applies section precedence, and validates resulting defaults before dispatch.