Skip to content

Commit

Permalink
Raw Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
achillesrasquinha committed Jan 27, 2019
1 parent 173ff91 commit fc04547
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 23 deletions.
14 changes: 0 additions & 14 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,14 +0,0 @@
pylint
autopep8
ipython
twine
bumpversion
vulture
safety
pytest
pytest-cov
pytest-xdist
pytest-sugar
pytest-travis-fold
tox-travis
coveralls
6 changes: 5 additions & 1 deletion src/pipupgrade/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ def get_parser():
)
parser.add_argument("-r", "--requirements",
action = "append",
help = "Path to requirements.txt file."
help = "Path(s) to requirements.txt file."
)
parser.add_argument("-i", "--interactive",
action = "store_true",
help = "Interactive Mode"
)
parser.add_argument("-p", "--project",
action = "append",
help = "Path(s) to Project"
)
parser.add_argument("-u", "--user",
action = "store_true",
help = "Install to the Python user install directory for environment \
Expand Down
66 changes: 58 additions & 8 deletions src/pipupgrade/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
# imports - standard imports
import sys, os, os.path as osp
import re
import glob

# imports - module imports
from pipupgrade.commands.util import cli_format
from pipupgrade.table import Table
from pipupgrade.util.string import pluralize
from pipupgrade.util.string import strip, pluralize
from pipupgrade.util.system import read, write
from pipupgrade import _pip, request as req, cli, semver
from pipupgrade.__attr__ import __name__
Expand Down Expand Up @@ -91,22 +92,71 @@ def _update_requirements(path, package):
)

f.write(line)
except Exception:
except Exception as e:
write(path, content)

def _get_included_requirements(fname):
path = osp.realpath(fname)



@cli.command
def command(requirements = [ ], latest = False, self = False, user = False, check = False, interactive = False, yes = False, no_color = True, verbose = False):
def command(
requirements = [ ],
project = None,
latest = False,
self = False,
user = False,
check = False,
interactive = False,
yes = False,
no_color = True,
verbose = False
):
cli.echo(cli_format("Checking...", cli.YELLOW))

registry = dict()

if self:
package = __name__

_pip.install(package, user = user, quiet = not verbose, no_cache = True, upgrade = True)
_pip.install(package, user = user, quiet = not verbose, no_cache_dir = True, upgrade = True)
cli.echo("%s upto date." % cli_format(package, cli.CYAN))
else:
if project:
for p in project:
projpath = osp.abspath(p)
requirements = requirements or [ ]

# COLLECT ALL THE REQUIREMENTS FILES!

# Detect Requirements Files
# Check requirements*.txt files in current directory.
for requirement in glob.glob(osp.join(projpath, "requirements*.txt")):
requirements.insert(0, requirement)

# Check if requirements is a directory
if osp.isdir(osp.join(projpath, "requirements")):
for requirement in glob.glob(osp.join(projpath, "requirements", "*.txt")):
requirements.insert(0, requirement)

if requirements:
for requirement in requirements:
path = osp.realpath(requirement)

if not osp.exists(path):
cli.echo(cli_format("{} not found.".format(path), cli.RED))
sys.exit(os.EX_NOINPUT)
else:
filenames = _get_included_requirements(requirement)

# with open(path) as f:
# content = f.readlines()

# for line in content:
# if strip(line).startswith("-r "):
# # fname =

for requirement in requirements:
path = osp.realpath(requirement)

Expand All @@ -124,6 +174,7 @@ def command(requirements = [ ], latest = False, self = False, user = False, chec

for package in packages:
package = PackageInfo(package)
package.source = source

if package.latest_version and package.current_version != package.latest_version:
diff_type = None
Expand All @@ -140,11 +191,13 @@ def command(requirements = [ ], latest = False, self = False, user = False, chec
cli_format(package.home_page, cli.CYAN)
])

package.source = source
package.diff_type = diff_type

dinfo.append(package)

if package.source != "__INSTALLED__":
_update_requirements(package.source, package)

stitle = "Installed Distributions" if source == "__INSTALLED__" else source

if not table.empty:
Expand Down Expand Up @@ -187,8 +240,5 @@ def command(requirements = [ ], latest = False, self = False, user = False, chec
, cli.BOLD))

_pip.install(package.name, user = user, quiet = not verbose, no_cache_dir = True, upgrade = True)

if package.source != "__INSTALLED__":
_update_requirements(package.source, package)
else:
cli.echo("%s upto date." % cli_format(stitle, cli.CYAN))
6 changes: 6 additions & 0 deletions src/pipupgrade/util/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

_REGEX_ANSI_ESCAPE = re.compile(r"\x1B\[[0-?]*[ -/]*[@-~]")

def strip(string):
string = string.lstrip()
string = string.rstrip()

return string

def strip_ansi(string):
string = _REGEX_ANSI_ESCAPE.sub("", string)
return string
Expand Down

0 comments on commit fc04547

Please sign in to comment.