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

redirection: unable to open file #5420

Closed
Kossak-esky opened this issue May 16, 2024 · 11 comments · Fixed by #5423
Closed

redirection: unable to open file #5420

Kossak-esky opened this issue May 16, 2024 · 11 comments · Fixed by #5423

Comments

@Kossak-esky
Copy link

Kossak-esky commented May 16, 2024

Current Behavior

This snippet:

xonsh --no-rc
f = p'/tmp/file.tmp'
echo 'abc' > @(f)

returns error: xonsh: ['/tmp/file.tmp']: unable to open file

Expected Behavior

The snippet should redirect string 'abc' to file /tmp/file.tmp

xonfig

+------------------+-----------------+
| xonsh            | 0.16.0          |
| Python           | 3.9.16          |
| PLY              | 3.11            |
| have readline    | True            |
| prompt toolkit   | 3.0.36          |
| shell type       | prompt_toolkit  |
| history backend  | json            |
| pygments         | 2.14.0          |
| on posix         | True            |
| on linux         | True            |
| distro           | manjaro         |
| on wsl           | False           |
| 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 |
| xontrib          | []              |
| RC file          | []              |
+------------------+-----------------+

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

@anki-code
Copy link
Member

anki-code commented May 16, 2024

Hey! Nice catch! Thanks!

Workaround:

xonsh --no-rc
$f = p'/tmp/file.tmp'
echo 'abc' > $f

@Kossak-esky
Copy link
Author

Thank you very much for workaround and for this awesome shell!

@anki-code
Copy link
Member

anki-code commented May 16, 2024

@Kossak-esky I made the fix. Please test:

xpip install -U --force-reinstall git+https://github.com/xonsh/xonsh@fix_redirect_to_subst
# restart xonsh
f = p'/tmp/file.tmp'
echo 'abc' > @(f)
cat @(f)
# abc

@Kossak-esky
Copy link
Author

It works, except cat < @(f) but I don't need this one (just tested it out of curiosity) and I understand it's not supported yet anyway.
Thank you!

@anki-code
Copy link
Member

anki-code commented May 16, 2024

This works as well:

f = p'/tmp/file.tmp'
echo 'abc' > @(f)
cat < @(f)
# abc

@Kossak-esky
Copy link
Author

Kossak-esky commented May 16, 2024

ok, it turns out it doesn't work when I have coreutils xontrib enabled.

This works:

kossak@lman3 ~ @ xonsh@fix2 --no-rc
kossak@lman3 ~ @ f = p'/tmp/file.tmp'
echo 'abc' > @(f)
cat < @(f)

abc

But when I create .xonshrc with body:

from xonsh.xontribs import xontribs_load

xontribs = [
    'coreutils',
]

xontribs_load(xontribs)

I get error:

kossak@lman3 ~ @ xonsh@fix2
kossak@lman3 ~ @ f = p'/tmp/file.tmp'
echo 'abc' > @(f)
cat < @(f)

abc
xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
OSError: [Errno 9] Bad file descriptor

@Kossak-esky
Copy link
Author

With traceback:

kossak@lman3 ~ @ f = p'/tmp/file.tmp'
echo 'abc' > @(f)
cat < @(f)

abc
xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "/home/kossak/.local/pipx/venvs/xonsh@fix2/lib/python3.9/site-packages/xonsh/built_ins.py", line 211, in subproc_captured_hiddenobject
    return xonsh.procs.specs.run_subproc(cmds, captured="hiddenobject", envs=envs)
  File "/home/kossak/.local/pipx/venvs/xonsh@fix2/lib/python3.9/site-packages/xonsh/procs/specs.py", line 957, in run_subproc
    return _run_specs(specs, cmds)
  File "/home/kossak/.local/pipx/venvs/xonsh@fix2/lib/python3.9/site-packages/xonsh/procs/specs.py", line 999, in _run_specs
    cp.end()
  File "/home/kossak/.local/pipx/venvs/xonsh@fix2/lib/python3.9/site-packages/xonsh/procs/pipelines.py", line 465, in end
    self._end(tee_output=tee_output)
  File "/home/kossak/.local/pipx/venvs/xonsh@fix2/lib/python3.9/site-packages/xonsh/procs/pipelines.py", line 478, in _end
    self._set_input()
  File "/home/kossak/.local/pipx/venvs/xonsh@fix2/lib/python3.9/site-packages/xonsh/procs/pipelines.py", line 576, in _set_input
    stdin.seek(0)
OSError: [Errno 9] Bad file descriptor

@anki-code
Copy link
Member

anki-code commented May 16, 2024

It's fixed in the PR, just update - #5420 (comment)

@Kossak-esky
Copy link
Author

I did update it, but somehow it still doesn't work when I have coreutils loaded. Without coreutils it works fine.

[kossak@lman3 ~]$ xonsh@fix2
kossak@lman3 ~ @ xpip install -U --force-reinstall git+https://github.com/xonsh/xonsh@fix_redirect_to_subst
Collecting git+https://github.com/xonsh/xonsh@fix_redirect_to_subst
  Cloning https://github.com/xonsh/xonsh (to revision fix_redirect_to_subst) to /tmp/pip-req-build-b5arx8xv
  Running command git clone --filter=blob:none --quiet https://github.com/xonsh/xonsh /tmp/pip-req-build-b5arx8xv
  Running command git checkout -b fix_redirect_to_subst --track origin/fix_redirect_to_subst
  Switched to a new branch 'fix_redirect_to_subst'
  branch 'fix_redirect_to_subst' set up to track 'origin/fix_redirect_to_subst'.
  Resolved https://github.com/xonsh/xonsh to commit e4a6f4f75720203a5df71484f12fcbb997d0b052
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: xonsh
  Building wheel for xonsh (pyproject.toml) ... done
  Created wheel for xonsh: filename=xonsh-0.16.0-py39-none-any.whl size=618295 sha256=2c458fa6bb7bb57eca07b399be8fc287b8dd78d6b2505778f18041531e6c338c
  Stored in directory: /tmp/pip-ephem-wheel-cache-6lmd98_2/wheels/a2/ae/ce/309e0bc4c48c4f47153e136a2f071614cb1db1ec4563533df3
