Skip to content

Commit ad79358

Browse files
committed
- v0.1.0 pre-release commit.
- Completed README.md. - New relevant screenshot in README.md. - Fixed bug causing incorrect results to display upon completion of option 1. - Attempt to fix "relative import" error in "setup_loggers.py" by moving log configuration/declaration back to `main.py` as new method. Signed-off-by: schlopp96 <71921821+schlopp96@users.noreply.github.com>
1 parent 41f190b commit ad79358

File tree

4 files changed

+134
-42
lines changed

4 files changed

+134
-42
lines changed

README.md

Lines changed: 87 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,98 @@
11
# UpgradePipPkgs
22

3-
- This is a small powershell script that will allow the user to upgrade _all_ outdated global pip packages at once.
3+
> Tool for upgrading all global `pip` packages with one command.
44
55
---
66

7-
## Full Repo Coming Soon
7+
## About
8+
9+
- **_`UpgradePipPkgs`_** can upgrade all of your `pip` packages using one of two methods:
10+
11+
**Method 1:**
12+
13+
> **First gather all outdated packages using the command `pip list --outdated`, then pass results to a list of outdated packages to be upgraded.**
14+
15+
- This method is generally more efficient than the following method, as only outdated packages are passed to upgrade process.
16+
- Unfortunately doesn't take into account package dependencies relying on specific package versions to function properly.
17+
18+
---
19+
20+
**Method 2:**
21+
22+
> **Iterate over _all_ installed packages, passing the command `pip install --upgrade {pkgname}` over each one.**
23+
24+
- This method takes more time overall, but is "safer".
25+
- "Safer" in this context meaning that package dependencies are corrected upon attempting upgrade on a package that specifies its dependencies, downgrading specific package versions where necessary.
26+
- Note that not all packages will be able to downgrade, as the order of packages upgraded is relevant to whether incorrect version dependencies are corrected.
27+
- For example, let's assume **`PackA`** requires **`PackB<=1.0.0`** as a dependency:
28+
1. **`PackA`** will be checked for available upgrade first, and will check for installed dependency pkg **`PackB<=1.0.0`**, installing it if not already installed.
29+
2. `PackB` is then checked, and has a new version available, `1.1.0`.
30+
3. `PackB-1.0.0` is then upgraded to `1.1.0`, but now `PackA` can't function correctly due to incorrect dependency version.
31+
4. This can easily be fixed by reinstalling `PackA` using the `pip` install command: "`pip install PackA`".
32+
33+
- You can review past results/program output in the application's log file, which can be found here:
34+
- `"~/UpgradePipPkgs/logs/output.log"`
35+
36+
---
37+
38+
## Installation
39+
40+
### Using PIP _(Recommended)_
41+
42+
> _Easiest_ method. Highly recommended over manual installation.
43+
44+
- To install _**`UpgradePipPkgs`**_ using `pip`, enter the following in your commandline environment:
45+
46+
```python
47+
> pip install UpgradePipPkgs
48+
```
49+
50+
- You should now be able to import/run _**`UpgradePipPkgs`**_ within your python environment by entering the following:
51+
52+
```python
53+
>>> from UpgradePipPkgs import upgrade_pip_pkgs
54+
...
55+
```
56+
57+
- Done!
58+
59+
---
60+
61+
### Manual Installation
62+
63+
> _Not_ recommended.
64+
65+
1. Before use, navigate to intended installation location, and create a new directory.
66+
2. Install all dependencies for this package within said directory using:
67+
68+
```python
69+
pip install -r requirements.txt
70+
```
71+
72+
3. Clone repository with the git client of your preference.
73+
- (Optional) move installation directory to `"path/to/Python/Libs/site_packages"` to be able to import this package to a Python program like any other importable package.
74+
75+
- Done!
76+
77+
---
78+
79+
## Usage
80+
81+
- In order to use _**`UpgradePipPkgs`**_, start by importing the module to your Python environment:
82+
83+
```python
84+
>>> from UpgradePipPkgs import upgrade_pip_pkgs
85+
```
86+
87+
- Call the `upgrade_pip_pkgs` function to start the application, and choose the method of operation by typing the option number, and press **[ENTER]**.
88+
89+
![alt](./img/README_screenshot.png)
890

991
---
1092

11-
Contact
93+
## Contact the Author
1294

