Hi,
Currently `detached.el` does not seem to work with `direnv`. For
example, rerunning a command run in a direnv fails since it can not
resolve the env successfully.
Reproduce steps:
1. Install direnv and setup bash config: https://direnv.net/docs/hook.html .
2. Running the following commands:
2.1 mkdir test
2.2 cd test
2.3 echo "layout python" > .envrc
2.4 direnv allow
2.5 pip install numpy
2.6 echo -e 'import numpy as np\nprint(np.random.randn())\n' > test.py
3. In a *shell* buffer run `python test.py` with `detached-shell-send-input`.
4. Kill the shell buffer and maybe go to another directory.
5. Run `detached-rerun-session` and rerun the last session.
6. Observe some error like `ModuleNotFoundError: No module named
'numpy'` (assume no `numpy` is installed in the default Python
site-packages.
Maximin Liebkne <ispinfx@gmail.com> writes:
> Hi,
Hello,
> Currently `detached.el` does not seem to work with `direnv`. For> example, rerunning a command run in a direnv fails since it can not> resolve the env successfully.
In general detached processes doesn't capture the environment it runs in
so it might fail to reproduce the results when it's rerun. However using
direnv is something that would be good to support.
> Reproduce steps:>> 1. Install direnv and setup bash config: https://direnv.net/docs/hook.html .> 2. Running the following commands:> 2.1 mkdir test> 2.2 cd test> 2.3 echo "layout python" > .envrc> 2.4 direnv allow> 2.5 pip install numpy> 2.6 echo -e 'import numpy as np\nprint(np.random.randn())\n' > test.py> 3. In a *shell* buffer run `python test.py` with `detached-shell-send-input`.> 4. Kill the shell buffer and maybe go to another directory.> 5. Run `detached-rerun-session` and rerun the last session.> 6. Observe some error like `ModuleNotFoundError: No module named> 'numpy'` (assume no `numpy` is installed in the default Python> site-packages.
Thanks for the steps, I managed to reproduce the problem with this:
2. Running the following commands:
2.1 mkdir test
2.2 cd test
2.3 echo "export DETACHED=TEST" > .envrc
2.4 direnv allow
3. In a *shell* buffer run `echo $DETACHED` with
`detached-shell-send-input` and observe TEST being the output
4. Run `detached-rerun-session` and rerun the last session.
5. Observe no output
This failure would also occur if you evaluate this lisp expression,
assuming the test directory is located under /tmp
(let ((default-directory "/tmp/test"))
(async-shell-command "echo $DETACHED"))
So the default behavior of Emacs seems to be to not pick up the direnv
environment. Maybe you can experiment with these packages:
- https://github.com/purcell/inheritenv
- https://github.com/purcell/envrc
and see if these can be used to make the `async-shell-command` example
above succeed.
/Niklas
Hi,
I do use `envrc`
(use-package envrc
:diminish envrc-mode
:hook (after-init . envrc-global-mode))
and it works smoothly. The following script
(let ((default-directory "/tmp/test"))
(async-shell-command "echo $DETACHED"))
evaluates to TEST successfully. But `detached-rerun-session` gives me
an empty result.
On Tue, Sep 27, 2022 at 3:25 PM Niklas Eklund <niklas.eklund@posteo.net> wrote:
>> Maximin Liebkne <ispinfx@gmail.com> writes:>> > Hi,>> Hello,>> > Currently `detached.el` does not seem to work with `direnv`. For> > example, rerunning a command run in a direnv fails since it can not> > resolve the env successfully.>> In general detached processes doesn't capture the environment it runs in> so it might fail to reproduce the results when it's rerun. However using> direnv is something that would be good to support.>> > Reproduce steps:> >> > 1. Install direnv and setup bash config: https://direnv.net/docs/hook.html .> > 2. Running the following commands:> > 2.1 mkdir test> > 2.2 cd test> > 2.3 echo "layout python" > .envrc> > 2.4 direnv allow> > 2.5 pip install numpy> > 2.6 echo -e 'import numpy as np\nprint(np.random.randn())\n' > test.py> > 3. In a *shell* buffer run `python test.py` with `detached-shell-send-input`.> > 4. Kill the shell buffer and maybe go to another directory.> > 5. Run `detached-rerun-session` and rerun the last session.> > 6. Observe some error like `ModuleNotFoundError: No module named> > 'numpy'` (assume no `numpy` is installed in the default Python> > site-packages.>> Thanks for the steps, I managed to reproduce the problem with this:>> 2. Running the following commands:> 2.1 mkdir test> 2.2 cd test> 2.3 echo "export DETACHED=TEST" > .envrc> 2.4 direnv allow> 3. In a *shell* buffer run `echo $DETACHED` with> `detached-shell-send-input` and observe TEST being the output> 4. Run `detached-rerun-session` and rerun the last session.> 5. Observe no output>> This failure would also occur if you evaluate this lisp expression,> assuming the test directory is located under /tmp>> (let ((default-directory "/tmp/test"))> (async-shell-command "echo $DETACHED"))>> So the default behavior of Emacs seems to be to not pick up the direnv> environment. Maybe you can experiment with these packages:>> - https://github.com/purcell/inheritenv> - https://github.com/purcell/envrc>> and see if these can be used to make the `async-shell-command` example> above succeed.>> /Niklas
Maximin Liebkne <ispinfx@gmail.com> writes:
> Hi,>> I do use `envrc`>> (use-package envrc> :diminish envrc-mode> :hook (after-init . envrc-global-mode))
I thought I was doing that, but turned out I had set it to :disabled and
forgot about it :P
> and it works smoothly. The following script>> (let ((default-directory "/tmp/test"))> (async-shell-command "echo $DETACHED"))>> evaluates to TEST successfully. But `detached-rerun-session` gives me> an empty result.
The following works for me as well with `envrc` enabled, but there is a
caveat for me. It doesn't work the first time, only the second time when
the async shell command buffer already exists.
Killing the `*Async Shell Command*` buffer and running the expression
above fails for me. Evaluating it a second time succeeds.
Consequently detached-rerun-session fails first time for me but reruning
it again without killing that buffer then it works. Is this behavior
reproduceable for you as well?
/Niklas
> On Tue, Sep 27, 2022 at 3:25 PM Niklas Eklund <niklas.eklund@posteo.net> wrote:>>>> Maximin Liebkne <ispinfx@gmail.com> writes:>>>> > Hi,>>>> Hello,>>>> > Currently `detached.el` does not seem to work with `direnv`. For>> > example, rerunning a command run in a direnv fails since it can not>> > resolve the env successfully.>>>> In general detached processes doesn't capture the environment it runs in>> so it might fail to reproduce the results when it's rerun. However using>> direnv is something that would be good to support.>>>> > Reproduce steps:>> >>> > 1. Install direnv and setup bash config: https://direnv.net/docs/hook.html .>> > 2. Running the following commands:>> > 2.1 mkdir test>> > 2.2 cd test>> > 2.3 echo "layout python" > .envrc>> > 2.4 direnv allow>> > 2.5 pip install numpy>> > 2.6 echo -e 'import numpy as np\nprint(np.random.randn())\n' > test.py>> > 3. In a *shell* buffer run `python test.py` with `detached-shell-send-input`.>> > 4. Kill the shell buffer and maybe go to another directory.>> > 5. Run `detached-rerun-session` and rerun the last session.>> > 6. Observe some error like `ModuleNotFoundError: No module named>> > 'numpy'` (assume no `numpy` is installed in the default Python>> > site-packages.>>>> Thanks for the steps, I managed to reproduce the problem with this:>>>> 2. Running the following commands:>> 2.1 mkdir test>> 2.2 cd test>> 2.3 echo "export DETACHED=TEST" > .envrc>> 2.4 direnv allow>> 3. In a *shell* buffer run `echo $DETACHED` with>> `detached-shell-send-input` and observe TEST being the output>> 4. Run `detached-rerun-session` and rerun the last session.>> 5. Observe no output>>>> This failure would also occur if you evaluate this lisp expression,>> assuming the test directory is located under /tmp>>>> (let ((default-directory "/tmp/test"))>> (async-shell-command "echo $DETACHED"))>>>> So the default behavior of Emacs seems to be to not pick up the direnv>> environment. Maybe you can experiment with these packages:>>>> - https://github.com/purcell/inheritenv>> - https://github.com/purcell/envrc>>>> and see if these can be used to make the `async-shell-command` example>> above succeed.>>>> /Niklas
> Is this behavior reproduceable for you as well?
Yes, you are right, I can reproduce this.
On Tue, Sep 27, 2022 at 4:39 PM Niklas Eklund <niklas.eklund@posteo.net> wrote:
>> Maximin Liebkne <ispinfx@gmail.com> writes:>> > Hi,> >> > I do use `envrc`> >> > (use-package envrc> > :diminish envrc-mode> > :hook (after-init . envrc-global-mode))>> I thought I was doing that, but turned out I had set it to :disabled and> forgot about it :P>> > and it works smoothly. The following script> >> > (let ((default-directory "/tmp/test"))> > (async-shell-command "echo $DETACHED"))> >> > evaluates to TEST successfully. But `detached-rerun-session` gives me> > an empty result.>> The following works for me as well with `envrc` enabled, but there is a> caveat for me. It doesn't work the first time, only the second time when> the async shell command buffer already exists.>> Killing the `*Async Shell Command*` buffer and running the expression> above fails for me. Evaluating it a second time succeeds.>> Consequently detached-rerun-session fails first time for me but reruning> it again without killing that buffer then it works. Is this behavior> reproduceable for you as well?>> /Niklas>> > On Tue, Sep 27, 2022 at 3:25 PM Niklas Eklund <niklas.eklund@posteo.net> wrote:> >>> >> Maximin Liebkne <ispinfx@gmail.com> writes:> >>> >> > Hi,> >>> >> Hello,> >>> >> > Currently `detached.el` does not seem to work with `direnv`. For> >> > example, rerunning a command run in a direnv fails since it can not> >> > resolve the env successfully.> >>> >> In general detached processes doesn't capture the environment it runs in> >> so it might fail to reproduce the results when it's rerun. However using> >> direnv is something that would be good to support.> >>> >> > Reproduce steps:> >> >> >> > 1. Install direnv and setup bash config: https://direnv.net/docs/hook.html .> >> > 2. Running the following commands:> >> > 2.1 mkdir test> >> > 2.2 cd test> >> > 2.3 echo "layout python" > .envrc> >> > 2.4 direnv allow> >> > 2.5 pip install numpy> >> > 2.6 echo -e 'import numpy as np\nprint(np.random.randn())\n' > test.py> >> > 3. In a *shell* buffer run `python test.py` with `detached-shell-send-input`.> >> > 4. Kill the shell buffer and maybe go to another directory.> >> > 5. Run `detached-rerun-session` and rerun the last session.> >> > 6. Observe some error like `ModuleNotFoundError: No module named> >> > 'numpy'` (assume no `numpy` is installed in the default Python> >> > site-packages.> >>> >> Thanks for the steps, I managed to reproduce the problem with this:> >>> >> 2. Running the following commands:> >> 2.1 mkdir test> >> 2.2 cd test> >> 2.3 echo "export DETACHED=TEST" > .envrc> >> 2.4 direnv allow> >> 3. In a *shell* buffer run `echo $DETACHED` with> >> `detached-shell-send-input` and observe TEST being the output> >> 4. Run `detached-rerun-session` and rerun the last session.> >> 5. Observe no output> >>> >> This failure would also occur if you evaluate this lisp expression,> >> assuming the test directory is located under /tmp> >>> >> (let ((default-directory "/tmp/test"))> >> (async-shell-command "echo $DETACHED"))> >>> >> So the default behavior of Emacs seems to be to not pick up the direnv> >> environment. Maybe you can experiment with these packages:> >>> >> - https://github.com/purcell/inheritenv> >> - https://github.com/purcell/envrc> >>> >> and see if these can be used to make the `async-shell-command` example> >> above succeed.> >>> >> /Niklas
Maximin Liebkne <ispinfx@gmail.com> writes:
>> Is this behavior reproduceable for you as well?>> Yes, you are right, I can reproduce this.
I think I might have some ugly hack that could work. Seems to be working
with detached-shell-command and detached-compile for me. Would be great
if you could try it out. It is available on the branch called direnv.
/Niklas
> On Tue, Sep 27, 2022 at 4:39 PM Niklas Eklund <niklas.eklund@posteo.net> wrote:>>>> Maximin Liebkne <ispinfx@gmail.com> writes:>>>> > Hi,>> >>> > I do use `envrc`>> >>> > (use-package envrc>> > :diminish envrc-mode>> > :hook (after-init . envrc-global-mode))>>>> I thought I was doing that, but turned out I had set it to :disabled and>> forgot about it :P>>>> > and it works smoothly. The following script>> >>> > (let ((default-directory "/tmp/test"))>> > (async-shell-command "echo $DETACHED"))>> >>> > evaluates to TEST successfully. But `detached-rerun-session` gives me>> > an empty result.>>>> The following works for me as well with `envrc` enabled, but there is a>> caveat for me. It doesn't work the first time, only the second time when>> the async shell command buffer already exists.>>>> Killing the `*Async Shell Command*` buffer and running the expression>> above fails for me. Evaluating it a second time succeeds.>>>> Consequently detached-rerun-session fails first time for me but reruning>> it again without killing that buffer then it works. Is this behavior>> reproduceable for you as well?>>>> /Niklas>>>> > On Tue, Sep 27, 2022 at 3:25 PM Niklas Eklund <niklas.eklund@posteo.net> wrote:>> >>>> >> Maximin Liebkne <ispinfx@gmail.com> writes:>> >>>> >> > Hi,>> >>>> >> Hello,>> >>>> >> > Currently `detached.el` does not seem to work with `direnv`. For>> >> > example, rerunning a command run in a direnv fails since it can not>> >> > resolve the env successfully.>> >>>> >> In general detached processes doesn't capture the environment it runs in>> >> so it might fail to reproduce the results when it's rerun. However using>> >> direnv is something that would be good to support.>> >>>> >> > Reproduce steps:>> >> >>> >> > 1. Install direnv and setup bash config: https://direnv.net/docs/hook.html .>> >> > 2. Running the following commands:>> >> > 2.1 mkdir test>> >> > 2.2 cd test>> >> > 2.3 echo "layout python" > .envrc>> >> > 2.4 direnv allow>> >> > 2.5 pip install numpy>> >> > 2.6 echo -e 'import numpy as np\nprint(np.random.randn())\n' > test.py>> >> > 3. In a *shell* buffer run `python test.py` with `detached-shell-send-input`.>> >> > 4. Kill the shell buffer and maybe go to another directory.>> >> > 5. Run `detached-rerun-session` and rerun the last session.>> >> > 6. Observe some error like `ModuleNotFoundError: No module named>> >> > 'numpy'` (assume no `numpy` is installed in the default Python>> >> > site-packages.>> >>>> >> Thanks for the steps, I managed to reproduce the problem with this:>> >>>> >> 2. Running the following commands:>> >> 2.1 mkdir test>> >> 2.2 cd test>> >> 2.3 echo "export DETACHED=TEST" > .envrc>> >> 2.4 direnv allow>> >> 3. In a *shell* buffer run `echo $DETACHED` with>> >> `detached-shell-send-input` and observe TEST being the output>> >> 4. Run `detached-rerun-session` and rerun the last session.>> >> 5. Observe no output>> >>>> >> This failure would also occur if you evaluate this lisp expression,>> >> assuming the test directory is located under /tmp>> >>>> >> (let ((default-directory "/tmp/test"))>> >> (async-shell-command "echo $DETACHED"))>> >>>> >> So the default behavior of Emacs seems to be to not pick up the direnv>> >> environment. Maybe you can experiment with these packages:>> >>>> >> - https://github.com/purcell/inheritenv>> >> - https://github.com/purcell/envrc>> >>>> >> and see if these can be used to make the `async-shell-command` example>> >> above succeed.>> >>>> >> /Niklas
Niklas Eklund <niklas.eklund@posteo.net> writes:
> Maximin Liebkne <ispinfx@gmail.com> writes:>>>> Is this behavior reproduceable for you as well?>>>> Yes, you are right, I can reproduce this.>> I think I might have some ugly hack that could work. Seems to be working> with detached-shell-command and detached-compile for me. Would be great> if you could try it out. It is available on the branch called direnv.
I created a more polished implementation on the branch. Give it a try,
it should work out of the box for envrc now.
/Niklas
>>> On Tue, Sep 27, 2022 at 4:39 PM Niklas Eklund <niklas.eklund@posteo.net> wrote:>>>>>> Maximin Liebkne <ispinfx@gmail.com> writes:>>>>>> > Hi,>>> >>>> > I do use `envrc`>>> >>>> > (use-package envrc>>> > :diminish envrc-mode>>> > :hook (after-init . envrc-global-mode))>>>>>> I thought I was doing that, but turned out I had set it to :disabled and>>> forgot about it :P>>>>>> > and it works smoothly. The following script>>> >>>> > (let ((default-directory "/tmp/test"))>>> > (async-shell-command "echo $DETACHED"))>>> >>>> > evaluates to TEST successfully. But `detached-rerun-session` gives me>>> > an empty result.>>>>>> The following works for me as well with `envrc` enabled, but there is a>>> caveat for me. It doesn't work the first time, only the second time when>>> the async shell command buffer already exists.>>>>>> Killing the `*Async Shell Command*` buffer and running the expression>>> above fails for me. Evaluating it a second time succeeds.>>>>>> Consequently detached-rerun-session fails first time for me but reruning>>> it again without killing that buffer then it works. Is this behavior>>> reproduceable for you as well?>>>>>> /Niklas>>>>>> > On Tue, Sep 27, 2022 at 3:25 PM Niklas Eklund <niklas.eklund@posteo.net> wrote:>>> >>>>> >> Maximin Liebkne <ispinfx@gmail.com> writes:>>> >>>>> >> > Hi,>>> >>>>> >> Hello,>>> >>>>> >> > Currently `detached.el` does not seem to work with `direnv`. For>>> >> > example, rerunning a command run in a direnv fails since it can not>>> >> > resolve the env successfully.>>> >>>>> >> In general detached processes doesn't capture the environment it runs in>>> >> so it might fail to reproduce the results when it's rerun. However using>>> >> direnv is something that would be good to support.>>> >>>>> >> > Reproduce steps:>>> >> >>>> >> > 1. Install direnv and setup bash config: https://direnv.net/docs/hook.html .>>> >> > 2. Running the following commands:>>> >> > 2.1 mkdir test>>> >> > 2.2 cd test>>> >> > 2.3 echo "layout python" > .envrc>>> >> > 2.4 direnv allow>>> >> > 2.5 pip install numpy>>> >> > 2.6 echo -e 'import numpy as np\nprint(np.random.randn())\n' > test.py>>> >> > 3. In a *shell* buffer run `python test.py` with `detached-shell-send-input`.>>> >> > 4. Kill the shell buffer and maybe go to another directory.>>> >> > 5. Run `detached-rerun-session` and rerun the last session.>>> >> > 6. Observe some error like `ModuleNotFoundError: No module named>>> >> > 'numpy'` (assume no `numpy` is installed in the default Python>>> >> > site-packages.>>> >>>>> >> Thanks for the steps, I managed to reproduce the problem with this:>>> >>>>> >> 2. Running the following commands:>>> >> 2.1 mkdir test>>> >> 2.2 cd test>>> >> 2.3 echo "export DETACHED=TEST" > .envrc>>> >> 2.4 direnv allow>>> >> 3. In a *shell* buffer run `echo $DETACHED` with>>> >> `detached-shell-send-input` and observe TEST being the output>>> >> 4. Run `detached-rerun-session` and rerun the last session.>>> >> 5. Observe no output>>> >>>>> >> This failure would also occur if you evaluate this lisp expression,>>> >> assuming the test directory is located under /tmp>>> >>>>> >> (let ((default-directory "/tmp/test"))>>> >> (async-shell-command "echo $DETACHED"))>>> >>>>> >> So the default behavior of Emacs seems to be to not pick up the direnv>>> >> environment. Maybe you can experiment with these packages:>>> >>>>> >> - https://github.com/purcell/inheritenv>>> >> - https://github.com/purcell/envrc>>> >>>>> >> and see if these can be used to make the `async-shell-command` example>>> >> above succeed.>>> >>>>> >> /Niklas
Will check it tomorrow, thanks for your work!
On Thu, Oct 6, 2022 at 23:21 Niklas Eklund <niklas.eklund@posteo.net> wrote:
>> Niklas Eklund <niklas.eklund@posteo.net> writes:>> > Maximin Liebkne <ispinfx@gmail.com> writes:> >> >>> Is this behavior reproduceable for you as well?> >>> >> Yes, you are right, I can reproduce this.> >> > I think I might have some ugly hack that could work. Seems to be working> > with detached-shell-command and detached-compile for me. Would be great> > if you could try it out. It is available on the branch called direnv.>> I created a more polished implementation on the branch. Give it a try,> it should work out of the box for envrc now.>> /Niklas>> >> >> On Tue, Sep 27, 2022 at 4:39 PM Niklas Eklund <niklas.eklund@posteo.net> wrote:> >>>> >>> Maximin Liebkne <ispinfx@gmail.com> writes:> >>>> >>> > Hi,> >>> >> >>> > I do use `envrc`> >>> >> >>> > (use-package envrc> >>> > :diminish envrc-mode> >>> > :hook (after-init . envrc-global-mode))> >>>> >>> I thought I was doing that, but turned out I had set it to :disabled and> >>> forgot about it :P> >>>> >>> > and it works smoothly. The following script> >>> >> >>> > (let ((default-directory "/tmp/test"))> >>> > (async-shell-command "echo $DETACHED"))> >>> >> >>> > evaluates to TEST successfully. But `detached-rerun-session` gives me> >>> > an empty result.> >>>> >>> The following works for me as well with `envrc` enabled, but there is a> >>> caveat for me. It doesn't work the first time, only the second time when> >>> the async shell command buffer already exists.> >>>> >>> Killing the `*Async Shell Command*` buffer and running the expression> >>> above fails for me. Evaluating it a second time succeeds.> >>>> >>> Consequently detached-rerun-session fails first time for me but reruning> >>> it again without killing that buffer then it works. Is this behavior> >>> reproduceable for you as well?> >>>> >>> /Niklas> >>>> >>> > On Tue, Sep 27, 2022 at 3:25 PM Niklas Eklund <niklas.eklund@posteo.net> wrote:> >>> >>> >>> >> Maximin Liebkne <ispinfx@gmail.com> writes:> >>> >>> >>> >> > Hi,> >>> >>> >>> >> Hello,> >>> >>> >>> >> > Currently `detached.el` does not seem to work with `direnv`. For> >>> >> > example, rerunning a command run in a direnv fails since it can not> >>> >> > resolve the env successfully.> >>> >>> >>> >> In general detached processes doesn't capture the environment it runs in> >>> >> so it might fail to reproduce the results when it's rerun. However using> >>> >> direnv is something that would be good to support.> >>> >>> >>> >> > Reproduce steps:> >>> >> >> >>> >> > 1. Install direnv and setup bash config: https://direnv.net/docs/hook.html .> >>> >> > 2. Running the following commands:> >>> >> > 2.1 mkdir test> >>> >> > 2.2 cd test> >>> >> > 2.3 echo "layout python" > .envrc> >>> >> > 2.4 direnv allow> >>> >> > 2.5 pip install numpy> >>> >> > 2.6 echo -e 'import numpy as np\nprint(np.random.randn())\n' > test.py> >>> >> > 3. In a *shell* buffer run `python test.py` with `detached-shell-send-input`.> >>> >> > 4. Kill the shell buffer and maybe go to another directory.> >>> >> > 5. Run `detached-rerun-session` and rerun the last session.> >>> >> > 6. Observe some error like `ModuleNotFoundError: No module named> >>> >> > 'numpy'` (assume no `numpy` is installed in the default Python> >>> >> > site-packages.> >>> >>> >>> >> Thanks for the steps, I managed to reproduce the problem with this:> >>> >>> >>> >> 2. Running the following commands:> >>> >> 2.1 mkdir test> >>> >> 2.2 cd test> >>> >> 2.3 echo "export DETACHED=TEST" > .envrc> >>> >> 2.4 direnv allow> >>> >> 3. In a *shell* buffer run `echo $DETACHED` with> >>> >> `detached-shell-send-input` and observe TEST being the output> >>> >> 4. Run `detached-rerun-session` and rerun the last session.> >>> >> 5. Observe no output> >>> >>> >>> >> This failure would also occur if you evaluate this lisp expression,> >>> >> assuming the test directory is located under /tmp> >>> >>> >>> >> (let ((default-directory "/tmp/test"))> >>> >> (async-shell-command "echo $DETACHED"))> >>> >>> >>> >> So the default behavior of Emacs seems to be to not pick up the direnv> >>> >> environment. Maybe you can experiment with these packages:> >>> >>> >>> >> - https://github.com/purcell/inheritenv> >>> >> - https://github.com/purcell/envrc> >>> >>> >>> >> and see if these can be used to make the `async-shell-command` example> >>> >> above succeed.> >>> >>> >>> >> /Niklas
Hi, thanks for your work.
I've tested it and it seems to work well on my local machine but not
remote direnv. That could be sad since my main usage of `detached` is
running commands on remote servers (possibly with different env), though
I understand that `envrc-mode` does not support `tramp`.
On Fri, Oct 7, 2022 at 10:01 AM Maximin Liebkne <ispinfx@gmail.com> wrote:
>> Will check it tomorrow, thanks for your work!>> On Thu, Oct 6, 2022 at 23:21 Niklas Eklund <niklas.eklund@posteo.net> wrote:> >> > Niklas Eklund <niklas.eklund@posteo.net> writes:> >> > > Maximin Liebkne <ispinfx@gmail.com> writes:> > >> > >>> Is this behavior reproduceable for you as well?> > >>> > >> Yes, you are right, I can reproduce this.> > >> > > I think I might have some ugly hack that could work. Seems to be working> > > with detached-shell-command and detached-compile for me. Would be great> > > if you could try it out. It is available on the branch called direnv.> >> > I created a more polished implementation on the branch. Give it a try,> > it should work out of the box for envrc now.> >> > /Niklas> >> > >> > >> On Tue, Sep 27, 2022 at 4:39 PM Niklas Eklund <niklas.eklund@posteo.net> wrote:> > >>>> > >>> Maximin Liebkne <ispinfx@gmail.com> writes:> > >>>> > >>> > Hi,> > >>> >> > >>> > I do use `envrc`> > >>> >> > >>> > (use-package envrc> > >>> > :diminish envrc-mode> > >>> > :hook (after-init . envrc-global-mode))> > >>>> > >>> I thought I was doing that, but turned out I had set it to :disabled and> > >>> forgot about it :P> > >>>> > >>> > and it works smoothly. The following script> > >>> >> > >>> > (let ((default-directory "/tmp/test"))> > >>> > (async-shell-command "echo $DETACHED"))> > >>> >> > >>> > evaluates to TEST successfully. But `detached-rerun-session` gives me> > >>> > an empty result.> > >>>> > >>> The following works for me as well with `envrc` enabled, but there is a> > >>> caveat for me. It doesn't work the first time, only the second time when> > >>> the async shell command buffer already exists.> > >>>> > >>> Killing the `*Async Shell Command*` buffer and running the expression> > >>> above fails for me. Evaluating it a second time succeeds.> > >>>> > >>> Consequently detached-rerun-session fails first time for me but reruning> > >>> it again without killing that buffer then it works. Is this behavior> > >>> reproduceable for you as well?> > >>>> > >>> /Niklas> > >>>> > >>> > On Tue, Sep 27, 2022 at 3:25 PM Niklas Eklund <niklas.eklund@posteo.net> wrote:> > >>> >>> > >>> >> Maximin Liebkne <ispinfx@gmail.com> writes:> > >>> >>> > >>> >> > Hi,> > >>> >>> > >>> >> Hello,> > >>> >>> > >>> >> > Currently `detached.el` does not seem to work with `direnv`. For> > >>> >> > example, rerunning a command run in a direnv fails since it can not> > >>> >> > resolve the env successfully.> > >>> >>> > >>> >> In general detached processes doesn't capture the environment it runs in> > >>> >> so it might fail to reproduce the results when it's rerun. However using> > >>> >> direnv is something that would be good to support.> > >>> >>> > >>> >> > Reproduce steps:> > >>> >> >> > >>> >> > 1. Install direnv and setup bash config: https://direnv.net/docs/hook.html .> > >>> >> > 2. Running the following commands:> > >>> >> > 2.1 mkdir test> > >>> >> > 2.2 cd test> > >>> >> > 2.3 echo "layout python" > .envrc> > >>> >> > 2.4 direnv allow> > >>> >> > 2.5 pip install numpy> > >>> >> > 2.6 echo -e 'import numpy as np\nprint(np.random.randn())\n' > test.py> > >>> >> > 3. In a *shell* buffer run `python test.py` with `detached-shell-send-input`.> > >>> >> > 4. Kill the shell buffer and maybe go to another directory.> > >>> >> > 5. Run `detached-rerun-session` and rerun the last session.> > >>> >> > 6. Observe some error like `ModuleNotFoundError: No module named> > >>> >> > 'numpy'` (assume no `numpy` is installed in the default Python> > >>> >> > site-packages.> > >>> >>> > >>> >> Thanks for the steps, I managed to reproduce the problem with this:> > >>> >>> > >>> >> 2. Running the following commands:> > >>> >> 2.1 mkdir test> > >>> >> 2.2 cd test> > >>> >> 2.3 echo "export DETACHED=TEST" > .envrc> > >>> >> 2.4 direnv allow> > >>> >> 3. In a *shell* buffer run `echo $DETACHED` with> > >>> >> `detached-shell-send-input` and observe TEST being the output> > >>> >> 4. Run `detached-rerun-session` and rerun the last session.> > >>> >> 5. Observe no output> > >>> >>> > >>> >> This failure would also occur if you evaluate this lisp expression,> > >>> >> assuming the test directory is located under /tmp> > >>> >>> > >>> >> (let ((default-directory "/tmp/test"))> > >>> >> (async-shell-command "echo $DETACHED"))> > >>> >>> > >>> >> So the default behavior of Emacs seems to be to not pick up the direnv> > >>> >> environment. Maybe you can experiment with these packages:> > >>> >>> > >>> >> - https://github.com/purcell/inheritenv> > >>> >> - https://github.com/purcell/envrc> > >>> >>> > >>> >> and see if these can be used to make the `async-shell-command` example> > >>> >> above succeed.> > >>> >>> > >>> >> /Niklas
Maximin Liebkne <ispinfx@gmail.com> writes:
> Hi, thanks for your work.>> I've tested it and it seems to work well on my local machine but not> remote direnv. That could be sad since my main usage of `detached` is> running commands on remote servers (possibly with different env), though> I understand that `envrc-mode` does not support `tramp`.
It seems like https://github.com/astoff/buffer-env doesn't support that
either from what I could see. Looks like it will be difficult to
implement something that works reliably.
My suggestion is that you would need to make sure that the command you
run is in itself reproduceable. For users in general I would recommend
creating a shell script that sets up the environment so that running
that script always yields the same result.
For direnv I tried to create a script (here named direnv_python) that I put in PATH which contain the following:
#!/usr/bin/env bash
direnv exec . python "$@"
It then worked well to run this:
direnv_python test.py
Executing that with detached makes it possible to rerun. Could you try
that approach and see if it works. I am assuming that would work as well
for remote hosts as the local host.
/Niklas
> On Fri, Oct 7, 2022 at 10:01 AM Maximin Liebkne <ispinfx@gmail.com> wrote:>>>> Will check it tomorrow, thanks for your work!>>>> On Thu, Oct 6, 2022 at 23:21 Niklas Eklund <niklas.eklund@posteo.net> wrote:>> >>> > Niklas Eklund <niklas.eklund@posteo.net> writes:>> >>> > > Maximin Liebkne <ispinfx@gmail.com> writes:>> > >>> > >>> Is this behavior reproduceable for you as well?>> > >>>> > >> Yes, you are right, I can reproduce this.>> > >>> > > I think I might have some ugly hack that could work. Seems to be working>> > > with detached-shell-command and detached-compile for me. Would be great>> > > if you could try it out. It is available on the branch called direnv.>> >>> > I created a more polished implementation on the branch. Give it a try,>> > it should work out of the box for envrc now.>> >>> > /Niklas>> >>> > >>> > >> On Tue, Sep 27, 2022 at 4:39 PM Niklas Eklund <niklas.eklund@posteo.net> wrote:>> > >>>>> > >>> Maximin Liebkne <ispinfx@gmail.com> writes:>> > >>>>> > >>> > Hi,>> > >>> >>> > >>> > I do use `envrc`>> > >>> >>> > >>> > (use-package envrc>> > >>> > :diminish envrc-mode>> > >>> > :hook (after-init . envrc-global-mode))>> > >>>>> > >>> I thought I was doing that, but turned out I had set it to :disabled and>> > >>> forgot about it :P>> > >>>>> > >>> > and it works smoothly. The following script>> > >>> >>> > >>> > (let ((default-directory "/tmp/test"))>> > >>> > (async-shell-command "echo $DETACHED"))>> > >>> >>> > >>> > evaluates to TEST successfully. But `detached-rerun-session` gives me>> > >>> > an empty result.>> > >>>>> > >>> The following works for me as well with `envrc` enabled, but there is a>> > >>> caveat for me. It doesn't work the first time, only the second time when>> > >>> the async shell command buffer already exists.>> > >>>>> > >>> Killing the `*Async Shell Command*` buffer and running the expression>> > >>> above fails for me. Evaluating it a second time succeeds.>> > >>>>> > >>> Consequently detached-rerun-session fails first time for me but reruning>> > >>> it again without killing that buffer then it works. Is this behavior>> > >>> reproduceable for you as well?>> > >>>>> > >>> /Niklas>> > >>>>> > >>> > On Tue, Sep 27, 2022 at 3:25 PM Niklas Eklund <niklas.eklund@posteo.net> wrote:>> > >>> >>>> > >>> >> Maximin Liebkne <ispinfx@gmail.com> writes:>> > >>> >>>> > >>> >> > Hi,>> > >>> >>>> > >>> >> Hello,>> > >>> >>>> > >>> >> > Currently `detached.el` does not seem to work with `direnv`. For>> > >>> >> > example, rerunning a command run in a direnv fails since it can not>> > >>> >> > resolve the env successfully.>> > >>> >>>> > >>> >> In general detached processes doesn't capture the environment it runs in>> > >>> >> so it might fail to reproduce the results when it's rerun. However using>> > >>> >> direnv is something that would be good to support.>> > >>> >>>> > >>> >> > Reproduce steps:>> > >>> >> >>> > >>> >> > 1. Install direnv and setup bash config: https://direnv.net/docs/hook.html .>> > >>> >> > 2. Running the following commands:>> > >>> >> > 2.1 mkdir test>> > >>> >> > 2.2 cd test>> > >>> >> > 2.3 echo "layout python" > .envrc>> > >>> >> > 2.4 direnv allow>> > >>> >> > 2.5 pip install numpy>> > >>> >> > 2.6 echo -e 'import numpy as np\nprint(np.random.randn())\n' > test.py>> > >>> >> > 3. In a *shell* buffer run `python test.py` with `detached-shell-send-input`.>> > >>> >> > 4. Kill the shell buffer and maybe go to another directory.>> > >>> >> > 5. Run `detached-rerun-session` and rerun the last session.>> > >>> >> > 6. Observe some error like `ModuleNotFoundError: No module named>> > >>> >> > 'numpy'` (assume no `numpy` is installed in the default Python>> > >>> >> > site-packages.>> > >>> >>>> > >>> >> Thanks for the steps, I managed to reproduce the problem with this:>> > >>> >>>> > >>> >> 2. Running the following commands:>> > >>> >> 2.1 mkdir test>> > >>> >> 2.2 cd test>> > >>> >> 2.3 echo "export DETACHED=TEST" > .envrc>> > >>> >> 2.4 direnv allow>> > >>> >> 3. In a *shell* buffer run `echo $DETACHED` with>> > >>> >> `detached-shell-send-input` and observe TEST being the output>> > >>> >> 4. Run `detached-rerun-session` and rerun the last session.>> > >>> >> 5. Observe no output>> > >>> >>>> > >>> >> This failure would also occur if you evaluate this lisp expression,>> > >>> >> assuming the test directory is located under /tmp>> > >>> >>>> > >>> >> (let ((default-directory "/tmp/test"))>> > >>> >> (async-shell-command "echo $DETACHED"))>> > >>> >>>> > >>> >> So the default behavior of Emacs seems to be to not pick up the direnv>> > >>> >> environment. Maybe you can experiment with these packages:>> > >>> >>>> > >>> >> - https://github.com/purcell/inheritenv>> > >>> >> - https://github.com/purcell/envrc>> > >>> >>>> > >>> >> and see if these can be used to make the `async-shell-command` example>> > >>> >> above succeed.>> > >>> >>>> > >>> >> /Niklas
Hi, the script method works on my local and remote machines. I'm gonna
take this way. Thank you!
On Sat, Oct 8, 2022 at 7:54 PM Niklas Eklund <niklas.eklund@posteo.net> wrote:
>> Maximin Liebkne <ispinfx@gmail.com> writes:>> > Hi, thanks for your work.> >> > I've tested it and it seems to work well on my local machine but not> > remote direnv. That could be sad since my main usage of `detached` is> > running commands on remote servers (possibly with different env), though> > I understand that `envrc-mode` does not support `tramp`.>> It seems like https://github.com/astoff/buffer-env doesn't support that> either from what I could see. Looks like it will be difficult to> implement something that works reliably.>> My suggestion is that you would need to make sure that the command you> run is in itself reproduceable. For users in general I would recommend> creating a shell script that sets up the environment so that running> that script always yields the same result.>> For direnv I tried to create a script (here named direnv_python) that I put in PATH which contain the following:>> #!/usr/bin/env bash> direnv exec . python "$@">> It then worked well to run this:>> direnv_python test.py>> Executing that with detached makes it possible to rerun. Could you try> that approach and see if it works. I am assuming that would work as well> for remote hosts as the local host.>> /Niklas>> > On Fri, Oct 7, 2022 at 10:01 AM Maximin Liebkne <ispinfx@gmail.com> wrote:> >>> >> Will check it tomorrow, thanks for your work!> >>> >> On Thu, Oct 6, 2022 at 23:21 Niklas Eklund <niklas.eklund@posteo.net> wrote:> >> >> >> > Niklas Eklund <niklas.eklund@posteo.net> writes:> >> >> >> > > Maximin Liebkne <ispinfx@gmail.com> writes:> >> > >> >> > >>> Is this behavior reproduceable for you as well?> >> > >>> >> > >> Yes, you are right, I can reproduce this.> >> > >> >> > > I think I might have some ugly hack that could work. Seems to be working> >> > > with detached-shell-command and detached-compile for me. Would be great> >> > > if you could try it out. It is available on the branch called direnv.> >> >> >> > I created a more polished implementation on the branch. Give it a try,> >> > it should work out of the box for envrc now.> >> >> >> > /Niklas> >> >> >> > >> >> > >> On Tue, Sep 27, 2022 at 4:39 PM Niklas Eklund <niklas.eklund@posteo.net> wrote:> >> > >>>> >> > >>> Maximin Liebkne <ispinfx@gmail.com> writes:> >> > >>>> >> > >>> > Hi,> >> > >>> >> >> > >>> > I do use `envrc`> >> > >>> >> >> > >>> > (use-package envrc> >> > >>> > :diminish envrc-mode> >> > >>> > :hook (after-init . envrc-global-mode))> >> > >>>> >> > >>> I thought I was doing that, but turned out I had set it to :disabled and> >> > >>> forgot about it :P> >> > >>>> >> > >>> > and it works smoothly. The following script> >> > >>> >> >> > >>> > (let ((default-directory "/tmp/test"))> >> > >>> > (async-shell-command "echo $DETACHED"))> >> > >>> >> >> > >>> > evaluates to TEST successfully. But `detached-rerun-session` gives me> >> > >>> > an empty result.> >> > >>>> >> > >>> The following works for me as well with `envrc` enabled, but there is a> >> > >>> caveat for me. It doesn't work the first time, only the second time when> >> > >>> the async shell command buffer already exists.> >> > >>>> >> > >>> Killing the `*Async Shell Command*` buffer and running the expression> >> > >>> above fails for me. Evaluating it a second time succeeds.> >> > >>>> >> > >>> Consequently detached-rerun-session fails first time for me but reruning> >> > >>> it again without killing that buffer then it works. Is this behavior> >> > >>> reproduceable for you as well?> >> > >>>> >> > >>> /Niklas> >> > >>>> >> > >>> > On Tue, Sep 27, 2022 at 3:25 PM Niklas Eklund <niklas.eklund@posteo.net> wrote:> >> > >>> >>> >> > >>> >> Maximin Liebkne <ispinfx@gmail.com> writes:> >> > >>> >>> >> > >>> >> > Hi,> >> > >>> >>> >> > >>> >> Hello,> >> > >>> >>> >> > >>> >> > Currently `detached.el` does not seem to work with `direnv`. For> >> > >>> >> > example, rerunning a command run in a direnv fails since it can not> >> > >>> >> > resolve the env successfully.> >> > >>> >>> >> > >>> >> In general detached processes doesn't capture the environment it runs in> >> > >>> >> so it might fail to reproduce the results when it's rerun. However using> >> > >>> >> direnv is something that would be good to support.> >> > >>> >>> >> > >>> >> > Reproduce steps:> >> > >>> >> >> >> > >>> >> > 1. Install direnv and setup bash config: https://direnv.net/docs/hook.html .> >> > >>> >> > 2. Running the following commands:> >> > >>> >> > 2.1 mkdir test> >> > >>> >> > 2.2 cd test> >> > >>> >> > 2.3 echo "layout python" > .envrc> >> > >>> >> > 2.4 direnv allow> >> > >>> >> > 2.5 pip install numpy> >> > >>> >> > 2.6 echo -e 'import numpy as np\nprint(np.random.randn())\n' > test.py> >> > >>> >> > 3. In a *shell* buffer run `python test.py` with `detached-shell-send-input`.> >> > >>> >> > 4. Kill the shell buffer and maybe go to another directory.> >> > >>> >> > 5. Run `detached-rerun-session` and rerun the last session.> >> > >>> >> > 6. Observe some error like `ModuleNotFoundError: No module named> >> > >>> >> > 'numpy'` (assume no `numpy` is installed in the default Python> >> > >>> >> > site-packages.> >> > >>> >>> >> > >>> >> Thanks for the steps, I managed to reproduce the problem with this:> >> > >>> >>> >> > >>> >> 2. Running the following commands:> >> > >>> >> 2.1 mkdir test> >> > >>> >> 2.2 cd test> >> > >>> >> 2.3 echo "export DETACHED=TEST" > .envrc> >> > >>> >> 2.4 direnv allow> >> > >>> >> 3. In a *shell* buffer run `echo $DETACHED` with> >> > >>> >> `detached-shell-send-input` and observe TEST being the output> >> > >>> >> 4. Run `detached-rerun-session` and rerun the last session.> >> > >>> >> 5. Observe no output> >> > >>> >>> >> > >>> >> This failure would also occur if you evaluate this lisp expression,> >> > >>> >> assuming the test directory is located under /tmp> >> > >>> >>> >> > >>> >> (let ((default-directory "/tmp/test"))> >> > >>> >> (async-shell-command "echo $DETACHED"))> >> > >>> >>> >> > >>> >> So the default behavior of Emacs seems to be to not pick up the direnv> >> > >>> >> environment. Maybe you can experiment with these packages:> >> > >>> >>> >> > >>> >> - https://github.com/purcell/inheritenv> >> > >>> >> - https://github.com/purcell/envrc> >> > >>> >>> >> > >>> >> and see if these can be used to make the `async-shell-command` example> >> > >>> >> above succeed.> >> > >>> >>> >> > >>> >> /Niklas