Unverified Commit e4fd5e39 authored by Bram Vanroy's avatar Bram Vanroy Committed by GitHub
Browse files

Use with_extension to change the extension (#4203)

As per https://github.com/huggingface/transformers/pull/3934#discussion_r421307659
parent ebf80e2e
......@@ -11,10 +11,6 @@ DataClass = NewType("DataClass", Any)
DataClassType = NewType("DataClassType", Any)
def trim_suffix(s: str, suffix: str):
return s if not s.endswith(suffix) or len(suffix) == 0 else s[: -len(suffix)]
class HfArgumentParser(ArgumentParser):
"""
This subclass of `argparse.ArgumentParser` uses type hints on dataclasses
......@@ -109,8 +105,7 @@ class HfArgumentParser(ArgumentParser):
(same as argparse.ArgumentParser.parse_known_args)
"""
if look_for_args_file and len(sys.argv):
basename = trim_suffix(sys.argv[0], ".py")
args_file = Path(f"{basename}.args")
args_file = Path(sys.argv[0]).with_suffix(".args")
if args_file.exists():
fargs = args_file.read_text().split()
args = fargs + args if args is not None else fargs + sys.argv[1:]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment