Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recent change in xonsh seems to have broken direnv #2

Closed
con-f-use opened this issue Oct 23, 2019 · 3 comments · Fixed by #3
Closed

Recent change in xonsh seems to have broken direnv #2

con-f-use opened this issue Oct 23, 2019 · 3 comments · Fixed by #3

Comments

@con-f-use
Copy link
Collaborator

con-f-use commented Oct 23, 2019

One of the recent changes to xonsh seems to have broken xonsh-direnv

$ cd atdiff                                                                           
direnv: loading .envrc
direnv: export +VIRTUAL_ENV ~PATH
{
  "DIRENV_DIFF": "eJzkkt1umzAYhu_FxwE30CSDMygwSFOWEeePEwuw-UnBEAwBUuXepy1bM63TNE0765mf198jWa-_F1AB9QUsNWQDFcC0LCg8BAyKeRkFOQwzpt7CP9FvBTEqWZwlcAhIQcomznLKryMtr-HV4L_wK94uvh2u-JolQUH5z973gLOg-n8PBZcRYF8LMhzPdDfYcDygAuEmEnqiOYxaEsCgIVkcg9GP2a2GHmxzBVRA5z0_c-uxN7TPeqvLQ8h4YSNUUEZKQSdLbUBLafos3Tnyttv1cigvTtywFbxHu-M47tJzyfOxzmb-qtt_tLA1farnZPs4kTq7bm0n7HkVRnWXdmfvLmcIDeZEUKTpLOoULH2SBVOny3lTU8lYNW1vF2jBmeQ5fFt5qWVNkNP7Y9u9x8mzXx216N6ZFIa7L62ndbIWWsl_qFvleDj7BxySGdYSTcNYKdz1zgGjt8vzphQokqym7ASroUlLJsjiVPzwN__yDjduBDaOh9baApvu5h9qBZfLlwAAAP__lzpRYQ==",
  "DIRENV_DIR": "-/home/confus/atdiff",
  "DIRENV_WATCHES": "eJxszsFKxDAQBuB3ybnsmHTTmendo-BdPAyTP26k20I3WwXx3b3LvsDH9_YTXq1fwhzosl1Bn7ZSwYGF_F6MrJdWK52wHruHIbxspbcrwhwzR0lnTTyE5-9267cw9_2O3-EBePJtre2DStuxHmTLsn2RIsWpRhFF5TIxZ1HN4_gkZpqAc4I5mDNYoFMUgU-u2ZCru9qjzZj_bd7_AgAA__9mNUXI",
  "PATH": "/home/confus/atdiff/.direnv/python-3.6.8/bin:/home/confus/.local/bin:/home/confus/bin:/home/confus/bin:/home/confus/.local/bin:/home/confus/.config/yadmdotfiles/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/confus/bin:/home/confus/.local/bin:/home/confus/.config/yadmdotfiles/bin",
  "VIRTUAL_ENV": "/home/confus/atdiff/.direnv/python-3.6.8"

$ which python                                                                        
/usr/bin/python      # so no env loaded!

$ xonfig                                                                              
+------------------+----------------------+
| xonsh            | 0.9.13               |
| Git SHA          | 550d70d2             |
| Commit Date      | May 22 01:42:07 2019 |
| Python           | 3.6.8                |
| PLY              | 3.11                 |
| have readline    | True                 |
| prompt toolkit   | 2.0.9                |
| shell type       | prompt_toolkit2      |
| pygments         | 2.2.0                |
| on posix         | True                 |
| on linux         | True                 |
| distro           | ubuntu               |
| on darwin        | False                |
| on windows       | False                |
| on cygwin        | False                |
| on msys2         | False                |
| is superuser     | False                |
| default encoding | utf-8                |
| xonsh encoding   | utf-8                |
| encoding errors  | surrogateescape      |
+------------------+----------------------+

This seems to effect both newly created environments and preexisting ones. Bash and other shells are not effected. See xonsh/xonsh#3369

@con-f-use
Copy link
Collaborator Author

con-f-use commented Oct 23, 2019

Seems to be related to to this: xonsh/xonsh#3369
I have made #3 to fix it in xonsh-direnv. I think this will make xonsh-direnv more robust, even once the problem is fixed upstream in xonsh.

@con-f-use
Copy link
Collaborator Author

con-f-use commented Oct 24, 2019

Welp, might be necessary to set $UPDATE_OS_ENVIRON=True in xonsh or do this (or a similar) fix, depending on xonsh and direnv version:

def __direnv():
    p = subprocess.Popen(
        'direnv export json'.split(),
        stdout=subprocess.PIPE,
        env=__xonsh__.env.detype()
    )
    r, _ = p.communicate()
    if len(r) > 0:
        for k, v in json.loads(r).items():
            if v is None:
                del (__xonsh__.env[k])
            else:
                __xonsh__.env[k] = v

or set $UPDATE_OS_ENVIRON = True in xonsh.

See: xonsh/xonsh#3371

@t184256
Copy link
Contributor

t184256 commented Oct 27, 2019

@con-f-use: definitely.

I'm making do with $UPDATE_OS_ENVIRON in the meantime, but we probably still need do changes with respect to the type conversion.

I think this one warrants a reopening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants