From 8a29e4f69e036f837d3ac0bc776666f20d78032b Mon Sep 17 00:00:00 2001 From: scbedd <45376673+scbedd@users.noreply.github.com> Date: Mon, 9 Sep 2019 15:51:27 -0700 Subject: [PATCH 1/6] 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 --- scripts/analyze_deps.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/analyze_deps.py b/scripts/analyze_deps.py index c8d1ef7f3055..b1309df63a5c 100755 --- a/scripts/analyze_deps.py +++ b/scripts/analyze_deps.py @@ -223,7 +223,6 @@ def render_report(output_path, report_context): 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') @@ -257,6 +256,8 @@ def render_report(output_path, report_context): frozen[req_name] = [spec] except: print('Unable to open shared_requirements.txt, shared requirements have not been validated') + if inconsistent: + exitcode = 1 missing_reqs, new_reqs, changed_reqs = {}, {}, {} non_overridden_reqs_count = 0 From 955e9090d6b60a6da68eef3167dbc87e17dce28e Mon Sep 17 00:00:00 2001 From: scbedd <45376673+scbedd@users.noreply.github.com> Date: Mon, 9 Sep 2019 16:05:12 -0700 Subject: [PATCH 2/6] updating logic to account for edge case where frozen file exists, but doesn't have any contents. we will falsely miss setting exitcode(1) --- scripts/analyze_deps.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/scripts/analyze_deps.py b/scripts/analyze_deps.py index b1309df63a5c..8fbbf94f2c70 100755 --- a/scripts/analyze_deps.py +++ b/scripts/analyze_deps.py @@ -218,13 +218,6 @@ def render_report(output_path, report_context): 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') - else: - print('\n\nAll library dependencies verified, no incompatible versions detected') frozen_filename = os.path.join(base_dir, 'shared_requirements.txt') if args.freeze: @@ -256,9 +249,7 @@ def render_report(output_path, report_context): frozen[req_name] = [spec] except: print('Unable to open shared_requirements.txt, shared requirements have not been validated') - if inconsistent: - exitcode = 1 - + missing_reqs, new_reqs, changed_reqs = {}, {}, {} non_overridden_reqs_count = 0 if frozen: @@ -303,6 +294,14 @@ 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)) + elif inconsistent: + exitcode = 1 + if not args.verbose: + print('\n\nIncompatible dependency versions detected in libraries, run this script with --verbose for details') + else: + print('\n') + else: + print('\n\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)] From f98747df0b4a9644e49b8f680470cd6ac555ced4 Mon Sep 17 00:00:00 2001 From: Brandon Siegel Date: Mon, 9 Sep 2019 16:45:10 -0700 Subject: [PATCH 3/6] Fix for bailing out from writing a lockfile with inconsistencies --- scripts/analyze_deps.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/analyze_deps.py b/scripts/analyze_deps.py index 8fbbf94f2c70..31f20947135a 100755 --- a/scripts/analyze_deps.py +++ b/scripts/analyze_deps.py @@ -217,13 +217,11 @@ def render_report(output_path, report_context): for lib in sorted(libs): print(' * %s' % (lib)) - exitcode = 0 - 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()): @@ -249,9 +247,10 @@ def render_report(output_path, report_context): frozen[req_name] = [spec] except: print('Unable to open shared_requirements.txt, shared requirements have not been validated') - + 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) From b7266b8107f2c863557b30f3d096b046ec6e58cc Mon Sep 17 00:00:00 2001 From: Brandon Siegel Date: Mon, 9 Sep 2019 16:45:28 -0700 Subject: [PATCH 4/6] Fix writing a lockfile on Python2 --- scripts/analyze_deps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/analyze_deps.py b/scripts/analyze_deps.py index 31f20947135a..32c24006b7f8 100755 --- a/scripts/analyze_deps.py +++ b/scripts/analyze_deps.py @@ -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 From 647c54ecefc3b97257b2591ef7293b2cb01940e2 Mon Sep 17 00:00:00 2001 From: Brandon Siegel Date: Mon, 9 Sep 2019 16:55:01 -0700 Subject: [PATCH 5/6] Improve verbose output formatting --- scripts/analyze_deps.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/scripts/analyze_deps.py b/scripts/analyze_deps.py index 32c24006b7f8..c8080413377a 100755 --- a/scripts/analyze_deps.py +++ b/scripts/analyze_deps.py @@ -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()): @@ -206,16 +209,21 @@ 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)) + print('') frozen_filename = os.path.join(base_dir, 'shared_requirements.txt') if args.freeze: @@ -296,11 +304,9 @@ def render_report(output_path, report_context): elif inconsistent: exitcode = 1 if not args.verbose: - print('\n\nIncompatible dependency versions detected in libraries, run this script with --verbose for details') - else: - print('\n') + print('\nIncompatible dependency versions detected in libraries, run this script with --verbose for details') else: - print('\n\nAll library dependencies verified, no incompatible versions detected') + 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)] @@ -329,6 +335,8 @@ def display_order(k): }) 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') From 47b1e879a338e321d7088ed8ccda4f05c6aa3626 Mon Sep 17 00:00:00 2001 From: Brandon Siegel Date: Mon, 9 Sep 2019 16:55:29 -0700 Subject: [PATCH 6/6] Display dependency consistency msg in all cases --- scripts/analyze_deps.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/analyze_deps.py b/scripts/analyze_deps.py index c8080413377a..6efbded72f14 100755 --- a/scripts/analyze_deps.py +++ b/scripts/analyze_deps.py @@ -301,8 +301,16 @@ 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: @@ -334,11 +342,4 @@ def display_order(k): 'repo_name': 'azure-sdk-for-python' }) - 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') - sys.exit(exitcode)