Skip to content

Commit

Permalink
skymarshal: only parse argfiles for the first argument
Browse files Browse the repository at this point in the history
We want to pass some arguments to skymarshal that start with @. argparse was
trying to expand these as if they were argfiles. Here we switch to only
trying to interpret the first argument as an argfile, which should be all
that's necessary.

Topic: skymarshal-narrow-argfile
GitOrigin-RevId: 3d93c30e0565d7515acf7036e029c774d2bd32ff
  • Loading branch information
william-smith-skydio authored and aaron-skydio committed Apr 17, 2023
1 parent 2683835 commit 61d70f0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions third_party/skymarshal/skymarshal/skymarshal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import argparse
import os
import shlex
import sys
import typing as T

import six
Expand All @@ -17,7 +19,7 @@
def parse_args(languages, args=None):
# type: (T.Sequence[T.Type[SkymarshalLanguage]], T.Optional[T.Sequence[str]]) -> argparse.Namespace
"""Parse the argument list and return an options object."""
parser = argparse.ArgumentParser(description=__doc__, fromfile_prefix_chars="@")
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("source_path", nargs="+")
parser.add_argument("--debug-tokens", action="store_true")
parser.add_argument("--print-def", action="store_true")
Expand All @@ -43,7 +45,17 @@ def parse_args(languages, args=None):
options = parser.parse_args(args)
else:
# Use the command-line args.
options = parser.parse_args()

# NOTE(will): Support argfiles, e.g. @argfile as the first argument. argparse supports this
# directly with fromfile_prefix_chars="@", but this was causing issues for any arguments
# that started with @, even if those arguments were inside the argfile. This approach is
# much narrower in only supporting an argfile as the first argument.
if len(sys.argv) >= 2 and sys.argv[1].startswith("@"):
with open(sys.argv[1][1:]) as argfile:
args = shlex.split(argfile.read())
options = parser.parse_args(args + sys.argv[2:])
else:
options = parser.parse_args()

return options

Expand Down

0 comments on commit 61d70f0

Please sign in to comment.