Merge pull request #1304 from jzengg/1285-fix-path-does-not-exist
Before adoption: this commit came in with the history the project adopted, so no landing records it.
1285 fix path does not exist
authored by David Lord · committed by GitHub · parents 278a054, db96143 · Browse files · 3 files·+27 added−8 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+27 added−8 removed
- tests:+11 added−0 removed
- other:+16 added−8 removed
Provenance
- Commit
2340acc- Tree
88cd9d4- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
278a054- Parent 2
db96143
3 files changed+27 added−8 removed
modified:click/core.py+14 added-7 removed
1321 unmodified lines1322 intentionally not finalized.1323 1324 Some settings are supported by both options and arguments.1325 1326- .. versionchanged:: 2.01327- Changed signature for parameter callback to also be passed the1328- parameter. In Click 2.0, the old callback format will still work,1329- but it will raise a warning to give you change to migrate the1330- code easier.1331-1326 :param param_decls: the parameter declarations for this option or1327 argument. This is a list of flags or argument1328 names.1329 :param type: the type that should be used. Either a :class:`ParamType`19 unmodified lines1349 should not be set for arguments or it will inverse the1350 order of processing.1351 :param envvar: a string or list of strings that are environment variables1352 that should be checked.1353+1354+ .. versionchanged:: 7.11355+ Empty environment variables are ignored rather than taking the1356+ empty string value. This makes it possible for scripts to clear1357+ variables if they can't unset them.1358+1359+ .. versionchanged:: 2.01360+ Changed signature for parameter callback to also be passed the1361+ parameter. The old callback format will still work, but it will1362+ raise a warning to give you a chance to migrate the code easier.1363 """1364 param_type_name = 'parameter'1365 1366 def __init__(self, param_decls=None, type=None, required=False,119 unmodified lines1486 rv = os.environ.get(envvar)1487 if rv is not None:1488 return rv1489 else:1486- return os.environ.get(self.envvar)1490+ rv = os.environ.get(self.envvar)1491 1492+ if rv != "":1493+ return rv1494+1495 def value_from_envvar(self, ctx):1496 rv = self.resolve_envvar_value(ctx)1497 if rv is not None and self.nargs != 1:1498 rv = self.type.split_envvar_value(rv)395 unmodified linesmodified:tests/test_options.py+11 added
111 unmodified lines112 assert result.exception113 assert 'Error: Missing option "-m" / "--message".' in result.output114 115 116+def test_empty_envvar(runner):117+ @click.command()118+ @click.option('--mypath', type=click.Path(exists=True), envvar='MYPATH')119+ def cli(mypath):120+ click.echo('mypath: %s' % mypath)121+122+ result = runner.invoke(cli, [], env={'MYPATH': ''})123+ assert result.exit_code == 0124+ assert result.output == 'mypath: None\n'125+126+127 def test_multiple_envvar(runner):128 @click.command()129 @click.option('--arg', multiple=True)130 def cmd(arg):385 unmodified linesmodified:CHANGES.rst+2 added-1 removed
23 unmodified lines24 - Add ``no_args_is_help`` option to ``click.Command``, defaults to25 False :pr:`1167`26 - Add ``show_defaults`` parameter to ``Context`` to enable showing27 defaults globally. :issue:`1018`28+- Handle ``env MYPATH=''`` as though the option were not passed.29+ :issue:`1196`30 29-31 Version 7.032 -----------33 34 Released 2018-09-25538 unmodified lines