Techcable / zsh2xonsh

A highly-compatible translator from zsh -> xonsh
MIT License
3 stars 0 forks source link

TODO: Add tests #3

Open Techcable opened 2 years ago

Techcable commented 2 years ago

This is hard (not just because I'm lazy), but also because we often want to execute the translated commands under a "clean" xonsh environment and not just verify they parse.....

However, getting a clean xonsh environment for testing would be difficult, because we're often running under xonsh or with an already modified $PATH.

This is especially true in my case because I use zsh2xonsh already in my .xonshrc 😉. Maybe we could use --no-rc and scrub the environment variables back to the original?

Alternatively, maybe we can spawn up zsh -f -c 'echo $PATH' to get a semi-clean path (or xonsh --no-rc)? We have to be careful not to inherit any environment variables besides the default one.

EDIT: xonsh --no-rc seems to work well using the following command.

from subprocess import run, PIPE, DEVNULL
run([sys.executable, '-m', 'xonsh', '--no-rc', '-c' 'echo $PATH'], env={}, stdout=PIPE, stderr=DEVNULL, encoding='utf-8').stdout.rstrip('\n')

I suggest we use this to bootstrap $PATH and $PYTHON_PATH, wiping other non-essential environment vars :)

This should give us a somewhat clean slate (while also respecting homebrew python).

andrewgazelka commented 1 year ago

This is especially true in my case because I use zsh2xonsh already in my .xonshrc 😉. Maybe we could use --no-rc and scrub the environment variables back to the original?

Why does this make it more difficult? I am probs being dumb, but I am not following.