login page

This commit is contained in:
Alicja Cięciwa
2020-10-27 12:57:58 +01:00
commit cb8886666c
8545 changed files with 1082463 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
# -*- coding=utf-8 -*-
from __future__ import absolute_import
from .command import cli # noqa

View File

@@ -0,0 +1,718 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import os
import sys
from click import (
argument, echo, edit, group, option, pass_context, secho, version_option, Choice
)
from ..__version__ import __version__
from ..exceptions import PipenvOptionsError
from ..patched import crayons
from ..vendor import click_completion, delegator
from .options import (
CONTEXT_SETTINGS, PipenvGroup, code_option, common_options, deploy_option,
general_options, install_options, lock_options, pass_state,
pypi_mirror_option, python_option, site_packages_option, skip_lock_option,
sync_options, system_option, three_option, uninstall_options,
verbose_option
)
# Enable shell completion.
click_completion.init()
subcommand_context = CONTEXT_SETTINGS.copy()
subcommand_context.update({
"ignore_unknown_options": True,
"allow_extra_args": True
})
subcommand_context_no_interspersion = subcommand_context.copy()
subcommand_context_no_interspersion["allow_interspersed_args"] = False
@group(cls=PipenvGroup, invoke_without_command=True, context_settings=CONTEXT_SETTINGS)
@option("--where", is_flag=True, default=False, help="Output project home information.")
@option("--venv", is_flag=True, default=False, help="Output virtualenv information.")
@option("--py", is_flag=True, default=False, help="Output Python interpreter information.")
@option("--envs", is_flag=True, default=False, help="Output Environment Variable options.")
@option("--rm", is_flag=True, default=False, help="Remove the virtualenv.")
@option("--bare", is_flag=True, default=False, help="Minimal output.")
@option(
"--completion",
is_flag=True,
default=False,
help="Output completion (to be executed by the shell).",
)
@option("--man", is_flag=True, default=False, help="Display manpage.")
@option(
"--support",
is_flag=True,
help="Output diagnostic information for use in GitHub issues.",
)
@general_options
@version_option(prog_name=crayons.normal("pipenv", bold=True), version=__version__)
@pass_state
@pass_context
def cli(
ctx,
state,
where=False,
venv=False,
py=False,
envs=False,
rm=False,
bare=False,
completion=False,
man=False,
support=None,
help=False,
site_packages=None,
**kwargs
):
# Handle this ASAP to make shell startup fast.
if completion:
from .. import shells
try:
shell = shells.detect_info()[0]
except shells.ShellDetectionFailure:
echo(
"Fail to detect shell. Please provide the {0} environment "
"variable.".format(crayons.normal("PIPENV_SHELL", bold=True)),
err=True,
)
ctx.abort()
print(click_completion.get_code(shell=shell, prog_name="pipenv"))
return 0
from ..core import (
system_which,
do_py,
warn_in_virtualenv,
do_where,
project,
cleanup_virtualenv,
ensure_project,
format_help,
do_clear,
)
from ..utils import create_spinner
if man:
if system_which("man"):
path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "pipenv.1")
os.execle(system_which("man"), "man", path, os.environ)
return 0
else:
secho("man does not appear to be available on your system.", fg="yellow", bold=True, err=True)
return 1
if envs:
echo("The following environment variables can be set, to do various things:\n")
from .. import environments
for key in environments.__dict__:
if key.startswith("PIPENV"):
echo(" - {0}".format(crayons.normal(key, bold=True)))
echo(
"\nYou can learn more at:\n {0}".format(
crayons.green(
"https://pipenv.pypa.io/en/latest/advanced/#configuration-with-environment-variables"
)
)
)
return 0
warn_in_virtualenv()
if ctx.invoked_subcommand is None:
# --where was passed…
if where:
do_where(bare=True)
return 0
elif py:
do_py()
return 0
# --support was passed…
elif support:
from ..help import get_pipenv_diagnostics
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."
)
)
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 create_spinner(text="Running..."):
# Remove the virtualenv.
cleanup_virtualenv(bare=True)
return 0
else:
echo(
crayons.red(
"No virtualenv has been created for this project yet!",
bold=True,
),
err=True,
)
ctx.abort()
# --two / --three was passed…
if (state.python or state.three is not None) or state.site_packages:
ensure_project(
three=state.three,
python=state.python,
warn=True,
site_packages=state.site_packages,
pypi_mirror=state.pypi_mirror,
clear=state.clear,
)
# Check this again before exiting for empty ``pipenv`` command.
elif ctx.invoked_subcommand is None:
# Display help to user, if no commands were passed.
echo(format_help(ctx.get_help()))
@cli.command(
short_help="Installs provided packages and adds them to Pipfile, or (if no packages are given), installs all packages from Pipfile.",
context_settings=subcommand_context,
)
@system_option
@code_option
@deploy_option
@site_packages_option
@skip_lock_option
@install_options
@pass_state
@pass_context
def install(
ctx,
state,
**kwargs
):
"""Installs provided packages and adds them to Pipfile, or (if no packages are given), installs all packages from Pipfile."""
from ..core import do_install
retcode = do_install(
dev=state.installstate.dev,
three=state.three,
python=state.python,
pypi_mirror=state.pypi_mirror,
system=state.system,
lock=not state.installstate.skip_lock,
ignore_pipfile=state.installstate.ignore_pipfile,
skip_lock=state.installstate.skip_lock,
requirementstxt=state.installstate.requirementstxt,
sequential=state.installstate.sequential,
pre=state.installstate.pre,
code=state.installstate.code,
deploy=state.installstate.deploy,
keep_outdated=state.installstate.keep_outdated,
selective_upgrade=state.installstate.selective_upgrade,
index_url=state.index,
extra_index_url=state.extra_index_urls,
packages=state.installstate.packages,
editable_packages=state.installstate.editables,
site_packages=state.site_packages
)
if retcode:
ctx.abort()
@cli.command(
short_help="Uninstalls a provided package and removes it from Pipfile.",
context_settings=subcommand_context
)
@option(
"--all-dev",
is_flag=True,
default=False,
help="Uninstall all package from [dev-packages].",
)
@option(
"--all",
is_flag=True,
default=False,
help="Purge all package(s) from virtualenv. Does not edit Pipfile.",
)
@uninstall_options
@pass_state
@pass_context
def uninstall(
ctx,
state,
all_dev=False,
all=False,
**kwargs
):
"""Uninstalls a provided package and removes it from Pipfile."""
from ..core import do_uninstall
retcode = do_uninstall(
packages=state.installstate.packages,
editable_packages=state.installstate.editables,
three=state.three,
python=state.python,
system=state.system,
lock=not state.installstate.skip_lock,
all_dev=all_dev,
all=all,
keep_outdated=state.installstate.keep_outdated,
pypi_mirror=state.pypi_mirror,
ctx=ctx
)
if retcode:
sys.exit(retcode)
LOCK_HEADER = """\
#
# These requirements were autogenerated by pipenv
# To regenerate from the project's Pipfile, run:
#
# pipenv lock {options}
#
"""
LOCK_DEV_NOTE = """\
# Note: in pipenv 2020.x, "--dev" changed to emit both default and development
# requirements. To emit only development requirements, pass "--dev-only".
"""
@cli.command(short_help="Generates Pipfile.lock.", context_settings=CONTEXT_SETTINGS)
@lock_options
@pass_state
@pass_context
def lock(
ctx,
state,
**kwargs
):
"""Generates Pipfile.lock."""
from ..core import ensure_project, do_init, do_lock
# Ensure that virtualenv is available.
# Note that we don't pass clear on to ensure_project as it is also
# handled in do_lock
ensure_project(
three=state.three, python=state.python, pypi_mirror=state.pypi_mirror,
warn=(not state.quiet), site_packages=state.site_packages,
)
emit_requirements = state.lockoptions.emit_requirements
dev = state.installstate.dev
dev_only = state.lockoptions.dev_only
pre = state.installstate.pre
if emit_requirements:
# Emit requirements file header (unless turned off with --no-header)
if state.lockoptions.emit_requirements_header:
header_options = ["--requirements"]
if dev_only:
header_options.append("--dev-only")
elif dev:
header_options.append("--dev")
echo(LOCK_HEADER.format(options=" ".join(header_options)))
# TODO: Emit pip-compile style header
if dev and not dev_only:
echo(LOCK_DEV_NOTE)
# Setting "emit_requirements=True" means do_init() just emits the
# install requirements file to stdout, it doesn't install anything
do_init(
dev=dev,
dev_only=dev_only,
emit_requirements=emit_requirements,
pypi_mirror=state.pypi_mirror,
pre=pre,
)
elif state.lockoptions.dev_only:
raise PipenvOptionsError(
"--dev-only",
"--dev-only is only permitted in combination with --requirements. "
"Aborting."
)
do_lock(
ctx=ctx,
clear=state.clear,
pre=pre,
keep_outdated=state.installstate.keep_outdated,
pypi_mirror=state.pypi_mirror,
write=not state.quiet,
)
@cli.command(
short_help="Spawns a shell within the virtualenv.",
context_settings=subcommand_context,
)
@option(
"--fancy",
is_flag=True,
default=False,
help="Run in shell in fancy mode. Make sure the shell have no path manipulating"
" scripts. Run $pipenv shell for issues with compatibility mode.",
)
@option(
"--anyway",
is_flag=True,
default=False,
help="Always spawn a sub-shell, even if one is already spawned.",
)
@argument("shell_args", nargs=-1)
@pypi_mirror_option
@three_option
@python_option
@pass_state
def shell(
state,
fancy=False,
shell_args=None,
anyway=False,
):
"""Spawns a shell within the virtualenv."""
from ..core import load_dot_env, do_shell
# Prevent user from activating nested environments.
if "PIPENV_ACTIVE" in os.environ:
# If PIPENV_ACTIVE is set, VIRTUAL_ENV should always be set too.
venv_name = os.environ.get("VIRTUAL_ENV", "UNKNOWN_VIRTUAL_ENVIRONMENT")
if not anyway:
echo(
"{0} {1} {2}\nNo action taken to avoid nested environments.".format(
crayons.normal("Shell for"),
crayons.green(venv_name, bold=True),
crayons.normal("already activated.", bold=True),
),
err=True,
)
sys.exit(1)
# Load .env file.
load_dot_env()
# Use fancy mode for Windows.
if os.name == "nt":
fancy = True
do_shell(
three=state.three,
python=state.python,
fancy=fancy,
shell_args=shell_args,
pypi_mirror=state.pypi_mirror,
)
@cli.command(
short_help="Spawns a command installed into the virtualenv.",
context_settings=subcommand_context_no_interspersion,
)
@common_options
@argument("command")
@argument("args", nargs=-1)
@pass_state
def run(state, command, args):
"""Spawns a command installed into the virtualenv."""
from ..core import do_run
do_run(
command=command, args=args, three=state.three, python=state.python, pypi_mirror=state.pypi_mirror
)
@cli.command(
short_help="Checks for PyUp Safety security vulnerabilities and against"
" PEP 508 markers provided in Pipfile.",
context_settings=subcommand_context
)
@option(
"--unused",
nargs=1,
default=False,
help="Given a code path, show potentially unused dependencies.",
)
@option(
"--db",
nargs=1,
default=lambda: os.environ.get('PIPENV_SAFETY_DB', False),
help="Path to a local PyUp Safety vulnerabilities database."
" Default: ENV PIPENV_SAFETY_DB or None.",
)
@option(
"--ignore",
"-i",
multiple=True,
help="Ignore specified vulnerability during PyUp Safety checks.",
)
@option(
"--output",
type=Choice(["default", "json", "full-report", "bare"]),
default="default",
help="Translates to --json, --full-report or --bare from PyUp Safety check",
)
@option(
"--key",
help="Safety API key from PyUp.io for scanning dependencies against a live"
" vulnerabilities database. Leave blank for scanning against a"
" database that only updates once a month.",
)
@option(
"--quiet",
is_flag=True,
help="Quiet standard output, except vulnerability report."
)
@common_options
@system_option
@argument("args", nargs=-1)
@pass_state
def check(
state,
unused=False,
db=False,
style=False,
ignore=None,
output="default",
key=None,
quiet=False,
args=None,
**kwargs
):
"""Checks for PyUp Safety security vulnerabilities and against PEP 508 markers provided in Pipfile."""
from ..core import do_check
do_check(
three=state.three,
python=state.python,
system=state.system,
unused=unused,
db=db,
ignore=ignore,
output=output,
key=key,
quiet=quiet,
args=args,
pypi_mirror=state.pypi_mirror,
)
@cli.command(short_help="Runs lock, then sync.", context_settings=CONTEXT_SETTINGS)
@option("--bare", is_flag=True, default=False, help="Minimal output.")
@option(
"--outdated", is_flag=True, default=False, help=u"List out-of-date dependencies."
)
@option("--dry-run", is_flag=True, default=None, help=u"List out-of-date dependencies.")
@install_options
@pass_state
@pass_context
def update(
ctx,
state,
bare=False,
dry_run=None,
outdated=False,
**kwargs
):
"""Runs lock, then sync."""
from ..core import (
ensure_project,
do_outdated,
do_lock,
do_sync,
project,
)
ensure_project(
three=state.three, python=state.python, pypi_mirror=state.pypi_mirror,
warn=(not state.quiet), site_packages=state.site_packages, clear=state.clear
)
if not outdated:
outdated = bool(dry_run)
if outdated:
do_outdated(clear=state.clear, pre=state.installstate.pre, pypi_mirror=state.pypi_mirror)
packages = [p for p in state.installstate.packages if p]
editable = [p for p in state.installstate.editables if p]
if not packages:
echo(
"{0} {1} {2} {3}{4}".format(
crayons.white("Running", bold=True),
crayons.red("$ pipenv lock", bold=True),
crayons.white("then", bold=True),
crayons.red("$ pipenv sync", bold=True),
crayons.white(".", bold=True),
)
)
else:
for package in packages + editable:
if package not in project.all_packages:
echo(
"{0}: {1} was not found in your Pipfile! Aborting."
"".format(
crayons.red("Warning", bold=True),
crayons.green(package, bold=True),
),
err=True,
)
ctx.abort()
do_lock(
ctx=ctx,
clear=state.clear,
pre=state.installstate.pre,
keep_outdated=state.installstate.keep_outdated,
pypi_mirror=state.pypi_mirror,
write=not state.quiet,
)
do_sync(
ctx=ctx,
dev=state.installstate.dev,
three=state.three,
python=state.python,
bare=bare,
dont_upgrade=not state.installstate.keep_outdated,
user=False,
clear=state.clear,
unused=False,
sequential=state.installstate.sequential,
pypi_mirror=state.pypi_mirror,
)
@cli.command(
short_help=u"Displays currently-installed dependency graph information.",
context_settings=CONTEXT_SETTINGS
)
@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, json_tree=False, reverse=False):
"""Displays currently-installed dependency graph information."""
from ..core import do_graph
do_graph(bare=bare, json=json, json_tree=json_tree, reverse=reverse)
@cli.command(
short_help="View a given module in your editor.", name="open",
context_settings=CONTEXT_SETTINGS
)
@common_options
@argument("module", nargs=1)
@pass_state
def run_open(state, module, *args, **kwargs):
"""View a given module in your editor.
This uses the EDITOR environment variable. You can temporarily override it,
for example:
EDITOR=atom pipenv open requests
"""
from ..core import which, ensure_project, inline_activate_virtual_environment
# Ensure that virtualenv is available.
ensure_project(
three=state.three, python=state.python,
validate=False, pypi_mirror=state.pypi_mirror,
)
c = delegator.run(
'{0} -c "import {1}; print({1}.__file__);"'.format(which("python"), module)
)
try:
assert c.return_code == 0
except AssertionError:
echo(crayons.red("Module not found!"))
sys.exit(1)
if "__init__.py" in c.out:
p = os.path.dirname(c.out.strip().rstrip("cdo"))
else:
p = c.out.strip().rstrip("cdo")
echo(crayons.normal("Opening {0!r} in your EDITOR.".format(p), bold=True))
inline_activate_virtual_environment()
edit(filename=p)
return 0
@cli.command(
short_help="Installs all packages specified in Pipfile.lock.",
context_settings=CONTEXT_SETTINGS
)
@option("--bare", is_flag=True, default=False, help="Minimal output.")
@sync_options
@pass_state
@pass_context
def sync(
ctx,
state,
bare=False,
user=False,
unused=False,
**kwargs
):
"""Installs all packages specified in Pipfile.lock."""
from ..core import do_sync
retcode = do_sync(
ctx=ctx,
dev=state.installstate.dev,
three=state.three,
python=state.python,
bare=bare,
dont_upgrade=(not state.installstate.keep_outdated),
user=user,
clear=state.clear,
unused=unused,
sequential=state.installstate.sequential,
pypi_mirror=state.pypi_mirror,
)
if retcode:
ctx.abort()
@cli.command(
short_help="Uninstalls all packages not specified in Pipfile.lock.",
context_settings=CONTEXT_SETTINGS
)
@option("--bare", is_flag=True, default=False, help="Minimal output.")
@option("--dry-run", is_flag=True, default=False, help="Just output unneeded packages.")
@verbose_option
@three_option
@python_option
@pass_state
@pass_context
def clean(ctx, state, dry_run=False, bare=False, user=False):
"""Uninstalls all packages not specified in Pipfile.lock."""
from ..core import do_clean
do_clean(ctx=ctx, three=state.three, python=state.python, dry_run=dry_run,
system=state.system)
if __name__ == "__main__":
cli()

