diff --git a/pip_auto_updater/README.md b/pip_auto_updater/README.md new file mode 100644 index 000000000..be8a2b25d --- /dev/null +++ b/pip_auto_updater/README.md @@ -0,0 +1,27 @@ +# 🛠️ Pip Auto-Updater + +This script automates the process of updating all outdated Python packages installed via `pip`. It’s designed for developers and QA engineers who want to maintain clean, up-to-date environments with minimal manual effort. + +## Features + +- Identifies all outdated packages using `pip list --outdated` excluding built-ins. +- Iteratively upgrades each package via `pip install --upgrade`, ensuring minimal disruption. +--- + +## Usage + +### Run the script directly: +```bash +python pip_auto_updater/update_packages.py +``` + +## Compatibility +- Python 3.8+ +- Pip 21+ + +## Notes +- Some packages may fail to update due to system-level constraints or dependency conflicts. +- It’s recommended to run this inside a virtual environment to avoid breaking global installs. + +## Author +Ayush Srivastava \ No newline at end of file diff --git a/pip_auto_updater/update_packages.py b/pip_auto_updater/update_packages.py new file mode 100644 index 000000000..76c3124a0 --- /dev/null +++ b/pip_auto_updater/update_packages.py @@ -0,0 +1,41 @@ +import subprocess +import sys + +def update_outdated_packages(): + """ + Updates all outdated third-party Python packages using pip. + Built-in and system packages are excluded. + """ + try: + # Get list of outdated packages + result = subprocess.run( + [sys.executable, "-m", "pip", "list", "--outdated", "--format=json"], + capture_output=True, text=True, check=True + ) + outdated = eval(result.stdout) # JSON parsing without import for simplicity + + if not outdated: + print("All packages are up to date.") + return + + print(f"Found {len(outdated)} outdated packages. Updating...\n") + + for pkg in outdated: + name = pkg['name'] + current_version = pkg['version'] + latest_version = pkg['latest_version'] + print(f"Updating {name} ({current_version} → {latest_version})...") + + try: + subprocess.run( + [sys.executable, "-m", "pip", "install", "--upgrade", name], + check=True + ) + print(f"✅ {name} updated successfully.\n") + except subprocess.CalledProcessError: + print(f"Failed to update {name}. Skipping...\n") + + except Exception as e: + print(f"Error occurred: {e}") + +update_outdated_packages() \ No newline at end of file