Merge branch 'master' into 2138-notpip_looping

This commit is contained in:
Kyle Altendorf
2018-05-17 09:12:34 -04:00
committed by GitHub
3 changed files with 39 additions and 3 deletions
+3 -2
View File
@@ -841,13 +841,14 @@ def update(
)
@option('--bare', is_flag=True, default=False, help="Minimal output.")
@option('--json', is_flag=True, default=False, help="Output JSON.")
@option('--json-tree', is_flag=True, default=False, help="Output JSON in nested tree.")
@option(
'--reverse', is_flag=True, default=False, help="Reversed dependency graph."
)
def graph(bare=False, json=False, reverse=False):
def graph(bare=False, json=False, json_tree=False, reverse=False):
from .core import do_graph
do_graph(bare=bare, json=json, reverse=reverse)
do_graph(bare=bare, json=json, json_tree=json_tree, reverse=reverse)
@command(short_help="View a given module in your editor.", name="open")
+35 -1
View File
@@ -906,6 +906,8 @@ def do_create_virtualenv(python=None, site_packages=False):
'new',
project.virtualenv_name,
'-d',
'-a',
project.project_directory,
]
# Default to using sys.executable, if Python wasn't provided.
if not python:
@@ -2409,7 +2411,7 @@ def do_check(three=None, python=False, system=False, unused=False, args=None):
sys.exit(1)
def do_graph(bare=False, json=False, reverse=False):
def do_graph(bare=False, json=False, json_tree=False, reverse=False):
import pipdeptree
try:
python_path = which('python')
@@ -2433,9 +2435,31 @@ def do_graph(bare=False, json=False, reverse=False):
err=True,
)
sys.exit(1)
if reverse and json_tree:
click.echo(
u'{0}: {1}'.format(
crayons.red('Warning', bold=True),
u'Using both --reverse and --json-tree together is not supported. '
u'Please select one of the two options.',
),
err=True,
)
sys.exit(1)
if json and json_tree:
click.echo(
u'{0}: {1}'.format(
crayons.red('Warning', bold=True),
u'Using both --json and --json-tree together is not supported. '
u'Please select one of the two options.',
),
err=True,
)
sys.exit(1)
flag = ''
if json:
flag = '--json'
if json_tree:
flag = '--json-tree'
if reverse:
flag = '--reverse'
if not project.virtualenv_exists:
@@ -2465,6 +2489,16 @@ def do_graph(bare=False, json=False, reverse=False):
data.append(d)
click.echo(simplejson.dumps(data, indent=4))
sys.exit(0)
elif json_tree:
def traverse(obj):
if isinstance(obj, list):
return [traverse(package) for package in obj if package['key'] not in BAD_PACKAGES]
else:
obj['dependencies'] = traverse(obj['dependencies'])
return obj
data = traverse(simplejson.loads(c.out))
click.echo(simplejson.dumps(data, indent=4))
sys.exit(0)
else:
for line in c.out.split('\n'):
# Ignore bad packages as top level.
+1
View File
@@ -48,6 +48,7 @@ def test_pipenv_graph(PipenvInstance, pypi):
p.pipenv('install requests')
assert 'requests' in p.pipenv('graph').out
assert 'requests' in p.pipenv('graph --json').out
assert 'requests' in p.pipenv('graph --json-tree').out
@pytest.mark.cli