View File

@@ -0,0 +1,469 @@
# -*- coding=utf-8 -*-
from __future__ import absolute_import
import os
import click.types
from click import (
BadParameter, BadArgumentUsage, Group, Option, argument, echo, make_pass_decorator, option
)
from click_didyoumean import DYMMixin
from .. import environments
from ..utils import is_valid_url
CONTEXT_SETTINGS = {
"help_option_names": ["-h", "--help"],
"auto_envvar_prefix": "PIPENV"
}
class PipenvGroup(DYMMixin, Group):
"""Custom Group class provides formatted main help"""
def get_help_option(self, ctx):
from ..core import format_help
"""Override for showing formatted main help via --help and -h options"""
help_options = self.get_help_option_names(ctx)
if not help_options or not self.add_help_option:
return
def show_help(ctx, param, value):
if value and not ctx.resilient_parsing:
if not ctx.invoked_subcommand:
# legit main help
echo(format_help(ctx.get_help()))
else:
# legit sub-command help
echo(ctx.get_help(), color=ctx.color)
ctx.exit()
return Option(
help_options,
is_flag=True,
is_eager=True,
expose_value=False,
callback=show_help,
help="Show this message and exit.",
)
class State(object):
def __init__(self):
self.index = None
self.extra_index_urls = []
self.verbose = False
self.quiet = False
self.pypi_mirror = None
self.python = None
self.two = None
self.three = None
self.site_packages = None
self.clear = False
self.system = False
self.installstate = InstallState()
self.lockoptions = LockOptions()
class InstallState(object):
def __init__(self):
self.dev = False
self.pre = False
self.selective_upgrade = False
self.keep_outdated = False
self.skip_lock = False
self.ignore_pipfile = False
self.sequential = False
self.code = False
self.requirementstxt = None
self.deploy = False
self.packages = []
self.editables = []
class LockOptions(object):
def __init__(self):
self.dev_only = False
self.emit_requirements = False
self.emit_requirements_header = False
pass_state = make_pass_decorator(State, ensure=True)
def index_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
state.index = value
return value
return option('-i', '--index', expose_value=False, envvar="PIP_INDEX_URL",
help='Target PyPI-compatible package index url.', nargs=1,
callback=callback)(f)
def extra_index_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
state.extra_index_urls.extend(list(value))
return value
return option("--extra-index-url", multiple=True, expose_value=False,
help=u"URLs to the extra PyPI compatible indexes to query for package look-ups.",
callback=callback, envvar="PIP_EXTRA_INDEX_URL")(f)
def editable_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
state.installstate.editables.extend(value)
return value
return option('-e', '--editable', expose_value=False, multiple=True,
callback=callback, type=click.types.STRING, help=(
"An editable Python package URL or path, often to a VCS "
"repository."
))(f)
def sequential_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
state.installstate.sequential = value
return value
return option("--sequential", is_flag=True, default=False, expose_value=False,
help="Install dependencies one-at-a-time, instead of concurrently.",
callback=callback, type=click.types.BOOL, show_envvar=True)(f)
def skip_lock_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
state.installstate.skip_lock = value
return value
return option("--skip-lock", is_flag=True, default=False, expose_value=False,
help=u"Skip locking mechanisms and use the Pipfile instead during operation.",
envvar="PIPENV_SKIP_LOCK", callback=callback, type=click.types.BOOL,
show_envvar=True)(f)
def keep_outdated_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
state.installstate.keep_outdated = value
return value
return option("--keep-outdated", is_flag=True, default=False, expose_value=False,
help=u"Keep out-dated dependencies from being updated in Pipfile.lock.",
callback=callback, type=click.types.BOOL, show_envvar=True)(f)
def selective_upgrade_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
state.installstate.selective_upgrade = value
return value
return option("--selective-upgrade", is_flag=True, default=False, type=click.types.BOOL,
help="Update specified packages.", callback=callback,
expose_value=False)(f)
def ignore_pipfile_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
state.installstate.ignore_pipfile = value
return value
return option("--ignore-pipfile", is_flag=True, default=False, expose_value=False,
help="Ignore Pipfile when installing, using the Pipfile.lock.",
callback=callback, type=click.types.BOOL, show_envvar=True)(f)
def _dev_option(f, help_text):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
state.installstate.dev = value
return value
return option("--dev", "-d", is_flag=True, default=False, type=click.types.BOOL,
help=help_text, callback=callback,
expose_value=False, show_envvar=True)(f)
def install_dev_option(f):
return _dev_option(f, "Install both develop and default packages")
def lock_dev_option(f):
return _dev_option(f, "Generate both develop and default requirements")
def uninstall_dev_option(f):
return _dev_option(f, "Deprecated (as it has no effect). May be removed in a future release.")
def pre_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
state.installstate.pre = value
return value
return option("--pre", is_flag=True, default=False, help=u"Allow pre-releases.",
callback=callback, type=click.types.BOOL, expose_value=False)(f)
def package_arg(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
state.installstate.packages.extend(value)
return value
return argument('packages', nargs=-1, callback=callback, expose_value=False,
type=click.types.STRING)(f)
def three_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
if value is not None:
state.three = value
state.two = not value
return value
return option("--three/--two", is_flag=True, default=None,
help="Use Python 3/2 when creating virtualenv.", callback=callback,
expose_value=False)(f)
def python_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
if value is not None:
state.python = validate_python_path(ctx, param, value)
return value
return option("--python", default=False, nargs=1, callback=callback,
help="Specify which version of Python virtualenv should use.",
expose_value=False, allow_from_autoenv=False)(f)
def pypi_mirror_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
if value is not None:
state.pypi_mirror = validate_pypi_mirror(ctx, param, value)
return value
return option("--pypi-mirror", default=environments.PIPENV_PYPI_MIRROR, nargs=1,
callback=callback, help="Specify a PyPI mirror.", expose_value=False)(f)
def verbose_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
if value:
if state.quiet:
raise BadArgumentUsage(
"--verbose and --quiet are mutually exclusive! Please choose one!",
ctx=ctx
)
state.verbose = True
setup_verbosity(ctx, param, 1)
return option("--verbose", "-v", is_flag=True, expose_value=False,
callback=callback, help="Verbose mode.", type=click.types.BOOL)(f)
def quiet_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
if value:
if state.verbose:
raise BadArgumentUsage(
"--verbose and --quiet are mutually exclusive! Please choose one!",
ctx=ctx
)
state.quiet = True
setup_verbosity(ctx, param, -1)
return option("--quiet", "-q", is_flag=True, expose_value=False,
callback=callback, help="Quiet mode.", type=click.types.BOOL)(f)
def site_packages_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
validate_bool_or_none(ctx, param, value)
state.site_packages = value
return value
return option("--site-packages/--no-site-packages", is_flag=True, default=None,
help="Enable site-packages for the virtualenv.", callback=callback,
expose_value=False, show_envvar=True)(f)
def clear_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
state.clear = value
return value
return option("--clear", is_flag=True, callback=callback, type=click.types.BOOL,
help="Clears caches (pipenv, pip, and pip-tools).",
expose_value=False, show_envvar=True)(f)
def system_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
if value is not None:
state.system = value
return value
return option("--system", is_flag=True, default=False, help="System pip management.",
callback=callback, type=click.types.BOOL, expose_value=False,
show_envvar=True)(f)
def requirementstxt_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
if value:
state.installstate.requirementstxt = value
return value
return option("--requirements", "-r", nargs=1, default=False, expose_value=False,
help="Import a requirements.txt file.", callback=callback)(f)
def emit_requirements_flag(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
if value:
state.lockoptions.emit_requirements = value
return value
return option("--requirements", "-r", default=False, is_flag=True, expose_value=False,
help="Generate output in requirements.txt format.", callback=callback)(f)
def emit_requirements_header_flag(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
if value:
state.lockoptions.emit_requirements_header = value
return value
return option("--header/--no-header", default=True, is_flag=True, expose_value=False,
help="Add header to generated requirements", callback=callback)(f)
def dev_only_flag(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
if value:
state.lockoptions.dev_only = value
return value
return option("--dev-only", default=False, is_flag=True, expose_value=False,
help="Emit development dependencies *only* (overrides --dev)", callback=callback)(f)
def code_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
if value:
state.installstate.code = value
return value
return option("--code", "-c", nargs=1, default=False, help="Install packages "
"automatically discovered from import statements.", callback=callback,
expose_value=False)(f)
def deploy_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
state.installstate.deploy = value
return value
return option("--deploy", is_flag=True, default=False, type=click.types.BOOL,
help=u"Abort if the Pipfile.lock is out-of-date, or Python version is"
" wrong.", callback=callback, expose_value=False)(f)
def setup_verbosity(ctx, param, value):
if not value:
return
import logging
loggers = ("pip", "piptools")
if value == 1:
for logger in loggers:
logging.getLogger(logger).setLevel(logging.INFO)
elif value == -1:
for logger in loggers:
logging.getLogger(logger).setLevel(logging.CRITICAL)
environments.PIPENV_VERBOSITY = value
def validate_python_path(ctx, param, value):
# Validating the Python path is complicated by accepting a number of
# friendly options: the default will be boolean False to enable
# autodetection but it may also be a value which will be searched in
# the path or an absolute path. To report errors as early as possible
# we'll report absolute paths which do not exist:
if isinstance(value, (str, bytes)):
if os.path.isabs(value) and not os.path.isfile(value):
raise BadParameter("Expected Python at path %s does not exist" % value)
return value
def validate_bool_or_none(ctx, param, value):
if value is not None:
return click.types.BOOL(value)
return False
def validate_pypi_mirror(ctx, param, value):
if value and not is_valid_url(value):
raise BadParameter("Invalid PyPI mirror URL: %s" % value)
return value
def common_options(f):
f = pypi_mirror_option(f)
f = verbose_option(f)
f = clear_option(f)
f = three_option(f)
f = python_option(f)
return f
def install_base_options(f):
f = common_options(f)
f = pre_option(f)
f = keep_outdated_option(f)
return f
def uninstall_options(f):
f = install_base_options(f)
f = uninstall_dev_option(f)
f = skip_lock_option(f)
f = editable_option(f)
f = package_arg(f)
return f
def lock_options(f):
f = install_base_options(f)
f = lock_dev_option(f)
f = emit_requirements_flag(f)
f = dev_only_flag(f)
return f
def sync_options(f):
f = install_base_options(f)
f = install_dev_option(f)
f = sequential_option(f)
return f
def install_options(f):
f = sync_options(f)
f = index_option(f)
f = extra_index_option(f)
f = requirementstxt_option(f)
f = selective_upgrade_option(f)
f = ignore_pipfile_option(f)
f = editable_option(f)
f = package_arg(f)
return f
def general_options(f):
f = common_options(f)
f = site_packages_option(f)
return f