Repository navigation
Patch Environment On OSX And Allow A Different Environment Per Window - #11054
Conversation
| env.PATH | ||
|
|
||
| getShellEnv: -> | ||
| shell = process.env.SHELL ? "/bin/bash" |
There was a problem hiding this comment.
I just tried it and it doesn't give accurate terminal results for $PATH me on my mac
# From terminal
/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/steel/n/bin:/usr/games/bin
# From executing this
/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
There was a problem hiding this comment.
We ran into the same problem when working with linters, we ended up creating consistent-path and consistent-env. Both are very battle tested and used by almost all of the linter providers.
consistent-path is a consistent-env dependent package which provides just the PATH, but looks like you could use consistent-env here
Note: Both of these are npm packages and not apm packages
There was a problem hiding this comment.
@lee-dohm If you replace the --login flag with --interactive this should work as intended ✨
There was a problem hiding this comment.
@thomasjo That would break linux because Atom is spawned on linux with nohup, see https://github.com/steelbrain/nohup-shell-hanging-bug
There was a problem hiding this comment.
@steelbrain the shell launching should not be done on any platform other than OS X. Consequently, nothing should break on Linux.
There was a problem hiding this comment.
@joefitzgerald There are several pairs of Desktop Environments and shells on Linux that do not supply ENV correctly to apps not run from terminal, most notably GNOME Shell and ZSH. Therefore we do need to fix it there as well
There was a problem hiding this comment.
Well we don't need to in this PR; this PR is intended to solve for the OS X issue, and add a project level API for the environment.
That doesn't preclude more cases beyond OS X; can you please open up (or link) an issue for each additional scenario, describing steps to reproduce, and desired behavior?
There was a problem hiding this comment.
@steelbrain Correct me if I'm wrong, but that has nothing to do with the DE nor the shell. What you're describing would be distribution-specific configuration problems. There are lots of silly *nix distributions out there with horrible defaults.
But if this truly is a problem (in particular the HUP scenario described earlier), then we'll just have to deal with it.
There was a problem hiding this comment.
Well we don't need to in this PR; this PR is intended to solve for the OS X issue, and add a project level API for the environment.
Agreed! We can patch other problems at a later point, once we can reliably reproduce the anecdotal reports.
There was a problem hiding this comment.
@joefitzgerald @thomasjo What do you guys have against the npm modules I suggested? It takes care of all the scenarios and fixes this for everyone not just the handful few
|
This is still not complete but I wanted to push up what I have so far. I decided to include patching |
|
|
||
| # Patch the `process.env` on startup to fix the problem first documented | ||
| # in #4126 | ||
| process.env = @project.getEnv() |
There was a problem hiding this comment.
This is going to make it less clean, but this should happen prior to packages being loaded. I.e. prior to @project being defined. Think of all the activities that packages may do on activation that they should not be doing during activation (but still are doing) that are dependent on process.env.
There was a problem hiding this comment.
If you move the patching logic such that it is executed in the first atom-environment, then maybe @project.getEnv() could be renamed to be @project.env. Perhaps we could also externalize the logic into a file that is only required if patching is needed (javascript FTW?).
There was a problem hiding this comment.
Thanks for the ideas. I'll take a deeper look at this later tonight or tomorrow.
There was a problem hiding this comment.
then maybe
@project.getEnv()could be renamed to be@project.env
That would lose us the current feature that packages can't muck up the environment for other packages (at least through the public API). Right now, everyone gets a copy and then they can do what they want with their copy.
I'll definitely move the first initialization further up though.
There was a problem hiding this comment.
Yeah, fair enough on making it a function:
project.getEnv()?project.env()?project.environment()?
There was a problem hiding this comment.
Looking deeper, it appears that packages aren't loaded until AtomEnvironment.startEditorWindow:
So doing the patching of the environment in the AtomEnvironment constructor does make it happen before packages are loaded.
There was a problem hiding this comment.
Personally, I was sticking with just "env" as the main part of the name to make it familiar to Node developers and process.env. I added "get" to the front to make it clear it is a function rather than just an attribute (and all of the other public APIs have a verb in the front). I can totally be swayed though.
|
I don't think we should make a new API for fetching environment variables. I think we should extend the existing API so it works correctly despite our multi-process setup, which shouldn't be that relevant to Atom users. The only justifications I could see for inventing something new would be the following:
|
|
Yep @nathansobo i've already made the requisite changes :) Pushing the commits shortly. |
- Convert environment.coffee and environment-spec.coffee to JavaScript - Pass the process's environment across the wire when launching atom multiple times from the command line
7f569e9 to
6b38049
Compare
| delete process._originalEnv | ||
| options = { | ||
| platform: process.platform, | ||
| env: _.clone(process.env) |
There was a problem hiding this comment.
I'll try it out. I haven't used it before. If it works the same, I'll update it.
I found that many Linux/OSX users tend to customize their environment in rc file ( It's true that running interactive shell can lead to problems. But running login shell can too. For example, I run |
|
Hey, since I tried to solve this problem in script-runner I thought I'd chime in here. Firstly, for people running things like RVM, or the equivalent for python, you definitely want to get the environment from an interactive login shell, or you won't get the right things. We tried tied to extract this into a separate module, called shell-environment, ideally so that other "script runner" packages could use it.. or in general, anyone who wanted to get a useful "environment" for running user commands. We also had some issues on Linux where things like DISPLAY were not getting set and this might be unintuitive for users who are expecting things to "just work". If you look at the approach we took in shell-environment, you'll see we avoided many of the issues of using an interactive shell by piping the results of |
|
I have discovered another minutia missing from this patch. Unless Atom is launched from the terminal, |
|
@gnestor I think |
|
@lee-dohm Ok so it sounds like this is a separate issue. Do you agree though that Atom should correctly set |
|
@gnestor No, I don't agree that |
|
In most of 1.12 betas (I'm on 1.12.0-beta7 at the moment on Sierra 10.12) there's a problem with new windows. If you open from OS X dock and inspect process.env, all is fine and wonderful in the world/window. When you go to File -> New Window, and inspect process.env on the new window, it does not include any of the environment variables, anything from login is gone. I haven't had change to inspect things but seems might be an issue with inheriting environment when creating new windows. I can't find a related issue to this either. |
|
It looks like the new-window events etc don't pass in the current atom/src/main-process/atom-application.coffee Line 210 in e5cfc6b I'll raise a new issue for it this week, maybe even attempt a fix. |
|
@driskell Have you filed an Issue on this behavior? |
|
Same issue here. |
|
Yes, when I start ATOM from the terminal, it works. When I try to launch from the Dock it does not have the Path configured. |
|
Guys, the Iterm2 plugin was causing the bug. Thanks. |

Create anatom.project.getEnvAPIPATHon OS X whenTERMis not setprocess.envon startupFixes #11037
Fixes #6956