13-
- Send me an email with any questions, concerns, comments, etc. to `schloppdaddy@gmail.com`
14-
- Project GitHub [repository](https://github.com/schlopp96/TotalPipUpgrade).
15-
- My GitHub [profile](https://github.com/schlopp96/)
95+
- If you have any questions, comments, or concerns that cannot be alleviated through the [project's GitHub repository "issues" tab](https://github.com/schlopp96/UpgradePipPkgs), please feel free to contact me through my email address:
96+
- `schloppdaddy@gmail.com`
1697

1798
---

UpgradePipPkgs/main.py

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22

3+
import logging
34
import subprocess
45
import sys
56
from os import chdir
@@ -8,21 +9,61 @@
89

910
from PyLoadBar import load
1011

11-
from setup_loggers import mainLogger, processLogger
12+
1213

1314
chdir(dirname(__file__))
1415

1516
__version__ = '0.1.0'
1617

1718
textborder: str = f'\n<{"*" * 120}>\n'
1819

20+
def config_logs(__file__) -> tuple[logging.Logger, logging.Logger]:
21+
"""Set program logging configuration and generate loggers.
22+
23+
---
24+
25+
Parameters:
26+
:param __file__: file to be logged.
27+
:type __file__: Any
28+
:return: program logging configuration.
29+
:rtype: tuple[Logger, Logger]
30+
"""
31+
# Log activity from file.
32+
mainLogger = logging.getLogger(__file__)
33+
mainLogger.setLevel(logging.INFO)
34+
35+
# Log activity from upgrade script `global_upgrade.ps1`.
36+
processLogger = logging.getLogger('Subprocess')
37+
processLogger.setLevel(logging.INFO)
38+
39+
# Handler for pre/post upgrade subprocess.
40+
mainFormatter = logging.Formatter(
41+
'[{asctime} :: {levelname} :: Line: {lineno}] - {message}\n', style='{')
42+
mainHandler = logging.FileHandler('./logs/output.log')
43+
mainHandler.setFormatter(mainFormatter)
44+
45+
# Handler for during upgrade subprocess
46+
processFormatter = logging.Formatter(
47+
'[{asctime} :: {levelname} :: {funcName}] - {message}\n', style='{')
48+
processHandler = logging.FileHandler('./logs/output.log')
49+
processHandler.setFormatter(processFormatter)
50+
51+
# Add handlers to both loggers.
52+
mainLogger.addHandler(mainHandler)
53+
processLogger.addHandler(processHandler)
54+
55+
return mainLogger,processLogger
56+
57+
# Set logger names.
58+
mainLogger, processLogger = config_logs(__file__)
59+
1960
def get_outdated_pkgs():
2061
"""Subprocess to retrieve outdated global pip packages using `pip list --outdated`.
2162
2263
---
2364
2465
Parameters:
25-
:return: retrieve and pass outdated global pip packages into a list for upgrading.
66+
:return: retrieve and pass outdated global pip packages to a list to be upgraded.
2667
:rtype: (List[str] | None)
2768
"""
2869
outdated_pkgs =[]
@@ -54,7 +95,6 @@ def upgrade_outdated(outdated_pkgs: list):
5495
:rtype: tuple[list, list] | None
5596
"""
5697
processLogger.info('Upgrading outdated pip packages...')
57-
5898
print('Upgrading outdated pip packages...\n')
5999

60100
processLogger.info('No. Package Version Latest Type Status ')
@@ -103,7 +143,7 @@ def upgrade_all():
103143
processLogger.info('Upgrading outdated pip packages using "brute force"...')
104144
print('Upgrading outdated pip packages using "brute force"...\n')
105145

106-
script_p = subprocess.Popen(['powershell.exe', './scripts/force_upgrade_pip_pkgs.ps1'], stdout=subprocess.PIPE, stderr = subprocess.STDOUT)
146+
script_p = subprocess.Popen(['powershell.exe', './scripts/force_upgrade_pip_pkgs.ps1'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
107147
with script_p.stdout:
108148
try:
109149
for line in iter(script_p.stdout.readline, b''):
@@ -160,13 +200,13 @@ def main() -> NoReturn | None:
160200
upgradelist, errorlist = upgrade_outdated(outdated_pkgs)
161201
total=len(outdated_pkgs)
162202
mainLogger.info('Successfully completed upgrade process!')
163-
mainLogger.info('\nSUMMARY:')
203+
mainLogger.info('SUMMARY:')
164204
mainLogger.info(f'No. of packages upgraded = {len(upgradelist)}/{total}')
165-
mainLogger.info(f'No. of upgrade errors = {len(upgradelist)}/{total}')
205+
mainLogger.info(f'No. of upgrade errors = {len(errorlist)}/{total}')
166206
print('\nSuccessfully completed upgrade process!')
167207
print('\nSUMMARY:')
168208
print(f'No. of packages upgraded = {len(upgradelist)}/{total}')
169-
print(f'No. of upgrade errors = {len(upgradelist)}/{total}')
209+
print(f'No. of upgrade errors = {len(errorlist)}/{total}')
170210
input('\nPress Enter to Exit.')
171211
return exitProgram(0)
172212
else:

UpgradePipPkgs/setup_loggers.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

img/README_screenshot.png

0 Bytes
Loading

0 commit comments

Comments
 (0)