ignore empty env vars consistently
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent 25a8879 · Browse files · 2 files·+19 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+19 added−3 removed
- other:+19 added−3 removed
Provenance
- Commit
ffe7a3b- Tree
6736bbf- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
25a8879
2 files changed+19 added−3 removed
modified:src/click/core.py+16 added-3 removed
2023 unmodified lines2024 2025 def resolve_envvar_value(self, ctx):2026 if self.envvar is None:2027 return2028+2029 if isinstance(self.envvar, (tuple, list)):2030 for envvar in self.envvar:2031 rv = os.environ.get(envvar)2031- if rv is not None:2032+2033+ if rv:2034 return rv2035 else:2036 rv = os.environ.get(self.envvar)2037 2036- if rv != "":2038+ if rv:2039 return rv2040 2041 def value_from_envvar(self, ctx):2042 rv = self.resolve_envvar_value(ctx)2043+2044 if rv is not None and self.nargs != 1:2045 rv = self.type.split_envvar_value(rv)2046+2047 return rv2048 2049 def handle_parse_result(self, ctx, opts, args):2050 with augment_usage_errors(ctx, param=self):376 unmodified lines2427 rv = super().resolve_envvar_value(ctx)2428 2429 if rv is not None:2430 return rv2431+2432 if self.allow_from_autoenv and ctx.auto_envvar_prefix is not None:2433 envvar = f"{ctx.auto_envvar_prefix}_{self.name.upper()}"2429- return os.environ.get(envvar)2434+ rv = os.environ.get(envvar)2435 2436+ if rv:2437+ return rv2438+2439 def value_from_envvar(self, ctx):2440 rv = self.resolve_envvar_value(ctx)2441+2442 if rv is None:2443 return None2444+2445 value_depth = (self.nargs != 1) + bool(self.multiple)2446+2447 if value_depth > 0 and rv is not None:2448 rv = self.type.split_envvar_value(rv)2449+2450 if self.multiple and self.nargs != 1:2451 rv = batch(rv, self.nargs)2452+2453 return rv2454 2455 def consume_value(self, ctx, opts):2456 value, source = super().consume_value(ctx, opts)79 unmodified linesmodified:CHANGES.rst+3 added
129 unmodified lines130 - Options with ``nargs`` > 1 no longer raise an error if a default is131 not given. Parameters with ``nargs`` > 1 default to ``None``, and132 parameters with ``multiple=True`` or ``nargs=-1`` default to an133 empty tuple. :issue:`472`134+- Handle empty env vars as though the option were not passed. This135+ extends the change introduced in 7.1 to be consistent in more cases.136+ :issue:`1285`137 138 139 Version 7.1.2140 -------------635 unmodified lines