drewdeponte / sublime_guard

Sublime Text 2 Guard Plugin - helps create a smoother development workflow.
MIT License
175 stars 15 forks source link

Arch Linux environment variables not passed to Sublime Text 2 when launched via launcher. #41

Closed BoGs closed 7 years ago

BoGs commented 12 years ago

I am looking at some environment variables and am at a loss for words. I reverted the changes back to the branch to have #!/usr/bin/env python as the shebang line.

This broke the guard plugin because it reverted back to my python 3.2.2 install. Then I updated the $PATH variable to include PATH=$HOME/bin:$PATH and also created a symlink within my $HOME/bin to the ln -s /usr/bin/python2.7 ~/bin/python, reloaded the zsh environment using source ~/.zshrc and finally

% python --version
Python 2.7.2

I am at a loss any ideas?

BoGs commented 12 years ago

When starting it just shows the black window. I do get the notifications that guard started and is running in the background just not displaying output in the window at the bottom of the app.

When trying to stop guard I get the following:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.2/threading.py", line 740, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.2/threading.py", line 693, in run
    self._target(*self._args, **self._kwargs)
  File "/home/<user>/.config/sublime-text-2/Packages/Guard/guard_wrapper", line 54, in read_stdout
    sys.stdout.write(data)
TypeError: must be str, not bytes

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.2/threading.py", line 740, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.2/threading.py", line 693, in run
    self._target(*self._args, **self._kwargs)
  File "/home/<user>/.config/sublime-text-2/Packages/Guard/guard_wrapper", line 65, in read_stderr
    sys.stderr.write(data)
TypeError: must be str, not bytes

Traceback (most recent call last):
  File "/home/<user>/.config/sublime-text-2/Packages/Guard/guard_wrapper", line 74, in <module>
    wrap.run_cmd(sys.argv[1:])
  File "/home/<user>/.config/sublime-text-2/Packages/Guard/guard_wrapper", line 34, in run_cmd
    self.proc.stdin.write(data)
TypeError: 'str' does not support the buffer interface
drewdeponte commented 12 years ago

@BoGs , interesting. So, this tells us there is definitely an issue with it working correctly with Python 3.2. I have created a separate issue for this at issue #42.

In terms of your environment I am curious how you are launching Sublime Text 2. The reason I ask is because on Mac OS X depending on how you launch the app it gets different environments. For example if you launch it from the shell which has your environment setup then Sublime Text 2 has the same environment that that your shell did. However, if you launch it from the Mac OS X Launcher or by double clicking a file in Mac OS X it opens it with a completely different environment.

I am wondering if you a similar situation is happening with you. Are you launching it from the shell with the updated PATH environment variable?

BoGs commented 12 years ago

@cyphactor I tried to load it both the ways you mentioned, I loaded it from the command line and it worked (using the new python2.7 sym link from the home bin) and then tried with the launcher and it did not work. My launcher command is just subl %U which I assume would use my environment variables since it is running as me.

Would it not use the same environment variables be used if launched from the shell or the window manager (link icon) since it is running as the current user?

drewdeponte commented 12 years ago

@BoGs ah so it is the same issue. Actually, your environment is not tied to your user account. It is tied to the shell that is launching Sublime Text 2. So in the case where you run it from the shell it is working because your shell is setting its environment up properly using your ~/.zshrc and your symlink.

In the case of your launcher. It is handing what ever its environment is to Sublime Text 2. It's environment is most likely based on the environment of the process that launched it, and so forth back down the chain until you get back to the base launcher for it.

In some linux distros (not sure if this is the case for Arch) you have an ~/.xinitrc file which initializes your X environment . If this is the case you can try slamming the export PATH stuff from your ~/.zshrc into the ~/.xinitrc and that may work.

The other thing that I could think to try would be to specify the export PATH stuff inside /etc/profile which is usually the system environment configuration file.

Please let me know if either of those work for you. If not I will keep dig into Arch a bit and see what I can figure out.

What is the launcher you are using called? Is it the default launcher for Arch? Do you know if Arch has you setup with Gnome, KDE, or some other desktop environment?

BoGs commented 12 years ago

So I got to the point of messing up my whole home directory :) - I tried to export the path within the ~/.xinitrc and did not seem to help within my current environment.

I have found a couple of things:

  1. When starting in python 3.2 (as the bug above) the process is actually not shutdown in the background just a fyi
  2. My current environment is the most up-to-date arch package with XFCE4 running ( initially I was launching LXDM to manage my login sessions, but I have stopped that and now just using startx which likes my ~/.zshrc
  3. I installed sublime text using the aur package at http://aur.archlinux.org/packages.php?ID=52754 which creates the links and installs the package to /opt/

As for how arch is setup, you can install whatever desktop environments your heart wishes, the reason I like it is it's FAST! and I have an older CPU.

I personally would not want to touch the /etc/profile file, I will try looking online for some more ideas, or maybe even sublime text support / forums might know?

If you want me to try anything else let me know :)

drewdeponte commented 12 years ago

@BoGs I was reviewing issues and noticed that I still had this ticket lying around. After reading through it again I had another idea which might work for you.

I noticed that you mentioned you are launching it using subl %U. This made me wonder if you could explicitly launch it in your shell by using the -c option in zsh. It might look something like zsh -c 'subl %U' but do look at the docs to verify. I am not sure that this will work but just another thought of something to try.

If the above doesn't work I would suggest digging into the other options for zsh to see if there is a way to force it to load your environment for the command that it is running. I would imagine there would be one but not sure off hand.

drewdeponte commented 12 years ago

I have tagged this as a related discussion as well now because it technically isn't a problem with Sublime Guard. It is an standard environment issue with launchers in systems. If anything there should be documentation on how to solve this problem with respect to Sublime Text 2 or maybe even at the OS level documentation somewhere. However, since it is in my opinion such a valuable issue to eventually find a solution for I am glad to keep the conversation going here.

Eventually, I will house documentation here for it. That is once we figure out some intelligent solutions for this issue.

drewdeponte commented 12 years ago

@BoGs, I created a python3_support branch. It would be awesome if you could try this and see if it resolves your issues. It is still very much under testing and it could have things broken. But, it would be good to get some testing on other peoples environments.