Successfully built xonsh
Installing collected packages: xonsh
  Attempting uninstall: xonsh
    Found existing installation: xonsh 0.16.0
    Uninstalling xonsh-0.16.0:
      Successfully uninstalled xonsh-0.16.0
Successfully installed xonsh-0.16.0
kossak@lman3 ~ @ xonsh@fix2
kossak@lman3 ~ @ xonfig
+-----------------------------+------------------------------------------------+
| xonsh                       | 0.16.0.dev114                                  |
| Git SHA                     | e4a6f4f7                                       |
| Commit Date                 | May 16 15:43:13 2024                           |
| Python                      | 3.9.16                                         |
| PLY                         | 3.11                                           |
| have readline               | True                                           |
| prompt toolkit              | 3.0.43                                         |
| shell type                  | prompt_toolkit                                 |
| history backend             | json                                           |
| pygments                    | 2.18.0                                         |
| on posix                    | True                                           |
| on linux                    | True                                           |
| distro                      | unknown                                        |
| on wsl                      | False                                          |
| 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                                |
| xontrib 1                   | argcomplete                                    |
| xontrib 2                   | coreutils                                      |
| xontrib 3                   | navi                                           |
| xontrib 4                   | abbrevs                                        |
| xontrib 5                   | fzf-widgets                                    |
| xontrib 6                   | vox                                            |
| xontrib 7                   | voxapi                                         |
| RC file 1                   | /home/kossak/.xonshrc                          |
| RC file 2                   | /home/kossak/.config/xonsh/rc.d/asdf.xsh       |
| RC file 3                   | /home/kossak/.config/xonsh/rc.d/cdf.xsh        |
| RC file 4                   | /home/kossak/.config/xonsh/rc.d/gcp.xsh        |
| RC file 5                   | /home/kossak/.config/xonsh/rc.d/kubernetes.xsh |
| RC file 6                   | /home/kossak/.config/xonsh/rc.d/local_all.xsh  |
| RC file 7                   | /home/kossak/.config/xonsh/rc.d/local_home.xsh |
| RC file 8                   | /home/kossak/.config/xonsh/rc.d/local_work.xsh |
| RC file 9                   | /home/kossak/.config/xonsh/rc.d/ssh.xsh        |
| UPDATE_OS_ENVIRON           | False                                          |
| XONSH_CAPTURE_ALWAYS        | False                                          |
| XONSH_SUBPROC_OUTPUT_FORMAT | stream_lines                                   |
| THREAD_SUBPROCS             | True                                           |
| XONSH_CACHE_SCRIPTS         | True                                           |
+-----------------------------+------------------------------------------------+
kossak@lman3 ~ @ f = p'/tmp/file.tmp'
echo 'abc' > @(f)
cat < @(f)
 
abc
xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
OSError: [Errno 9] Bad file descriptor
kossak@lman3 ~ @ xonsh@fix2 --no-rc
kossak@lman3 ~ @ f = p'/tmp/file.tmp'
echo 'abc' > @(f)
cat < @(f)
 
abc
kossak@lman3 ~ @

@Kossak-esky
Copy link
Author

I tried clean installation, that shows that loading coreutils break things:

[kossak@lman3 ~]$ pipx install --python /home/kossak/.asdf/installs/python/3.9.16/bin/python --suffix=@fix3 'git+https://github.com/xonsh/xonsh@fix_redirect_to_subst'
  installed package xonsh 0.16.0 (xonsh@fix3), installed using Python 3.9.16
  These apps are now globally available
    - xonsh-cat@fix3
    - xonsh-uname@fix3
    - xonsh-uptime@fix3
    - xonsh@fix3
done! ✨ 🌟 ✨
[kossak@lman3 ~]$ xonsh@fix3 --no-rc
kossak@lman3 ~ @ f = p'/tmp/file.tmp'
echo 'abc' > @(f)
cat < @(f)
abc
kossak@lman3 ~ @ xontrib list
coreutils  not-loaded
kossak@lman3 ~ @ xontrib load coreutils
kossak@lman3 ~ @ xontrib list
coreutils  loaded      manual
kossak@lman3 ~ @ f = p'/tmp/file.tmp'
echo 'abc' > @(f)
cat < @(f)
abc
xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
OSError: [Errno 9] Bad file descriptor
kossak@lman3 ~ @ 

@anki-code
Copy link
Member

anki-code commented May 17, 2024

"Bad file descriptor" looks like #4792. Thank you for reporting. Feel free to create separate issue about coreutils if it's not 4792.

anki-code added a commit that referenced this issue May 26, 2024
### Motivation

Closes #5420

### Before

```xsh
xonsh --no-rc
f = p'/tmp/file.tmp'
echo 'abc' > @(f)
# returns error: xonsh: ['/tmp/file.tmp']: unable to open file
```

### After

```xsh
xonsh --no-rc
f = p'/tmp/file.tmp'
echo 'abc' > @(f)
cat @(f)
# abc
```

## For community
⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍
comment**

---------

Co-authored-by: a <1@1.1>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants