Commit graph

10853 commits

Author SHA1 Message Date
pre-commit-ci[bot]
0ed58e60c9
[pre-commit.ci] pre-commit autoupdate (#5486)
<!--pre-commit.ci start-->
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.4.7 →
v0.4.8](https://github.com/astral-sh/ruff-pre-commit/compare/v0.4.7...v0.4.8)
<!--pre-commit.ci end-->

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-06-10 21:33:37 +02:00
Jason R. Coombs
4aec6d1d12
Perform proper case-insensitive matching in command_cache on Windows (#5477)
Closes #5476
Closes #5469
2024-06-10 12:29:13 -04:00
amacfie-tc
8e229a421f
Add Starship to xonsh-compatible projects (#5484)
## For community
⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍
comment**

---------

Co-authored-by: Andy Kipp <anki-code@users.noreply.github.com>
2024-06-10 18:25:31 +02:00
Andy Kipp
63da8e3492
Tutorial: Callable alias and capturing (#5472)
<!---

Thanks for opening a PR on xonsh!

Please do this:

1. Include a news file with your PR
(https://xon.sh/devguide.html#changelog).
2. Add the documentation for your feature into `/docs`.
3. Add the example of usage or before-after behavior.
4. Mention the issue that this PR is addressing e.g. `#1234`.

-->

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

---------

Co-authored-by: a <1@1.1>
2024-06-10 09:42:00 -04:00
Andy Kipp
81df360e9d
spec: added output_format (#5481)
This is continuation for introduced before
`$XONSH_SUBPROC_OUTPUT_FORMAT` (#5377) so news file is not needed.

### Motivation

Having `output_format` in spec and in pipeline allows to switch output
format in `SpecModifierAlias` and during non-blocking work e.g.
```xsh
p=!(echo '1\n2\n3')
p.output_format = 'list_lines'
p.out
# ['1','2','3']
```
```xsh
from xonsh.procs.specs import SpecModifierAlias
class SpecModifierOutputLinesAlias(SpecModifierAlias):
    def on_modifer_added(self, spec):
        spec.output_format = 'list_lines'
aliases['xlines'] = SpecModifierOutputLinesAlias()

$(xlines echo '1\n2\n3')
# ['1','2','3']
```

## 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>
2024-06-10 09:38:53 -04:00
a
9e86938c4d update 2024-06-07 17:03:49 +02:00
pre-commit-ci[bot]
5afb83d67e
[pre-commit.ci] pre-commit autoupdate (#5479)
<!--pre-commit.ci start-->
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.4.5 →
v0.4.7](https://github.com/astral-sh/ruff-pre-commit/compare/v0.4.5...v0.4.7)
<!--pre-commit.ci end-->

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-06-03 20:03:09 +02:00
Andy Kipp
c89a7267be
list_lines: list for single line output (#5478)
### Motivation

This is fix for introduced before
`$XONSH_SUBPROC_OUTPUT_FORMAT='list_lines'` so news file is not needed.

We should return the list for single line output to avoid unintended
reading the string.

### Before
```xsh
$XONSH_SUBPROC_OUTPUT_FORMAT='list_lines'
mkdir -p /tmp/list_lines
cd /tmp/list_lines
touch 123

du $(ls)
# 0	123

for f in $(ls):
    print(f)
# 1
# 2
# 3

touch 321

for f in $(ls):
    print(f)
# 123
# 321
```

### After

```xsh
$XONSH_SUBPROC_OUTPUT_FORMAT='list_lines'
mkdir -p /tmp/list_lines
cd /tmp/list_lines
touch 123

du $(ls)
# 0	123

for f in $(ls):
    print(f)
# 123

touch 321

for f in $(ls):
    print(f)
# 123
# 321
```


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

Co-authored-by: a <1@1.1>
2024-06-02 16:33:34 +02:00
Andy Kipp
850bd8f34b
Revert "Revert #5423" (#5475)
Reverts xonsh/xonsh#5468

Closes #5466

Related #5423

---------

Co-authored-by: a <1@1.1>
2024-06-02 14:53:00 +02:00
Andy Kipp
6245e460a6
Tutorial: micro about exec alias args (#5474)
Replaced too emotional warning.

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

Co-authored-by: a <1@1.1>
2024-06-01 22:35:25 +02:00
Andy Kipp
c9046ab3f6
Revert #5423 (#5468)
I'm going to revert #5423 because it was regress -
https://github.com/xonsh/xonsh/issues/5466 - and we need to fix parser
instead of resolver.

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

---------

Co-authored-by: a <1@1.1>
2024-05-31 22:59:59 +02:00
Andy Kipp
b0b1fe0ac1
XONSH_TRACE_SUBPROC docs (#5467)
## For community
⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍
comment**

Co-authored-by: a <1@1.1>
2024-05-31 17:37:01 +02:00
Andy Kipp
2908f4da17
SpecModifierAlias: micro move (#5464)
It's needed to put spec modifier to the end of resolving.

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

Co-authored-by: a <1@1.1>
2024-05-31 17:36:02 +02:00
Andy Kipp
aaf3c99a3b
Added `$XONSH_TRACE_SUBPROC=3` (#5459)
Show std if `$XONSH_TRACE_SUBPROC=3`.

### Motivation

* It's very helpful if you want to understand how subproc is working. 
* It's helpful to trace `SpecModifierAlias`.
* It's helpful to trace cases like #2618

## 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>
2024-05-31 12:50:25 +02:00
jyn
a953c29443
allow test_raise_subproc_error_with_show_traceback to be run locally (#5461)
previously, this succeeded in CI, but always failed locally with the
following error:
```xsh
_____________________________________________________________________ test_raise_subproc_error_with_show_traceback[True] _____________________________________________________________________

monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x76f6ba8882e0>, interactive = True

    @skip_if_on_windows
    @pytest.mark.parametrize("interactive", [True, False])
    def test_raise_subproc_error_with_show_traceback(monkeypatch, interactive):
        out, err, ret = run_xonsh(
            "$COLOR_RESULTS=False\n$RAISE_SUBPROC_ERROR=False\n$XONSH_SHOW_TRACEBACK=False\nls nofile",
            interactive=interactive,
            single_command=True,
        )
        assert ret != 0
>       assert re.match("ls.*No such file or directory\n", out)
E       assert None
E        +  where None = <function match at 0x76f6bcd0cd30>('ls.*No such file or directory\n', "\x1b]0;ls | jyn@pop-os: ~/src/xonsh | xonsh\x07ls: cannot access 'nofile': No such file or directory\n")
E        +    where <function match at 0x76f6bcd0cd30> = re.match

tests/test_integrations.py:1190: AssertionError
```

the problem was that the following string was prepended before the error
message:
```
\x1b]0;ls | jyn@pop-os: ~/src/xonsh | xonsh\x07l
```

that in turn came from
[`BaseShell.settitle`](66c0490d37/xonsh/base_shell.py (L570)),
which always prepends at least the escape codes even when TITLE is set
to an empty string.

avoid this issue by mimicking a dumb terminal in tests, in which case
`settitle` doesn't add any title at all.

see
https://xonsh.zulipchat.com/#narrow/stream/435069-xonsh-dev/topic/Running.20tests.20locally
for more context.
<!---

Thanks for opening a PR on xonsh!

Please do this:

1. Include a news file with your PR
(https://xon.sh/devguide.html#changelog).
2. Add the documentation for your feature into `/docs`.
3. Add the example of usage or before-after behavior.
4. Mention the issue that this PR is addressing e.g. `#1234`.

-->

## For community
⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍
comment**
2024-05-30 17:02:53 +02:00
jyn
fccdd021c4
note that xonsh requires pip 24 for an editable install and development (#5460)
with pip 22, i was getting extremely strange errors like this one:
```
$ pip install '.[dev]'
Processing /home/jyn/src/xonsh
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
WARNING: unknown 0.0.0 does not provide the extra 'dev'
Building wheels for collected packages: UNKNOWN
  Building wheel for UNKNOWN (pyproject.toml) ... done

Successfully installed UNKNOWN-0.0.0
$ pytest
tests/test_lib/test_subprocess.xsh:10: in <module>
    from xonsh.pytest.tools import ON_WINDOWS
E   ModuleNotFoundError: No module named 'xonsh.pytest'
```

see
https://xonsh.zulipchat.com/#narrow/stream/435069-xonsh-dev/topic/install.20xonsh.20for.20development.20without.20sudo.20rights
for more context.

<!---

Thanks for opening a PR on xonsh!

Please do this:

1. Include a news file with your PR
(https://xon.sh/devguide.html#changelog).
2. Add the documentation for your feature into `/docs`.
3. Add the example of usage or before-after behavior.
4. Mention the issue that this PR is addressing e.g. `#1234`.

-->

## For community
⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍
comment**
2024-05-30 16:03:55 +02:00
Andy Kipp
1feab91935
prompt: yellow env_name (#5457)
### Motivation

When interact with default prompt I noticed that`env_name` has no color
and when you type command or see the output it mix with `env_name`
visually. Prompt is not highlighted when `env_name` has default color.

### Before

Output and env_name are visually mixed:

<img width="900" alt="image"
src="https://github.com/xonsh/xonsh/assets/1708680/c843388e-6e72-4fba-ab0f-6cd3fb023cd2">


### After

Output and env_name are visually distinct:

<img width="918" alt="image"
src="https://github.com/xonsh/xonsh/assets/1708680/09f45cd8-63d1-479a-bfab-c8063cf03aeb">



## 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>
2024-05-28 22:25:21 -04:00
Andy Kipp
1f960b2a8d
aliases.py: micro fix 2 (#5456)
## For community
⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍
comment**

Co-authored-by: a <1@1.1>
2024-05-28 22:47:08 +02:00
Andy Kipp
bc8a243f2b
aliases.py: micro fix (#5454)
It's after all merged features.

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

Co-authored-by: a <1@1.1>
2024-05-28 19:16:24 +02:00
Andy Kipp
730fe45627
Added SpecModifierAlias and xthread, xunthread aliases (#5443)
### Motivation

* We have no recommended way to force subprocess command be
(un)threadable
  * #4214
  * #2119
  * #5003
* It's interesting opportunity to have a way to modify specs and CP
using `SpecModifierAlias`.

### Before

```xsh
!(ssh host -T "echo 1")
# output=''  # EXPECTED: 1

__xonsh__.commands_cache.threadable_predictors['ssh'] = lambda *a, **kw: True
!(ssh host -T "echo 1")
```


### After

```xsh
xthread
# Mark command as threadable.

!(xthread ssh host -T "echo 1")
# output='1'
```

Closes:
* Closes #4214
* Closes #2119
* Partially closes #5003

Implementation of `SpecModifierAlias` will help in:
* #2618

JFYI #5413 

## 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>
Co-authored-by: Gil Forsyth <gforsyth@users.noreply.github.com>
2024-05-28 11:03:45 -04:00
Andy Kipp
499bbf8161
Tutorial: add info about non-blocking !() (#5449)
Closes #3394

### Motivation

After reading [the history of threading and
operators](https://github.com/xonsh/xonsh/issues/5444) I realized that
this was intended, to make the `!()` operator non-blocking. So let's
write about this in tutorial.

### Next steps

In the future we need to solve these points:
* Confusion around `.output` and `.out`.
* Show good cases where non-blocking is doing perfect work to people. Or
remove the non-blocking functionality [to remove
threading](https://github.com/xonsh/xonsh/discussions/4710).

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

---------

Co-authored-by: a <1@1.1>
Co-authored-by: Gil Forsyth <gforsyth@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-05-28 10:51:22 -04:00
Andy Kipp
b55e6a4e3d
Tutorial: add note about rtn (#5447)
subj

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

---------

Co-authored-by: a <1@1.1>
2024-05-28 09:24:18 -04:00
Andy Kipp
0f4839940f
Tutorial: microfix (#5451)
<!---

Thanks for opening a PR on xonsh!

Please do this:

1. Include a news file with your PR
(https://xon.sh/devguide.html#changelog).
2. Add the documentation for your feature into `/docs`.
3. Add the example of usage or before-after behavior.
4. Mention the issue that this PR is addressing e.g. `#1234`.

-->

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

Co-authored-by: a <1@1.1>
2024-05-28 14:08:47 +02:00
pre-commit-ci[bot]
3df3d9a03f
[pre-commit.ci] pre-commit autoupdate (#5448)
<!--pre-commit.ci start-->
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.4.4 →
v0.4.5](https://github.com/astral-sh/ruff-pre-commit/compare/v0.4.4...v0.4.5)
<!--pre-commit.ci end-->

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-05-27 20:37:55 +02:00
Andy Kipp
1f5a7a816b
Mitigate exception on start up if `dircolors` binary is broken (#5439)
### Motivation

If `dircolors` utility is wrong by any reason you can't start xonsh
shell. This should not be stopper.

### Before

```xsh
cd /tmp
echo '#!/bin/qwe' > dircolors && chmod +x dircolors
echo '$PATH.append("/tmp")' > rc
xonsh --no-env --rc /tmp/rc
# OSError: [Errno 8] Exec format error: 'dircolors'
# Xonsh encountered an issue during launch
```

### After

It's working.

## 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>
2024-05-27 20:37:30 +02:00
Andy Kipp
120bcb3559
Revert partial_proxy (#5445)
In #5366 we removed partial_proxy. But @doronz88 [found the
case](https://xonsh.zulipchat.com/#narrow/stream/435525-xonsh-xontrib/topic/.E2.9C.94.20xontrib-z.20and.20maybe.20other.20break.20in.20master)
where this functionality is good and needed. In xontrib-z there is a
[handler](a40abb4d8b/xontrib/z.py (L225-L227))
that requires partial_proxy. So I bring partial_proxy back because it
looks useful.

## 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>
2024-05-27 18:00:15 +02:00
Andy Kipp
2d966fb1b5
Refreshing procs/specs.py (#5424)
### Motivation

This PR just clean the code in `procs/specs.py` without changes the
logic: group the code into functions. This is needed to the next feature
PR #5443.

## 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>
2024-05-26 10:59:36 +02:00
Andy Kipp
14342b2ea3
Fixed redirect with python substitution (#5423)
### 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>
2024-05-26 10:57:35 +02:00
Andy Kipp
1613914d50
Revert jobs.obj rename (#5442)
### Motivation

Closes #5441

In the nutshell [Starship uses
"obj"](86c1312a05/src/init/starship.xsh (L4-L11))
so let's revert [the
renaming](0f25a5a348 (diff-893f3d2e484910a3d1f57b499bdc81bf828ad764af9b7de0a8abb3d4e648d2c7L958))
and will implement backwards compatibility when we switch jobs to
singleton object some day.

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

Co-authored-by: a <1@1.1>
2024-05-25 07:34:26 +02:00
Andy Kipp
f582a33d61
Added support of NixOS core tools in `predict_threadable` (#5440)
### Motivation

Closes #5003

### The case

Core utils in Nix are symlinks to one binary file that contains all
utils:

```xsh
docker run --rm -it nixos/nix bash

which echo
# /nix/store/k6h0vjh342kqlkq69sxjj8i5y50l6jfr-coreutils-9.3/bin/echo

ls -la /nix/store/k6h0vjh342kqlkq69sxjj8i5y50l6jfr-coreutils-9.3/bin/
# b2sum -> coreutils
# base32 -> coreutils
# ...
# All tools are symlinks to one binary file - `coreutils`.
```

When
[`default_predictor_readbin`](61bda708c9/xonsh/commands_cache.py (L392))
read `coreutils` it catches `(b'isatty', b'tcgetattr', b'tcsetattr')`
and return `threadable=False` forever.

The list of Nix coreutils tools are exactly the same as in [brew
coreutils](https://formulae.brew.sh/formula/coreutils). So I can check
the real predicts on distinct binaries and see that only 2 tools among
106 are unthreadable and they already covered by
`default_threadable_predictors` (If it's wrong please add unthreadable
tools to the
[default_threadable_predictors](61bda708c9/xonsh/commands_cache.py (L518))):

```xsh
brew install coreutils

ls /opt/homebrew/opt/coreutils/libexec/gnubin/ | wc -l
# 106

for t in p`/opt/homebrew/opt/coreutils/libexec/gnubin/.*`:
    if not (th := __xonsh__.commands_cache.predict_threadable([t.name])):
        print($(which @(t.name)), th)
# /opt/homebrew/opt/coreutils/libexec/gnubin/cat False
# /opt/homebrew/opt/coreutils/libexec/gnubin/yes False

defaults = __import__('xonsh').commands_cache.default_threadable_predictors().keys()
defaults['cat']
# <function xonsh.commands_cache.predict_false>
defaults['yes']
# <function xonsh.commands_cache.predict_false>
```

So the rest of we need is to check the symlink and apply default
prediction if the tools is the symlink to coreutils. This implements
this PR. Test included.

## 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>
2024-05-24 16:51:25 -04:00
Andy Kipp
61bda708c9
Unpin prompt-toolkit version (#5438)
Merge this after https://github.com/xonsh/xonsh/pull/5437

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

---------

Co-authored-by: a <1@1.1>
2024-05-23 14:08:54 -04:00
Andy Kipp
1847f8a379
Fixed I/O operation on closed file and Bad file descriptor exceptions after running callable aliases multiple times (#5437)
### Motivation

Closes #5435.

### After

After this fix I can't reproduce this:
* https://github.com/xonsh/xonsh/issues/5241#issuecomment-1961249511
  * We can revert https://github.com/xonsh/xonsh/pull/5288
* https://github.com/xonsh/xonsh/issues/5393 
  * We can revert https://github.com/xonsh/xonsh/pull/5403

### Next step

Here is the PR for unpin ptk - #5438

## 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>
2024-05-23 14:07:30 -04:00
Andy Kipp
0f25a5a348
Read stop signals from the process and update the process state. (#5361)
Reading stop signals from the process and update the process state.

### The issue

Technically. In a couple of places that critical for processing signals
we have `os.waitpid()`. The function behavior is pretty unobvious and
one of things is processing return code after catching the signal. We
had no good signal processing around this and this PR fixes this. See
also `proc_untraced_waitpid` function description.

From user perspective. For example we have process that is waiting for
user input from terminal e.g. `python -c "input()"` or `fzf`. If this
process will be in captured pipeline e.g. `!(echo 1 | fzf | head)` it
will be suspended by OS and the pipeline will be in the endless loop
with future crashing and corrupting std at the end. This PR fixes this.

### The solution

Technically. The key function is `proc_untraced_waitpid` - it catches
the stop signals and updates the process state.

From user perspective. First of all we expect that users will use
captured object `!()` only for capturable processes. Because of it our
goal here is to just make the behavior in this case stable.
In this PR we detect that process in the pipeline is suspended and we
need to finish the command pipeline carefully:
* Show the message about suspended process.
* Keep suspended process in `jobs`. The same behavior we can see in
bash. This is good because we don't know what process suspended and why.
May be experienced user will want to continue it manually.
* Finish the CommandPipeline with returncode=None and suspended=True.

### Before

```xsh
!(fzf) # or !(python -c "input()")
# Hanging / Exceptions / OSError / No way to end the command.
# After exception:
$(echo 1)
# OSError / IO error
```

### After

```xsh
!(fzf) # or `!(ls | fzf | head)` or `!(python -c "input()")`
# Process ['fzf'] with pid 60000 suspended with signal 22 SIGTTOU and stay in `jobs`.
# This happends when process start waiting for input but there is no terminal attached in captured mode.
# CommandPipeline(returncode=None, suspended=True, ...)

$(echo 1)
# Success.
```
Closes #4752 #4577

### Notes

* There is pretty edge case situation when the process was terminated so
fast that we can't catch pid alive and check signal
([src](67d672783d/xonsh/jobs.py (L71-L80))).
I leave it as is for now.

### Mentions

#2159

## 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>
Co-authored-by: Gil Forsyth <gforsyth@users.noreply.github.com>
2024-05-22 11:45:39 -04:00
Andy Kipp
635d7837c5
Saving history on SIGINT (#5425)
### Motivation

Development tools like PyCharm send SIGINT before SIGKILL in case of
reload app. Saving history on SIGINT is the last chance to save history
in this case.

I understand that history will be flushed on Ctrl+C (SIGINT) but it
looks like no bad consequences of this. In addition history saving will
be more stable.

### Before
```xsh
# Development in PyCharm
xonsh --no-rc
echo cmd
# Ctrl+RR of Ctrl+DD to restart.
# Command history lost.
```

### After
```xsh
# Development in PyCharm
xonsh --no-rc
echo cmd
# Ctrl+R Ctrl+R for restart
# Command history is here.
```

Closes #2657

### Env

Use `$XONSH_HISTORY_SIGINT_FLUSH=False` to switch it off.

## 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>
2024-05-22 10:20:08 -04:00
Andy Kipp
c5f7b74ca8
Show `root and @#` in prompt if user is superuser. (#5409)
### Before

```xsh
sudo xonsh --no-rc
# <user>@host ~ #
```


### After

```xsh
sudo xonsh --no-rc
# root@host ~ @#
```

It's in sync with:

```xsh
docker run -it ubuntu bash
# root@ce01c2856819:/#
echo $USER
# 
# root@ce01c2856819:/#
```
## 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>
2024-05-22 09:27:03 -04:00
Andy Kipp
aa69ce868a
Now last executed CommandPipeline is available in `__xonsh__.last` (#5422)
### Motivation

There is no way to access to the CommandPipeline of executed command in
uncaptured mode. This causes:
 * No chance to get return code in one universal way.
 * Barrier to trace and inspection.

### Before

```xsh
$(ls nofile)
# No way to access to the CommandPipeline of executed command.
```

### After
```xsh
$(ls nofile)
__xonsh__.last.rtn  # In interactive or not interactive.
# 2
```
```xsh
# Sugar sir:
last = type('LastCP', (object,), {'__getattr__':lambda self, name: getattr(__xonsh__.last, name) })()

ls nofile
last.rtn
# 2
```

JFYI #5342

## 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>
2024-05-22 09:25:35 -04:00
Andy Kipp
f50a9e577c
Fix 5379, 5429 (#5432)
Fix described in
https://github.com/xonsh/xonsh/issues/5358#issuecomment-2104322754
Closes #5379, #5429

## For community
⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍
comment**
2024-05-22 08:27:44 +05:30
Andy Kipp
f17b72ca1f
Added `env.detype_all()` to get all available variables that is possible to detype. (#5431)
### Motivation

Closes #4636 

In fact`Env` manages two lists: explicitly set values and Xettings. When
we operate with env we have no detyping for Xettings. The `detype_all`
function doint detyping for all possible env variables.

### Before

```xsh
# No way to get all detyped variables e.g.
'PROMPT' in __xonsh__.env.detype()
# False
```

### After
```xsh
'PROMPT' in __xonsh__.env.detype_all()
# True
```

## 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>
2024-05-22 07:53:11 +05:30
Andy Kipp
9073a4c33c
Make xonsh tolerant to inaccessible paths: history backend, script cache (#5430)
Closes #5319

### Before

```xsh
mkdir -p /tmp/noaccess
chmod 000 /tmp/noaccess
echo 'print(1)' > /tmp/1.xsh

xonsh --no-rc --no-env -DXONSH_DATA_DIR='/tmp/noaccess'
# Json History error

xonsh --no-rc --no-env -DXONSH_DATA_DIR='/tmp/noaccess' /tmp/1.xsh
# Script cache error
```

### After

```xsh
mkdir -p /tmp/noaccess
chmod 000 /tmp/noaccess
echo 'print(1)' > /tmp/1.xsh

xonsh --no-rc --no-env -DXONSH_DATA_DIR='/tmp/noaccess'
# Error during load <class 'xonsh.history.json.JsonHistory'>: [Errno 13] Permission denied: '/tmp/noaccess/history_json'
# Set $XONSH_HISTORY_BACKEND='dummy' to disable history.
# History disabled.
# @

xonsh --no-rc --no-env -DXONSH_DATA_DIR=/tmp/noaccess /tmp/1.xsh
# xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
# update_cache: Cache file is not writable: /tmp/noaccess/xonsh_script_cache/private/tmp/1_.xsh.cpython-311
# Set $XONSH_CACHE_SCRIPTS=0, $XONSH_CACHE_EVERYTHING=0 to disable cache.
# 1
```
And no warnings when everything is switched off:
```xsh
xonsh % python -m xonsh --no-rc --no-env -DXONSH_DATA_DIR=/tmp/noaccess -DXONSH_HISTORY_BACKEND=dummy
# @

xonsh --no-rc --no-env -DXONSH_DATA_DIR=/tmp/noaccess -DXONSH_CACHE_SCRIPTS=0 -DXONSH_CACHE_EVERYTHING=0 /tmp/1.xsh
# 1
```

## 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>
2024-05-20 21:14:14 +02:00
Noorhteen Raja NJ
e03bda413a
Fix argparser (#5421)
fixed the issue caused by regression 


## For community
⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍
comment**
2024-05-16 16:31:05 +05:30
Noorhteen Raja NJ
51a14c989d
chore: use stable 3.12 for CI jobs (#5307) 2024-05-16 15:43:57 +05:30
Noorhteen Raja NJ
614ddebc59
fix: update virtualenv activator (#5419) 2024-05-16 14:29:48 +05:30
Andy Kipp
a79d48c749
History: Saving history in case of any type of exiting the shell. (#5418)
### Before

```xsh
echo 1 
echo 2
# <<Crash>>
# No json history
```

### After

Closes #2657

```xsh
echo 1 
echo 2
# <<Crash>>
# In json history
# echo 1
# echo 2
```

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

---------

Co-authored-by: a <1@1.1>
2024-05-16 11:01:38 +05:30
Andy Kipp
948510e40a
More detailed proc proxy name (#5417)
When cls.f is partial it's better to show full specification.

## 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>
2024-05-15 14:10:53 +02:00
Andy Kipp
e7f2489486
Skip welcome if there is no TTY (#5414)
## For community
⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍
comment**

---------

Co-authored-by: a <1@1.1>
2024-05-15 03:18:19 +02:00
pre-commit-ci[bot]
eff74d9d9a
[pre-commit.ci] pre-commit autoupdate (#5412)
<!--pre-commit.ci start-->
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.4.3 →
v0.4.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.4.3...v0.4.4)
<!--pre-commit.ci end-->

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-05-13 21:22:46 +02:00
Andy Kipp
ef578c1ca6
Ignore ptk warning (#5410)
Because we downgraded ptk in https://github.com/xonsh/xonsh/pull/5403

### Before

```xsh
xonsh --no-rc
# /Users/pc/.local/mamba-envs/lib/python3.12/site-packages/prompt_toolkit/application/application.py:961: DeprecationWarning: There is no current event loop
#  loop = asyncio.get_event_loop()
#@
```

### After

```xsh
xonsh --no-rc
#@
```

## 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>
2024-05-13 09:41:05 -04:00
Andy Kipp
fd5304fb87
fix(signals): fix processing exit signals and exit exception (#5399)
### Before

Case 1: Handler catches the exit signal and do not pass it forward. As
result xonsh could be suspended by OS or crash. Also exit code is wrong.
See repeatable examples with SIGHUP in
https://github.com/xonsh/xonsh/issues/5381#issuecomment-2097961804.

Case 2: From bash/zsh as login shell run xonsh. Then send quit signal to
xonsh. The terminal state will be broken: disabled SIGINT, mouse pointer
produces mouse state codes.

### After

Case 1: Xonsh exit normally with right exit code. Fixed #5381 #5304
#5371.

Case 2: After exiting with right exit code the state of the terminal is
good.

## 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>
2024-05-13 09:31:55 -04:00
Andy Kipp
bb394a8e84
feat: add superhelp and additional context via new FuncAlias (#5366)
### Goals

* Make callable aliases transparent.
* Catch errors in callable aliases and show the name of the source.
* Show additional attributes: thredable, capturable.
* Closes #5266

## Exception

### Before

```xsh
aliases['cd']
# <function xonsh.dirstack.cd>

aliases['trace']
# <function xonsh.aliases.trace>

aliases['null'] = lambda: 1/0
null
# ZeroDivisionError: division by zero

@aliases.register('catch')
@aliases.register('me')
@aliases.register('if')
@aliases.register('you')
@aliases.register('can')
def _exc(args, stdin, stdout):
    for line in stdin.readlines():
        print(line.strip() + '!', file=stdout, flush=True)
    return 1/0 if 'i' in $__ALIAS_NAME else 0

echo hey | catch | me | if | you | can
# ZeroDivisionError: division by zero      <--- ???
# hey!!!!!
```

### After

```xsh 
aliases['cd']
# FuncAlias({'name': 'cd', 'func': 'cd'})

aliases['trace']
# FuncAlias({'name': 'trace', 'func': 'trace', '__xonsh_threadable__': False})

$XONSH_SHOW_TRACEBACK=False
$RAISE_SUBPROC_ERROR = False
aliases['null'] = lambda: 1/0
null
#Exception in thread {'cls': 'ProcProxyThread', 'name': 'Thread-15', 'func': FuncAlias({'name': 'null', 'func': '<lambda>'}), 'alias': 'null', 'pid': None}
#ZeroDivisionError: division by zero



@aliases.register('catch')
@aliases.register('me')
@aliases.register('if')
@aliases.register('you')
@aliases.register('can')
def _exc(args, stdin, stdout):
    for line in stdin.readlines():
        print(line.strip() + '!', file=stdout, flush=True)
    return 1/0 if 'i' in $__ALIAS_NAME else 0
echo hey | catch | me | if | you | can
# Exception in thread {'cls': 'ProcProxyThread', 'name': 'Thread-8', 'func': FuncAlias({'name': 'if', 'func': '_exc'}), 'alias': 'if', 'pid': None}
# ZeroDivisionError: division by zero
# hey!!!!!
```

## Superhelp

### Before
```xsh
@aliases.register("hello")
def _alias_hello():
    """Show world."""
    print('world')

hello?
# No manual entry for hello
```

### After
```xsh
@aliases.register("hello")
def _alias_hello():
    """Show world."""
    print('world')

hello?
# FuncAlias({'name': 'hello', 'func': '_alias_hello'}):
# Show world.
```



## 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>
2024-05-13 09:11:58 -04:00
Andy Kipp
55b341d477
Add Jupytext to news (#5402)
https://github.com/xonsh/xonsh/discussions/5401

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

---------

Co-authored-by: a <1@1.1>
2024-05-10 11:03:44 +02:00