Skip to content

Commit

Permalink
Merge pull request #16 from jessamynsmith/master
Browse files Browse the repository at this point in the history
Optionally return an error code
  • Loading branch information
mattrobenolt committed Feb 8, 2015
2 parents 3c4cd07 + 2ce05f7 commit 134b90f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/piplint/__init__.py
Expand Up @@ -36,7 +36,7 @@ def disable(self):
self.ENDC = u''


def check_requirements(requirement_files, strict=False, verbose=False,
def check_requirements(requirement_files, strict=False, error_on_extras=False, verbose=False,
venv=None, do_colour=False):
"""
Given a list of requirements files, checks them against the installed
Expand Down Expand Up @@ -176,6 +176,7 @@ def valid_version(version, compare, r_version):
errors.append("%sRequirement %r not installed in virtualenv.%s"
% (colour.FAIL, r_package, colour.ENDC))

code = 0
if unknown_reqs:
print("\nFor debugging purposes, the following packages are installed but not in the requirements file(s):")
unknown_reqs_with_versions = []
Expand All @@ -187,18 +188,20 @@ def valid_version(version, compare, r_version):
print("%s%s%s\n" % (colour.WARNING,
"\n".join(sorted(unknown_reqs_with_versions)),
colour.ENDC))
if error_on_extras:
code = 2

if errors:
print("Errors found:")
print('\n'.join(errors))
print("You must correct your environment before committing (and running tests).\n")
return 1
code = 1

if not errors and not unknown_reqs:
print("%sNo errors found; all packages accounted for!%s"
% (colour.OKGREEN, colour.ENDC))

return 0
return code


def main():
Expand All @@ -212,6 +215,9 @@ def main():
cli_parser.add_argument('-s', '--strict', action='store_true',
default=False,
help='strict matching of package names')
cli_parser.add_argument('-x', '--error-on-extras', action='store_true',
default=False,
help='return error if extra packages are installed in virtualenv')
cli_parser.add_argument('-v', '--verbose', action='store_true',
default=False, help='show status of all packages')
cli_parser.add_argument('file', nargs='+',
Expand All @@ -220,6 +226,7 @@ def main():

# call the main function to kick off the real work
code = check_requirements(cli_args.file, strict=cli_args.strict,
error_on_extras=cli_args.error_on_extras,
verbose=cli_args.verbose, venv=cli_args.venv,
do_colour=cli_args.colour,)
sys.exit(code)
Expand Down

0 comments on commit 134b90f

Please sign in to comment.