Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
clear=False,
pre=False,
keep_outdated=False,
write=True,
pypi_mirror=None,
):
"""Executes the freeze functionality.
"""
cached_lockfile = {}
if not pre:
pre = project.settings.get('allow_prereleases')
if keep_outdated:
if not project.lockfile_exists:
click.echo(
'{0}: Pipfile.lock must exist to use --keep-outdated!'.format(
crayons.red('Warning', bold=True)
)
)
sys.exit(1)
cached_lockfile = project.lockfile_content
# Create the lockfile.
lockfile = project._lockfile
# Cleanup lockfile.
for section in ('default', 'develop'):
for k, v in lockfile[section].copy().items():
if not hasattr(v, 'keys'):
del lockfile[section][k]
# Ensure that develop inherits from default.
dev_packages = project.dev_packages.copy()
for dev_package in project.dev_packages:
if dev_package in project.packages:
dev_packages[dev_package] = project.packages[dev_package]
)
sys.exit(1)
from pipenv.core import project
if not project.virtualenv_exists:
click.echo(crayons.red(
'No virtualenv has been created for this project yet!',
bold=True,
), err=True)
sys.exit(1)
click.echo(
crayons.normal(
u'{0} ({1})...'.format(
crayons.normal('Removing virtualenv', bold=True),
crayons.green(project.virtualenv_location),
)
)
)
# Remove the virtualenv.
from ._utils import spinner
with spinner():
from .operations.virtualenv import cleanup_virtualenv
cleanup_virtualenv(bare=True)
for c in procs:
if concurrent:
c.block()
if 'Ignoring' in c.out:
click.echo(crayons.yellow(c.out.strip()))
if verbose:
click.echo(crayons.blue(c.out or c.err))
# The Installation failed...
if c.return_code != 0:
# Save the Failed Dependency for later.
failed_deps_list.append((c.dep, c.ignore_hash))
# Alert the user.
click.echo(
'{0} {1}! Will try again.'.format(
crayons.red('An error occurred while installing'),
crayons.green(c.dep.split('--hash')[0].strip()),
)
elif (python) or (three is not None) or (site_packages is not False):
set_using_default_python(False)
# Ensure python is installed before deleting existing virtual env
ensure_python(three=three, python=python)
click.echo(crayons.red('Virtualenv already exists!'), err=True)
# If VIRTUAL_ENV is set, there is a possibility that we are
# going to remove the active virtualenv that the user cares
# about, so confirm first.
if 'VIRTUAL_ENV' in os.environ:
if not (
PIPENV_YES or
click.confirm('Remove existing virtualenv?', default=True)
):
abort()
click.echo(
crayons.normal(u'Removing existing virtualenv...', bold=True),
err=True,
)
# Remove the virtualenv.
cleanup_virtualenv(bare=True)
# Call this function again.
ensure_virtualenv(
three=three, python=python, site_packages=site_packages
)
def format_help(help):
"""Formats the help string."""
help = help.replace('Options:', str(crayons.normal('Options:', bold=True)))
help = help.replace(
'Usage: pipenv',
str('Usage: {0}'.format(crayons.normal('pipenv', bold=True))),
)
help = help.replace(' check', str(crayons.red(' check', bold=True)))
help = help.replace(' clean', str(crayons.red(' clean', bold=True)))
help = help.replace(' graph', str(crayons.red(' graph', bold=True)))
help = help.replace(
' install', str(crayons.magenta(' install', bold=True))
)
help = help.replace(' lock', str(crayons.green(' lock', bold=True)))
help = help.replace(' open', str(crayons.red(' open', bold=True)))
help = help.replace(' run', str(crayons.yellow(' run', bold=True)))
help = help.replace(' shell', str(crayons.yellow(' shell', bold=True)))
help = help.replace(' sync', str(crayons.green(' sync', bold=True)))
help = help.replace(
' uninstall', str(crayons.magenta(' uninstall', bold=True))
)
help = help.replace(' update', str(crayons.green(' update', bold=True)))
get_pipenv_diagnostics()
return 0
# --clear was passed…
elif state.clear:
do_clear()
return 0
# --venv was passed…
elif venv:
# There is no virtualenv yet.
if not project.virtualenv_exists:
echo(
"{}({}){}".format(
crayons.red("No virtualenv has been created for this project"),
crayons.white(project.project_directory, bold=True),
crayons.red(" yet!")
),
err=True,
)
ctx.abort()
else:
echo(project.virtualenv_location)
return 0
# --rm was passed…
elif rm:
# Abort if --system (or running in a virtualenv).
from ..environments import PIPENV_USE_SYSTEM
if PIPENV_USE_SYSTEM:
echo(
crayons.red(
"You are attempting to remove a virtualenv that "
"Pipenv did not create. Aborting."
def format_help(help):
"""Formats the help string."""
help = help.replace('Options:', str(crayons.normal('Options:', bold=True)))
help = help.replace(
'Usage: pipenv',
str('Usage: {0}'.format(crayons.normal('pipenv', bold=True))),
)
help = help.replace(' check', str(crayons.red(' check', bold=True)))
help = help.replace(' clean', str(crayons.red(' clean', bold=True)))
help = help.replace(' graph', str(crayons.red(' graph', bold=True)))
help = help.replace(
' install', str(crayons.magenta(' install', bold=True))
)
help = help.replace(' lock', str(crayons.green(' lock', bold=True)))
help = help.replace(' open', str(crayons.red(' open', bold=True)))
help = help.replace(' run', str(crayons.yellow(' run', bold=True)))
help = help.replace(' shell', str(crayons.yellow(' shell', bold=True)))
help = help.replace(' sync', str(crayons.green(' sync', bold=True)))
help = help.replace(
def _purge(bare=False, downloads=False, allow_global=False, verbose=False):
"""Executes the purge functionality."""
if downloads:
if not bare:
click.echo(
crayons.normal(u'Clearing out downloads directory...', bold=True)
)
shutil.rmtree(project.download_location)
return
freeze = delegator.run(
'{0} freeze'.format(
escape_grouped_arguments(which_pip(allow_global=allow_global))
)
).out
# Remove comments from the output, if any.
installed = [
line
for line in freeze.splitlines()
if not line.lstrip().startswith('#')
]
# Remove setuptools and friends from installed, if present.
from pipenv.patched import crayons
from pipenv.vendor import blindspin, click
from pipenv.core import BAD_PACKAGES, project
from pipenv.environments import (
PIPENV_COLORBLIND,
PIPENV_DONT_LOAD_ENV,
PIPENV_DOTENV_LOCATION,
PIPENV_NOSPIN,
)
from pipenv.utils import proper_case
# Disable colors, for the color blind and others who do not prefer colors.
if PIPENV_COLORBLIND:
crayons.disable()
# Disable spinner, for cleaner build logs (the unworthy).
if PIPENV_NOSPIN:
@contextlib.contextmanager # noqa: F811
def spinner():
yield
else:
spinner = blindspin.spinner
def convert_deps_to_pip(deps, project=None, r=True, include_index=False):
""""Converts a Pipfile-formatted dependency to a pip-formatted one.
"""
from pipenv._compat import NamedTemporaryFile
from pipenv.vendor import requirementslib
def _ensure_environment():
# Skip this on Windows...
if os.name != 'nt':
if 'LANG' not in os.environ:
click.echo(
'{0}: the environment variable {1} is not set!'
'\nWe recommend setting this in {2} (or equivalent) for '
'proper expected behavior.'.format(
crayons.red('Warning', bold=True),
crayons.normal('LANG', bold=True),
crayons.green('~/.profile'),
),
err=True,
)