bcomnes / sublime-standard-format

:sparkles: Runs standard --fix against the javascript in your ST3 window on save or manually.
https://packagecontrol.io/packages/StandardFormat
MIT License
60 stars 21 forks source link

Breaks the PATH environment variable #63

Closed adnanademovic closed 7 years ago

adnanademovic commented 7 years ago

Path variable gets changed to "agent pid ". Suffice to say, causes lots of things to fail outside the package, including other packages.

I assume it's standard-format.py#L123 that's the culprit here.

bcomnes commented 7 years ago

What OS are you running on?

adnanademovic commented 7 years ago

Linux

bcomnes commented 7 years ago

It tries to calculate the users real path by running https://github.com/bcomnes/sublime-standard-format/blob/master/StandardFormat.sublime-settings#L56 This isn't guaranteed to work on all systems, but in my tests works alright. Any ideas on how to improve that?

bcomnes commented 7 years ago

This behavior can also be disabled here: https://github.com/bcomnes/sublime-standard-format/blob/master/StandardFormat.sublime-settings#L53

adnanademovic commented 7 years ago

The only problem is that it's changing the process' path variable. I assume you're doing that for the subprocess. Python's subprocess.Popen has an optional env parameter. You can extend the existing environment if that is your desire, and it will work as if you modified the actual env. I just tested the following code with a dummy example.

myenv = dict(os.environ) # Shallow copy of environment

# either
myenv['PATH'] += ':' + your_extra_path_stuff
# or
myenv['PATH'] = your_extra_path_stuff
# (I'm half-asleep, so I'm having a hard time figuring out what your desired solution is)

# Then, whenever you call Popen
suprocess.Popen( <the args that you used>, env=myenv)

Gonna go to sleep now

bcomnes commented 7 years ago

I don't think I intended to modify the process env. I'll take a look.

adnanademovic commented 7 years ago

I've made a fix that works nicely on my end