Skip to content

Commit

Permalink
Implement auto_envvar_prefix
Browse files Browse the repository at this point in the history
- Closes #2200

Signed-off-by: Dan Ryan <dan@danryan.co>
  • Loading branch information
techalchemy committed Nov 14, 2018
1 parent f9b97da commit 08c384b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
1 change: 1 addition & 0 deletions news/2200.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added persistent settings for all CLI flags via ``PIPENV_{FLAG_NAME}`` environment variables by enabling ``auto_envvar_prefix=PIPENV`` in click (implements PEEP-0002).
2 changes: 1 addition & 1 deletion pipenv/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .cli import cli

if __name__ == "__main__":
cli()
cli(auto_envvar_prefix="PIPENV")
39 changes: 20 additions & 19 deletions pipenv/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def callback(ctx, param, value):
state.installstate.editables.extend(value)
return value
return option('-e', '--editable', expose_value=False, multiple=True,
help='An editable python package URL or path, often to a VCS repo.',
callback=callback)(f)
help='An editable python package URL or path, often to a VCS repo.',
callback=callback, type=click.types.STRING)(f)


def sequential_option(f):
Expand Down Expand Up @@ -157,7 +157,7 @@ def callback(ctx, param, 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)(f)
callback=callback, type=click.types.BOOL)(f)


def dev_option(f):
Expand All @@ -184,7 +184,8 @@ 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,)(f)
return argument('packages', nargs=-1, callback=callback, expose_value=False,
type=click.types.STRING)(f)


def three_option(f):
Expand All @@ -195,8 +196,8 @@ def callback(ctx, param, 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)
help="Use Python 3/2 when creating virtualenv.", callback=callback,
expose_value=False)(f)


def python_option(f):
Expand All @@ -206,8 +207,8 @@ def callback(ctx, param, value):
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)(f)
help="Specify which version of Python virtualenv should use.",
expose_value=False)(f)


def pypi_mirror_option(f):
Expand All @@ -217,7 +218,7 @@ def callback(ctx, param, value):
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)
callback=callback, help="Specify a PyPI mirror.", expose_value=False)(f)


def verbose_option(f):
Expand All @@ -227,7 +228,7 @@ def callback(ctx, param, value):
state.verbose = True
setup_verbosity(ctx, param, value)
return option("--verbose", "-v", is_flag=True, expose_value=False,
callback=callback, help="Verbose mode.")(f)
callback=callback, help="Verbose mode.", type=click.types.BOOL)(f)


def site_packages_option(f):
Expand All @@ -236,8 +237,8 @@ def callback(ctx, param, value):
state.site_packages = value
return value
return option("--site-packages", is_flag=True, default=False, type=click.types.BOOL,
help="Enable site-packages for the virtualenv.", callback=callback,
expose_value=False)(f)
help="Enable site-packages for the virtualenv.", callback=callback,
expose_value=False)(f)


def clear_option(f):
Expand All @@ -246,8 +247,8 @@ def callback(ctx, param, value):
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)(f)
help="Clears caches (pipenv, pip, and pip-tools).",
expose_value=False)(f)


def system_option(f):
Expand All @@ -257,7 +258,7 @@ def callback(ctx, param, value):
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)(f)
callback=callback, type=click.types.BOOL, expose_value=False)(f)


def requirementstxt_option(f):
Expand All @@ -267,7 +268,7 @@ def callback(ctx, param, 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)
help="Import a requirements.txt file.", callback=callback)(f)


def requirements_flag(f):
Expand All @@ -277,7 +278,7 @@ def callback(ctx, param, value):
state.installstate.requirementstxt = 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)
help="Generate output in requirements.txt format.", callback=callback)(f)


def code_option(f):
Expand All @@ -296,8 +297,8 @@ def callback(ctx, param, value):
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)
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):
Expand Down

0 comments on commit 08c384b

Please sign in to comment.