Skip to content

Commit

Permalink
move clear cache function to tools
Browse files Browse the repository at this point in the history
  • Loading branch information
realiti4 committed Jan 3, 2022
1 parent 8d2f276 commit ff2de95
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
30 changes: 1 addition & 29 deletions pip_upgrade/main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import sys
import subprocess
import shutil
import argparse
import logging

from pathlib import Path
from pip_upgrade.tool import PipUpgrade
from pip_upgrade.tools import Config, cprint
from pip_upgrade.tools import Config, cprint, clear_cache

parser = argparse.ArgumentParser()
parser.add_argument('-e', '--exclude', nargs='+', help="Exclude packages you don't want to upgrade")
Expand All @@ -30,31 +27,6 @@ def check_venv(config):
if not args.novenv and config['conf']['novenv'] == 'false':
assert not sys.prefix == sys.base_prefix, 'Please use pip-upgrade in a virtualenv. If you would like to surpass this use pip-upgrade --novenv'

def clear_cache():
"""
Clears pip cache
"""
arg_list = [sys.executable, '-m', 'pip', 'cache', 'dir']
output = subprocess.check_output(arg_list)
output = output.decode("utf-8").replace("\n", "").replace("\r", "")

# Dev - print folder size
dev_path = Path(output)
cache_size = sum(f.stat().st_size for f in dev_path.glob('**/*') if f.is_file())
cache_size = int((cache_size / 1024) / 1024)

print(f'Folder will be deleted: {output} Size: {cache_size}MB')
confirm = input('Continue? (y/n): ')

if confirm.lower() == 'y':
try:
shutil.rmtree(output)
print('Cache is cleared..')
except Exception as e:
print(e)
else:
print('Aborted, if the folder was wrong, please fill an issue.')

def main(dev=False):
config = Config()

Expand Down
1 change: 1 addition & 0 deletions pip_upgrade/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pip_upgrade.tools.cprint import ColoredPrint
from pip_upgrade.tools.config import Config
from pip_upgrade.tools.clear_cache import clear_cache

# Initialize cprint
cprint = ColoredPrint()
31 changes: 31 additions & 0 deletions pip_upgrade/tools/clear_cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import sys
import subprocess
import shutil

from pathlib import Path


def clear_cache():
"""
Clears pip cache
"""
arg_list = [sys.executable, '-m', 'pip', 'cache', 'dir']
output = subprocess.check_output(arg_list)
output = output.decode("utf-8").replace("\n", "").replace("\r", "")

# Dev - print folder size
dev_path = Path(output)
cache_size = sum(f.stat().st_size for f in dev_path.glob('**/*') if f.is_file())
cache_size = int((cache_size / 1024) / 1024)

print(f'Folder will be deleted: {output} Size: {cache_size}MB')
confirm = input('Continue? (y/n): ')

if confirm.lower() == 'y':
try:
shutil.rmtree(output)
print('Cache is cleared..')
except Exception as e:
print(e)
else:
print('Aborted, if the folder was wrong, please fill an issue.')
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pip-upgrade-tool",
version="0.7.1",
version="0.7.2",
author="Onur Cetinkol",
author_email="realiti44@gmail.com",
description="An easy tool for upgrading all of your packages while not breaking dependencies",
Expand Down

0 comments on commit ff2de95

Please sign in to comment.