[Python-ideas] argparse.ArgumentParser: include arguments from files with relative paths

Robert Schindler robert at shajil.de
Tue Aug 29 04:38:58 EDT 2017


Hello,

I'm often using ArgumentParser in my projects, as well as its ability to
read argument lists from files. However, the problem is that nested
includes of such argument files have to specify paths relative to
os.getcwd(), no matter where the file containing the include statement
is located. Currently, this can be circumvented by always using absolute
paths. But imho that is not a practical solution, due to the obvious
portability issues it causes.

I suggest adding a new parameter to argparse.ArgumentParser that
controls the behaviour:

   * fromfile_parent_relative_ - Whether to treat paths of included argument
     files as relative to the location of the file they are specified in
     (``True``) or to the current working directory (``False``)
     (default: ``False``)

Doing so would allow users to choose between the two different strategies
while keeping backwards compatibility.

I made a pull request [1] which adds the functionality + docs to
demonstrate a possible solution.

What do you think about this enhancement?

Please note this is my first contribution to cpython. I now know that I
should have presented it to python-ideas before starting a pull request.
Sorry for doing it the wrong way around.

Best regards
Robert

[1] https://github.com/python/cpython/pull/1698
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170829/3755682a/attachment.sig>


More information about the Python-ideas mailing list