Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent alias (windows function) to store all arguments in one string instead of an array of strings #1101

Conversation

aguiot
Copy link

@aguiot aguiot commented Jun 29, 2021

Hi,

We are facing an issue when defining alias in the package.py of a windows package.
Arguments passed to the python script defined in the alias receive all arguments in one string instead of an array of strings.

Here is a way to reproduce it:

  1. the python script (test/ test_arg.py)
# coding: utf8

import sys
import argparse  # noqa: I100


if __name__ == "__main__":

    argv = sys.argv[1:]

    parser = argparse.ArgumentParser()
    parser.add_argument("foo", type=str)
    parser.add_argument("-b", "--bar", type=str, default="toto")
    args = parser.parse_args(argv)

    print(argv)
    print(args)
  1. the alias defined test package (test/package.py)
    import os

    alias(
        "arg_test",
        "python {}".format(
            os.path.join("{root}", "test_arg.py")
        ),
    )
  1. tests

When calling arg_test like this: rez env test -- arg_test blah --bar titi, we would expect:
argv = ['blah', '--bar', 'titi'] and args = Namespace(bar='titi', foo='blah')

But unfortunately, we have
argv = ['blah --bar titi'] and args = Namespace(bar='toto', foo='blah --bar titi')

because the sys.argv is not split

@nerdvegas nerdvegas merged commit fadd3eb into AcademySoftwareFoundation:master Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants