Skip to content

Commit b8b6433

Browse files
committed
Switch default config file parsing behavior to shlex.
- The parameter to `parse_args` is now `legacy_config_parsing`. - All existing test cases already pass with the default `shlex`.
1 parent f3e692d commit b8b6433

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

tap/tap.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,13 @@ def _log_all(self, repo_path: Optional[str] = None) -> Dict[str, Any]:
385385
def parse_args(self: TapType,
386386
args: Optional[Sequence[str]] = None,
387387
known_only: bool = False,
388-
parse_config_files_with_shlex = False) -> TapType:
388+
legacy_config_parsing = False) -> TapType:
389389
"""Parses arguments, sets attributes of self equal to the parsed arguments, and processes arguments.
390390
391391
:param args: List of strings to parse. The default is taken from `sys.argv`.
392392
:param known_only: If true, ignores extra arguments and only parses known arguments.
393393
Unparsed arguments are saved to self.extra_args.
394+
:legacy_config_parsing: If true, config files are parsed using `str.split` instead of `shlex.split`.
394395
:return: self, which is a Tap instance containing all of the parsed args.
395396
"""
396397
# Prevent double parsing
@@ -399,10 +400,10 @@ def parse_args(self: TapType,
399400

400401
# Collect arguments from all of the configs
401402

402-
if parse_config_files_with_shlex:
403-
splitter = lambda arg_string: split(arg_string, comments=True)
404-
else:
403+
if legacy_config_parsing:
405404
splitter = lambda arg_string: arg_string.split()
405+
else:
406+
splitter = lambda arg_string: split(arg_string, comments=True)
406407

407408
config_args = [arg for args_from_config in self.args_from_configs for arg in splitter(args_from_config)]
408409

tests/test_load_config_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class ShlexConfigTap(Tap):
146146
with open(fname, 'w') as f:
147147
f.write('--a 21 # Important arg value\n\n# Multi-word quoted string\n--b "two three four"')
148148

149-
args = ShlexConfigTap(config_files=[fname]).parse_args(parse_config_files_with_shlex=True)
149+
args = ShlexConfigTap(config_files=[fname]).parse_args()
150150

151151
self.assertEqual(args.a, 21)
152152
self.assertEqual(args.b, 'two three four')

0 commit comments

Comments
 (0)