Skip to content

Commit

Permalink
adjusting where inconsistency is set. if we are inconsistent, but the… (
Browse files Browse the repository at this point in the history
#7152)

* adjusting where inconsistency is set. if we are inconsistent, but there is no lock file, we know that we have to exit with code 1

* updating logic to account for edge case where frozen file exists, but doesn't have any contents. we will falsely miss setting exitcode(1)

* Fix for bailing out from writing a lockfile with inconsistencies

* Fix writing a lockfile on Python2

* Improve verbose output formatting

* Display dependency consistency msg in all cases
  • Loading branch information
scbedd authored Sep 10, 2019
1 parent dcaa3c2 commit 54a1af0
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions scripts/analyze_deps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
from __future__ import print_function, unicode_literals
import argparse
import ast
from datetime import datetime
Expand Down Expand Up @@ -183,21 +183,24 @@ def render_report(output_path, report_context):
packages, dependencies = get_lib_deps(base_dir)

if args.verbose:
print('Packages analyzed:')
print('Packages analyzed')
print('=================')
for package in sorted(packages.keys()):
info = packages[package]
print("%s %s" % (package, info['version']))
print(" from %s" % (info['source']))

print('\n\nRequirements discovered:')
print('\n\nRequirements discovered')
print('=======================')
for requirement in sorted(dependencies.keys()):
specs = dependencies[requirement]
libs = []
print('\n%s' % (requirement))
print('%s' % (requirement))
for spec in specs.keys():
print('%s' % (spec if spec else '(empty)'))
for lib in specs[spec]:
print(' * %s' % (lib))
print('')

inconsistent = []
for requirement in sorted(dependencies.keys()):
Expand All @@ -206,32 +209,27 @@ def render_report(output_path, report_context):
if num_specs == 1:
continue

if not inconsistent and args.verbose:
print('\nInconsistencies detected')
print('========================')

inconsistent.append(requirement)
if args.verbose:
print("\n\nRequirement '%s' has %s unique specifiers:" % (requirement, num_specs))
print("Requirement '%s' has %s unique specifiers:" % (requirement, num_specs))
for spec in sorted(specs.keys()):
libs = specs[spec]
friendly_spec = '(none)' if spec == '' else spec
print("\n '%s'" % (friendly_spec))
print(" '%s'" % (friendly_spec))
print(' ' + ('-' * (len(friendly_spec) + 2)))
for lib in sorted(libs):
print(' * %s' % (lib))

exitcode = 0
if inconsistent:
if not args.verbose:
print('\n\nIncompatible dependency versions detected in libraries, run this script with --verbose for details')
else:
print('\n')
exitcode = 1
else:
print('\n\nAll library dependencies verified, no incompatible versions detected')
print('')

frozen_filename = os.path.join(base_dir, 'shared_requirements.txt')
if args.freeze:
if exitcode != 0:
if inconsistent:
print('Unable to freeze requirements due to incompatible dependency versions')
sys.exit(exitcode)
sys.exit(1)
else:
with io.open(frozen_filename, 'w', encoding='utf-8') as frozen_file:
for requirement in sorted(dependencies.keys()):
Expand Down Expand Up @@ -260,6 +258,7 @@ def render_report(output_path, report_context):

missing_reqs, new_reqs, changed_reqs = {}, {}, {}
non_overridden_reqs_count = 0
exitcode = 0
if frozen:
flat_deps = {req: sorted(dependencies[req].keys()) for req in dependencies}
missing_reqs, new_reqs, changed_reqs = dict_compare(frozen, flat_deps)
Expand Down Expand Up @@ -302,6 +301,20 @@ def render_report(output_path, report_context):
print("\nThe following libraries declare requirement '%s' which does not match the frozen requirement '%s':" % (changed_req + spec, changed_req + frozen_specs[0]))
for lib in non_overridden_libs:
print(" * %s" % (lib))
if exitcode == 0:
if args.verbose:
print('')
print('All library dependencies validated against frozen requirements')
elif not args.verbose:
print('Library dependencies do not match frozen requirements, run this script with --verbose for details')
elif inconsistent:
exitcode = 1

if exitcode == 1:
if not args.verbose:
print('\nIncompatible dependency versions detected in libraries, run this script with --verbose for details')
else:
print('\nAll library dependencies verified, no incompatible versions detected')

if args.out:
external = [k for k in dependencies if k not in packages and not should_skip_lib(k)]
Expand Down Expand Up @@ -329,9 +342,4 @@ def display_order(k):
'repo_name': 'azure-sdk-for-python'
})

if exitcode == 0:
print('All library dependencies validated against frozen requirements')
elif not args.verbose:
print('Library dependencies do not match frozen requirements, run this script with --verbose for details')

sys.exit(exitcode)

0 comments on commit 54a1af0

Please sign in to comment.