Open hughetop opened 1 year ago
Another interesting side effect about the alias command with cmd (doskey) is that they aren't there in a ResolvedContext. Ex: if the blender package.py uses the alias function in commands:
rez-env rez python-3.9
> python
>>> from rez.resolved_context import ResolvedContext
>>> context = ResolvedContext(['blender'])
>>> context.which('blender')
>>> # None
However, if the package.py commands function is this instead:
def commands():
env.PATH.prepend(r'C:\Program Files\Blender Foundation\Blender 3.1')
then context.which('blender')
works correctly. So I've been adding directories to $PATH instead of using the alias function.
Edit: this workaround works for now, but I prefer the explicit "this command runs this exact executable" of the alias function, rather than "look for something in the %PATH% and run it, yolo" of adding to the PATH.
Forgot to update this, I have since switched over to using .bat files in a package /bin directory for custom executables. For software like python or Blender I still prepend it's directory to $PATH.
Hi @hughetop,
I found that to remove a macro with doskey, you can do the following:
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/doskey#code-try-11
A solution could to have a hook on the shell process exit and then unregister the aliases we defined earlier?
Yeah, I noticed how to delete the macro entry, but I don't know if that' something rez would handle or if all our packages would do that. I'm not using aliases with cmd anymore though, so this hasn't been a priority for me.
yes I don't know either, I needed to run a Python script in the bin directory so I went with a cmd script that calls python.exe ... and added that to the path
While testing on windows I noticed that the "doskey" macros created with the
alias
command persist outside of the resulting rez environment. So if you have a package.py file like:Then after doing
rez-env blender
I can runblender
and it will launch Blender. Awesome! The problem is that after exiting the rez environment, the 'blender' alias still exists. This was causing some weird problems when testing with multiple versions of software and multiple softwares. Ideally when the rez environment is exited, it should "unalias" any aliases. On windows, this would be doingdoskey blender=
to remove the macro.Environment
To Reproduce
Expected behavior The command should not exist since the rez environment was exited.
Actual behavior It runs the alias, which can error due to the environment being invalid.