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_venv():
# There is no virtualenv yet.
from pipenv.core import project
if not project.virtualenv_exists:
click.echo(
crayons.red(
'No virtualenv has been created for this project yet!'
),
err=True,
)
sys.exit(1)
click.echo(project.virtualenv_location)
try:
do_create_virtualenv()
except KeyboardInterrupt:
cleanup_virtualenv(bare=False)
sys.exit(1)
# Ensure the Pipfile exists.
if not deploy:
ensure_pipfile(system=system)
if not requirements_dir:
cleanup_reqdir = True
requirements_dir = TemporaryDirectory(
suffix='-requirements', prefix='pipenv-'
)
# Write out the lockfile if it doesn't exist, but not if the Pipfile is being ignored
if (project.lockfile_exists and not ignore_pipfile) and not skip_lock:
old_hash = project.get_lockfile_hash()
new_hash = project.calculate_pipfile_hash()
if new_hash != old_hash:
if deploy:
click.echo(
crayons.red(
'Your Pipfile.lock ({0}) is out of date. Expected: ({1}).'.format(
old_hash[-6:], new_hash[-6:]
)
)
)
click.echo(
crayons.normal('Aborting deploy.', bold=True), err=True
)
requirements_dir.cleanup()
sys.exit(1)
elif (system or allow_global) and not (PIPENV_VIRTUALENV):
"""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]
# Resolve dev-package dependencies, with pip-tools.
pip_freeze = delegator.run(
'{0} freeze'.format(escape_grouped_arguments(which_pip(allow_global=system)))
).out
sections = {
'dev': {
ctx.abort()
else:
echo(project.virtualenv_location)
return 0
# --rm was passed…
elif rm:
# Abort if --system (or running in a virtualenv).
if environments.PIPENV_USE_SYSTEM:
echo(
crayons.red(
"You are attempting to remove a virtualenv that "
"Pipenv did not create. Aborting."
)
)
ctx.abort()
if project.virtualenv_exists:
loc = project.virtualenv_location
echo(
crayons.normal(
u"{0} ({1})…".format(
crayons.normal("Removing virtualenv", bold=True),
crayons.green(loc),
)
)
)
with spinner():
# Remove the virtualenv.
cleanup_virtualenv(bare=True)
return 0
else:
echo(
crayons.red(
return resolve_deps(
packages,
which,
project=project,
pre=pre,
sources=sources,
clear=clear,
allow_global=system,
req_dir=requirements_dir
)
from pipenv.core import project
sources = (
replace_pypi_sources(project.pipfile_sources, pypi_mirror_source)
if pypi_mirror_source
else project.pipfile_sources
)
keep_outdated = os.environ.get("PIPENV_KEEP_OUTDATED", False)
results, resolver = resolve(
packages,
pre=pre,
project=project,
sources=sources,
clear=clear,
system=system,
requirements_dir=requirements_dir,
)
if keep_outdated:
results = clean_outdated(results, resolver, project)
else:
results = clean_results(results, resolver, project)
if write:
from pipenv.patched.piptools import logging as piptools_logging
piptools_logging.log.verbosity = 1 if verbose else 0
return resolve_deps(
packages,
which,
project=project,
pre=pre,
sources=sources,
clear=clear,
allow_global=system,
req_dir=requirements_dir
)
from pipenv.core import project
sources = (
replace_pypi_sources(project.pipfile_sources, pypi_mirror_source)
if pypi_mirror_source
else project.pipfile_sources
)
keep_outdated = os.environ.get("PIPENV_KEEP_OUTDATED", False)
results, resolver = resolve(
packages,
pre=pre,
project=project,
sources=sources,
clear=clear,
system=system,
requirements_dir=requirements_dir,
)
if keep_outdated:
results = clean_outdated(results, resolver, project)
else:
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.
for package_name in BAD_PACKAGES:
for i, package in enumerate(installed):
for key in os.environ:
if key.startswith('PIPENV'):
print(' - `{0}`: `{1}`'.format(key, os.environ[key]))
print('')
print_utf(u'Debug–specific environment variables:')
print('')
for key in ('PATH', 'SHELL', 'EDITOR', 'LANG', 'PWD', 'VIRTUAL_ENV'):
if key in os.environ:
print(' - `{0}`: `{1}`'.format(key, os.environ[key]))
print('')
print('')
print('---------------------------')
print('')
if project.pipfile_exists:
print_utf(
u'Contents of `Pipfile` ({0!r}):'.format(project.pipfile_location)
)
print('')
print('```toml')
with open(project.pipfile_location, 'r') as f:
print(f.read())
print('```')
print('')
if project.lockfile_exists:
print('')
print_utf(
u'Contents of `Pipfile.lock` ({0!r}):'.format(
project.lockfile_location
)
)
print('')
print('```json')
project=project,
clear=clear,
pre=pre,
allow_global=system,
pypi_mirror=pypi_mirror,
)
# Add dependencies to lockfile.
for dep in results:
is_top_level = dep['name'] in settings['packages']
pipfile_entry = settings['packages'][dep['name']] if is_top_level else None
dep_lockfile = _clean_resolved_dep(dep, is_top_level=is_top_level, pipfile_entry=pipfile_entry)
lockfile[settings['lockfile_key']].update(dep_lockfile)
# Add refs for VCS installs.
# TODO: be smarter about this.
vcs_reqs, vcs_lockfile = _get_vcs_deps(
project,
pip_freeze,
which=which,
verbose=verbose,
clear=clear,
pre=pre,
allow_global=system,
dev=settings['dev']
)
vcs_lines = [req.as_line() for req in vcs_reqs if req.editable]
vcs_results = _venv_resolve_deps(
vcs_lines,
which=which,
verbose=verbose,
project=project,
clear=clear,
pre=pre,