From 0df5afbfeb3c05957df29f3ad5a1aba0517acaea Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 21 Sep 2017 11:22:30 -0400 Subject: [PATCH] only output good packages in graph --json Signed-off-by: Kenneth Reitz --- pipenv/cli.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/pipenv/cli.py b/pipenv/cli.py index 49fa7325..5a338af2 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -67,7 +67,7 @@ $$/ $$/ $$$$$$$/ $$$$$$$/ $$/ $$/ $/ $$/ # Packages that should be ignored later. BAD_PACKAGES = ( 'setuptools', 'pip', 'wheel', 'six', 'packaging', 'distribute' - 'pyparsing', 'appdirs', 'pipenv' + 'pyparsing', 'appdirs', ) # Are we using the default Python? @@ -984,7 +984,7 @@ def do_lock(verbose=False, system=False, clear=False): # Run the PEP 508 checker in the virtualenv, add it to the lockfile. cmd = '"{0}" {1}'.format(which('python', allow_global=system), shellquote(pep508checker.__file__.rstrip('cdo'))) c = delegator.run(cmd) - lockfile['_meta']['host-environment-markers'] = json.loads(c.out) + lockfile['_meta']['host-environment-markers'] = simplejson.loads(c.out) # Write out the lockfile. with open(project.lockfile_location, 'w') as f: @@ -1950,9 +1950,6 @@ def graph(bare=False, json=False): ) sys.exit(1) - if json: - bare = True - j = '--json' if json else '' cmd = '"{0}" {1} {2}'.format( @@ -1967,23 +1964,28 @@ def graph(bare=False, json=False): if not bare: if json: - data = simplejson.loads(c.out) - print(data) + data = [] + for d in simplejson.loads(c.out): + if d['package']['key'] not in BAD_PACKAGES: + data.append(d) - for line in c.out.split('\n'): + click.echo(simplejson.dumps(data, indent=4)) + sys.exit(0) + else: + for line in c.out.split('\n'): - # Ignore bad packages. - if line.split('==')[0] in BAD_PACKAGES: - continue + # Ignore bad packages. + if line.split('==')[0] in BAD_PACKAGES: + continue - # Bold top-level packages. - if not line.startswith(' '): - click.echo(crayons.white(line, bold=True)) + # Bold top-level packages. + if not line.startswith(' '): + click.echo(crayons.white(line, bold=True)) - # Echo the rest. - else: - click.echo(crayons.white(line, bold=False)) + # Echo the rest. + else: + click.echo(crayons.white(line, bold=False)) else: click.echo(c.out)