Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def do_graph(bare=False, json=False, json_tree=False, reverse=False):
from pipenv.vendor.vistir.compat import JSONDecodeError
import pipdeptree
pipdeptree_path = pipdeptree.__file__.rstrip("cdo")
try:
python_path = which("python")
except AttributeError:
click.echo(
u"{0}: {1}".format(
crayons.red("Warning", bold=True),
u"Unable to display currently-installed dependency graph information here. "
u"Please run within a Pipenv project.",
),
err=True,
)
sys.exit(1)
except RuntimeError:
pass
else:
python_path = vistir.compat.Path(python_path).as_posix()
def graph(bare=False):
cmd = '"{0}" {1}'.format(
which('python'),
shellquote(pipdeptree.__file__.rstrip('cdo'))
)
# Run dep-tree.
c = delegator.run(cmd)
if not bare:
for line in c.out.split('\n'):
# 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))
flag = '--reverse'
if not project.virtualenv_exists:
click.echo(
u'{0}: No virtualenv has been created for this project yet! Consider '
u'running {1} first to automatically generate one for you or see'
u'{2} for further instructions.'.format(
crayons.red('Warning', bold=True),
crayons.green('`pipenv install`'),
crayons.green('`pipenv install --help`'),
),
err=True,
)
sys.exit(1)
cmd = '"{0}" {1} {2}'.format(
python_path,
escape_grouped_arguments(pipdeptree.__file__.rstrip('cdo')),
flag,
)
# Run dep-tree.
c = delegator.run(cmd)
if not bare:
if json_:
data = []
for d in json.loads(c.out):
if d['package']['key'] not in BAD_PACKAGES:
data.append(d)
click.echo(json.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]