Skip to content

Commit 6632f92

Browse files
Add pip auto-updater script with support for outdated package detection and upgrade
1 parent 4fa945c commit 6632f92

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

pip_auto_updater/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# 🛠️ Pip Auto-Updater
2+
3+
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.
4+
5+
## Features
6+
7+
- Identifies all outdated packages using `pip list --outdated` excluding built-ins.
8+
- Iteratively upgrades each package via `pip install --upgrade`, ensuring minimal disruption.
9+
---
10+
11+
## Usage
12+
13+
### Run the script directly:
14+
```bash
15+
python pip_auto_updater/update_packages.py
16+
```
17+
18+
## Compatibility
19+
- Python 3.8+
20+
- Pip 21+
21+
22+
## Notes
23+
- Some packages may fail to update due to system-level constraints or dependency conflicts.
24+
- It’s recommended to run this inside a virtual environment to avoid breaking global installs.
25+
26+
## Author
27+
Ayush Srivastava
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import subprocess
2+
import sys
3+
4+
def update_outdated_packages():
5+
"""
6+
Updates all outdated third-party Python packages using pip.
7+
Built-in and system packages are excluded.
8+
"""
9+
try:
10+
# Get list of outdated packages
11+
result = subprocess.run(
12+
[sys.executable, "-m", "pip", "list", "--outdated", "--format=json"],
13+
capture_output=True, text=True, check=True
14+
)
15+
outdated = eval(result.stdout) # JSON parsing without import for simplicity
16+
17+
if not outdated:
18+
print("All packages are up to date.")
19+
return
20+
21+
print(f"Found {len(outdated)} outdated packages. Updating...\n")
22+
23+
for pkg in outdated:
24+
name = pkg['name']
25+
current_version = pkg['version']
26+
latest_version = pkg['latest_version']
27+
print(f"Updating {name} ({current_version}{latest_version})...")
28+
29+
try:
30+
subprocess.run(
31+
[sys.executable, "-m", "pip", "install", "--upgrade", name],
32+
check=True
33+
)
34+
print(f"✅ {name} updated successfully.\n")
35+
except subprocess.CalledProcessError:
36+
print(f"Failed to update {name}. Skipping...\n")
37+
38+
except Exception as e:
39+
print(f"Error occurred: {e}")
40+
41+
update_outdated_packages()

0 commit comments

Comments
 (0)