The PyPA recommended tool for installing Python packages.
91
Build a command-line tool that installs Python packages with different distribution format preferences and reports the installation details.
Package managers provide options to control whether pre-built binary distributions (wheels) or source distributions are used during installation. These options help with reproducible builds, debugging compatibility issues, and optimizing installation speed.
Create a Python script package_installer.py that:
Accepts command-line arguments:
--package <name>: Package name to install (required)--version <version>: Specific version to install (optional, defaults to latest)--format <format>: Distribution format preference - one of binary-only, source-only, or prefer-binary (required)--target <path>: Target directory for installation (required)--report <path>: Output file path for the installation report (default: install_report.json)Installs packages with format preferences:
--format:
binary-only: Install only from pre-built binary distributionssource-only: Force installation from source distributionsprefer-binary: Prefer binary distributions when availableGenerates a JSON report containing:
package: The package nameversion: The installed versionformat_preference: The format preference requestedinstalled_from: The distribution type used (wheel or source)install_path: The target installation directorytimestamp: ISO 8601 formatted timestampError handling:
Input:
python package_installer.py --package wheel --version 0.37.0 --format binary-only --target ./test_install1 --report test1.jsonExpected Output File (test1.json):
{
"package": "wheel",
"version": "0.37.0",
"format_preference": "binary-only",
"installed_from": "wheel",
"install_path": "./test_install1",
"timestamp": "2024-01-15T10:30:00Z"
}Input:
python package_installer.py --package six --version 1.16.0 --format source-only --target ./test_install2 --report test2.jsonExpected Output File (test2.json):
{
"package": "six",
"version": "1.16.0",
"format_preference": "source-only",
"installed_from": "source",
"install_path": "./test_install2",
"timestamp": "2024-01-15T10:31:00Z"
}Input:
python package_installer.py --package click --format prefer-binary --target ./test_install3Expected Output File (install_report.json):
{
"package": "click",
"version": "8.1.7",
"format_preference": "prefer-binary",
"installed_from": "wheel",
"install_path": "./test_install3",
"timestamp": "2024-01-15T10:32:00Z"
}Input:
python package_installer.py --package requests --format invalid --target ./test_install4Expected Behavior:
The Python Package Installer - provides package installation and management capabilities.
package_installer.py: Main implementation filetest_package_installer.py: Test file containing automated tests for the test casesInstall with Tessl CLI
npx tessl i tessl/pypi-pipevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10