AcademySoftwareFoundation / rez

An integrated package configuration, build and deployment system for software
https://rez.readthedocs.io
Apache License 2.0
949 stars 338 forks source link

Rez env strips double dash in command #1462

Open johhnry opened 1 year ago

johhnry commented 1 year ago

Hi,

I want to pass arguments to a Blender Python script through the command line as described here.

I should be able to do this using Rez:

$ rez env blender -- blender -b --python script.py -- -s "test"

It works when running it in a new Rez shell but not when running the command directly with double dash.

Environment

To Reproduce

# test.py
import sys

if __name__ == "__main__":
    print(sys.argv)

Running the command:

$ rez env python -- python test.py -- -s "test"

Expected behavior

Should print the following:

['test.py', '--', '-s', 'test']

Actual behavior

Instead it strips out the arguments after the -- (double dashes):

['test.py']
JeanChristopheMorinPerso commented 1 year ago

Hi @johhnry, I think you can just do rez env python -- python test.py -s "test" and it'll work. When I test locally it works as expected:

[jcmorin@arch01 /tmp]$ rez-env python -- python test.py -s "asd"
['test.py', '-s', 'asd']

Or do you have a specific reason to need the second --?

johhnry commented 1 year ago

Hi @JeanChristopheMorinPerso,

The specific reason to use -- is passing arguments to a Blender python script like I described earlier:

$ rez env blender -- blender -b --python script.py -- -s "test"

Since if I pass them after the --python script.py, they will be parsed as Blender arguments. (Blender ignore all arguments after the -- so it's convenient to pass them here)

instinct-vfx commented 1 year ago

What platform / shell are you using? If i am not mistaken -- is a shell feature. Can you maybe escape it?

JeanChristopheMorinPerso commented 1 year ago

I know that we do control -- in Rez. Not sure if it works I cmd though, but I am under the impression it works in PowerShell...

johhnry commented 1 year ago

@instinct-vfx I am using Powershell in Windows Terminal but it also does the same behavior in cmd:

# In a Rez resolved shell (cmd)
$ blender -b --python test.py -- -s "test"
['blender', '-b', '--python', 'test.py', '--', '-s', 'test']

# In cmd
$ rez env blender -- blender -b --python test.py -- -s "test"
['blender', '-b', '--python', 'test.py']
JeanChristopheMorinPerso commented 1 year ago

Yes, I expect the behavior to be the same. -- is handled by the program, not the OS.

dbr commented 1 year ago

I ran into this with nested rez env commands, for example

$ rez env python -- rez env python -- python3

..which I would expect to execute the python3 command, however it just runs the second rez env command without arguments(?)

As I understand, it should function the same as either of these two options:

$ rez env python
> $ rez env python
>> $ python 3

or

$ rez env python -c 'rez env python -c "python3"'
herronelou commented 1 year ago

I have run into the same issue and had posted about it on Slack, adding the link here for posterity.

https://academysoftwarefdn.slack.com/archives/C0321B828FM/p1694028568579839

dbr commented 8 months ago

Ran into this issue again today, using the Rez integration in Deadline.

I tried to submit a command line job which ran something like rez env example_pkg -- example

However, the included-by-default Rez event plugin for Deadline essentially does

rez env $packages_from_submission etc -- $user_command

So, with $user_command is the above example command, what will be executed is:

rez env $packages_from_submission etc -- rez env example_pkg -- example

which of course triggers this bug (resulting in the task executing an interactive shell and getting stuck forever)