Skip to content

Commit

Permalink
Merge pull request #13 from realiti4/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
realiti4 authored Dec 1, 2021
2 parents bddeeb3 + f72b4f7 commit ff7e06e
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 10 deletions.
13 changes: 11 additions & 2 deletions pip_upgrade/dependencies_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ def get_dependencies(self):
try:
pkg_store = self.dict[pkg_name.lower()]
except Exception as e:
raise e
if '_' in pkg_name: # Fix for '_'
pkg_name = pkg_name.replace('_', '-')
try:
pkg_store = self.dict[pkg_name]
except Exception as e:
raise e

pkg_store.current_version = current_version
pkg_store.latest_version = latest_version
Expand Down Expand Up @@ -104,4 +109,8 @@ def retrieve_dependencies(self):
# raise e
print(f'Skipping {name}, warning: Name mismatch. This will be improved. Manually upgrade if needed')


def check_name_in_dict(self):
"""
Case and '_', '-' checks. Returns the true name on dict
"""
return
11 changes: 8 additions & 3 deletions pip_upgrade/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pathlib import Path
from pip_upgrade.tool import PipUpgrade
from pip_upgrade.utils.config import Config
from pip_upgrade.tools import Config

parser = argparse.ArgumentParser()
parser.add_argument('-e', '--exclude', nargs='+', help="Exclude packages you don't want to upgrade")
Expand All @@ -15,6 +15,7 @@
parser.add_argument('--clean', action='store_true', help="Clears pip's cache")
parser.add_argument('-y', '--yes', action='store_true', help="Accept all upgrades and skip user prompt")
parser.add_argument('--reset-config', action='store_true', help='Reset config file to default')
parser.add_argument('--dev', action='store_true', help="Doesn't actually call upgrade at the end")
parser.add_argument('-q', '--query', help="Query package dependency info from pypi")

args = parser.parse_args()
Expand Down Expand Up @@ -53,9 +54,13 @@ def clear_cache():
else:
print('Aborted, if the folder was wrong, please fill an issue.')

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

if dev:
print('Developer Mode')
args.dev = True

if args.reset_config:
config._reset()
sys.exit()
Expand All @@ -72,4 +77,4 @@ def main():
pip_upgrade.upgrade()

if __name__ == "__main__":
main()
main(dev=False)
7 changes: 4 additions & 3 deletions pip_upgrade/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import subprocess

from pip_upgrade.dependencies_base import DependenciesBase
from pip_upgrade.tools import cprint


class PipUpgrade(DependenciesBase):
Expand Down Expand Up @@ -132,8 +133,7 @@ def upgrade(self):

if len(packages) > 0:
# Info
print(f"{self.colored}These packages will be upgraded: \033[m{list(packages.keys())}")
# print(f'These packages will be upgraded: {list(packages.keys())}')
cprint('These packages will be upgraded: ', list(packages.keys()), color='green')
if self.restorable:
restore = self.config['restore']['last_exclude']
print(f'(-r, --repeat : -e {restore})')
Expand All @@ -145,13 +145,14 @@ def upgrade(self):
packages = list(packages.items())
packages = [''.join(x) for x in packages]

if cont_upgrade:
if cont_upgrade and not self.args.dev:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-U', *packages])

print('All packages are up to date! 🎉')

if self.self_check:
print("A new update avaliable for pip-upgrade-tool.\nPlease manually upgrade the tool using 'python -m pip install -U pip-upgrade-tool'")
# cprint("A new update avaliable for pip-upgrade-tool.\nPlease manually upgrade the tool using 'python -m pip install -U pip-upgrade-tool'", color='yellow')

def _help(self):
print("")
Expand Down
5 changes: 5 additions & 0 deletions pip_upgrade/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from pip_upgrade.tools.cprint import ColoredPrint
from pip_upgrade.tools.config import Config

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

class ColoredPrint():
def __init__(self):
self.enabled = True
self.color_dict = {
'green': '\033[32m',
'yellow': 'notimplemented',
'default': '\033[m'
}
if not self.terminal_check:
self.enabled = False

def terminal_check(self):
"""Don't print colored if it is cmd"""
return True

def __call__(self, *input, color='green', disabled=False):
if disabled or not self.enabled:
print(*input)
else:
if isinstance(input, tuple):
print(f"{self.color_dict[color]}{input[0]}{self.color_dict['default']}", *input[1:])
else:
print(f"{self.color_dict[color]}{input}{self.color_dict['default']}")

if __name__ == '__main__':
cprint = ColoredPrint()
cprint('heey', 'ha')
print('de')
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions 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.6.1",
version="0.6.2",
author="Onur Cetinkol",
author_email="realiti44@gmail.com",
description="An easy tool for upgrading all of your packages while not breaking dependencies",
Expand All @@ -21,6 +21,6 @@
"Operating System :: OS Independent",
],
python_requires='>=3.6',
packages=["pip_upgrade", "pip_upgrade.utils"],
packages=["pip_upgrade", "pip_upgrade.tools"],
install_requires=["packaging"],
)
31 changes: 31 additions & 0 deletions test/run_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest
import argparse

from pip_upgrade.tool import PipUpgrade
from pip_upgrade.utils.config import Config


parser = argparse.ArgumentParser()
parser.add_argument('-e', '--exclude', nargs='+', help="Exclude packages you don't want to upgrade")
parser.add_argument('--local', action='store_true', help="Upgrades local packages as well")
parser.add_argument('--novenv', action='store_true', help="Disables venv check")
parser.add_argument('--clear', action='store_true', help="Clears pip's cache") # Deprecated
parser.add_argument('--clean', action='store_true', help="Clears pip's cache")
parser.add_argument('-y', '--yes', action='store_true', help="Accept all upgrades and skip user prompt")
parser.add_argument('--reset-config', action='store_true', help='Reset config file to default')
parser.add_argument('--dev', action='store_true', help="Doesn't actually call upgrade at the end")

args = parser.parse_args()

def test_main():
config = Config()

args.dev = True
args.yes = True

pip_upgrade = PipUpgrade(args, config)

pip_upgrade.get_dependencies()

pip_upgrade.upgrade()

0 comments on commit ff7e06e

Please sign in to comment.