Commit graph

10602 commits

Author SHA1 Message Date
Andy Kipp
d2d13f028f
Downgrade prompt-toolkit to >=3.0.29,<3.0.40 (#5403)
This downgrade continues previous (#5288). Found issue in prompt-toolkit
3.0.40 (#5393).

JFYI #5241

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

Co-authored-by: a <1@1.1>
2024-05-09 09:13:03 -04:00
pre-commit-ci[bot]
4a2cfc6415
[pre-commit.ci] pre-commit autoupdate (#5397)
<!--pre-commit.ci start-->
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.4.2 →
v0.4.3](https://github.com/astral-sh/ruff-pre-commit/compare/v0.4.2...v0.4.3)
<!--pre-commit.ci end-->

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-05-06 20:20:34 +02:00
Andy Kipp
ac7bc67406
Fixed showing exception message (#5394)
subj

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-06 19:48:43 +05:30
Andy Kipp
b19a89b432
Fixed `xonsh -DVAR=VAL` behavior: initiate env variables before shell initialization. (#5396)
### Before

Case 1:
```xsh
xonsh --no-rc --no-env -DCOLOR_OUTPUT 0  # space between -DVAR and VALUE
```
```xsh
Traceback (most recent call last):
  File "/Users/pc/.local/xonsh-env/lib/python3.12/site-packages/xonsh/main.py", line 478, in main
    args = premain(argv)
           ^^^^^^^^^^^^^
  File "/Users/pc/.local/xonsh-env/lib/python3.12/site-packages/xonsh/main.py", line 420, in premain
    env.update([x.split("=", 1) for x in args.defines])
  File "<frozen _collections_abc>", line 987, in update
ValueError: not enough values to unpack (expected 2, got 1)
Xonsh encountered an issue during launch
```
Case 2:
```xsh
xonsh --no-rc --no-env -DXONSH_HISTORY_BACKEND=dummy
history info
# json  # EXPECTED: dummy
```

### After
Case 1:
```xsh
xonsh --no-rc --no-env -DCOLOR_OUTPUT 0
# Wrong format for -DCOLOR_OUTPUT argument. Use -DVAR=VAL form.
```

Case 2:
```xsh
xonsh --no-rc --no-env -DXONSH_HISTORY_BACKEND=dummy
history info
# dummy
```

Closes #5395

## 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-06 17:39:10 +05:30
Andy Kipp
cdc1d602a2
Fixed empty stacktrace for CalledProcessError (#5391)
Fixed #5387

### Before

```xsh
$XONSH_SHOW_TRACEBACK = False
$RAISE_SUBPROC_ERROR = True

ls nofile
# ls: nofile: No such file or directory
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
#
```

### After 

```xsh
$RAISE_SUBPROC_ERROR = False
$XONSH_SHOW_TRACEBACK = False
ls nofile
# ls: nofile: No such file or directory

$RAISE_SUBPROC_ERROR = True
$XONSH_SHOW_TRACEBACK = False
ls nofile
# ls: nofile: No such file or directory
# subprocess.CalledProcessError: Command '['ls', 'nofile']' returned non-zero exit status 1.

$RAISE_SUBPROC_ERROR = True
$XONSH_SHOW_TRACEBACK = True
ls nofile
# ls: nofile: No such file or directory
# Traceback (most recent call last):
# ...
# subprocess.CalledProcessError: Command '['ls', 'nofile']' returned non-zero exit status 1.

$RAISE_SUBPROC_ERROR = False
$XONSH_SHOW_TRACEBACK = True
ls nofile
# ls: nofile: No such file or directory
```

## 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-04 11:50:32 +02:00
Andy Kipp
c3cd47e1da
Revert "Update new-issue.md: update issue template" (#5390)
Reverting xonsh/xonsh#5389 with update by comments

---------

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-03 11:37:33 -04:00
Andy Kipp
f6f06fc256
Update new-issue.md: update issue template (#5389)
## For community
⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍
comment**
2024-05-03 12:10:34 +02:00
Andy Kipp
a3e8b1a025
Use substring for env completion and better way to sort list (#5388)
### Motivation

It's very annoying to search env variable exactly by lprefix. The better
is to search by substring and sort results by the position of substring
and then alphabetically.

Closes #5386

### Before

```xsh
$TRA<Tab>
# nothing
```

### After
```xsh
$TRA<Tab>
# 'XONSH_TRACE_COMPLETIONS', 
# 'XONSH_TRACE_SUBPROC', 
# 'XONSH_TRACE_SUBPROC_FUNC', 
# 'XONSH_TRACEBACK_LOGFILE', 
# 'XONSH_SHOW_TRACEBACK', 
# 'VC_GIT_INCLUDE_UNTRACKED'
```

## 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-03 10:30:14 +02:00
Andy Kipp
21da30e753
Fixed populating the return code for interrupted process. (#5380)
### Motivation

There is annoying behavior when you run command in the loop and can't
interrupt e.g. [this
report](https://github.com/xonsh/xonsh/discussions/5371) and a bit
#5342. After diving into this I see the issue around return code.

### The essence

Basically ``p = subprocess.Popen()`` populates ``p.returncode`` after
``p.wait()``, ``p.poll()`` or ``p.communicate()``
([doc](https://docs.python.org/3/library/os.html#os.waitpid)). But if
you're using `os.waitpid()` BEFORE these functions you're capturing
return code from a signal subsystem and ``p.returncode`` will be ``0``
like success but it's not success. So after ``os.waitid`` call you need
to set return code manually ``p.returncode = -os.WTERMSIG(status)`` like
in Popen. Example:
```xsh
python  # python interactive

import os, signal, subprocess as sp

p = sp.Popen(['sleep', '100'])
p.pid
# 123
p.wait()
# Ctrl+C or `kill -SIGINT 123` from another terminal
p.returncode
# -2

# BUT:

p = sp.Popen(['sleep', '100'])
p.pid
# 123

pid, status = os.waitpid(p.pid, os.WUNTRACED)
# status=2

# From another terminal:
kill -SIGINT 123

p.wait()
# 0
p.returncode
# 0
```

```xsh
from xonsh.tools import describe_waitpid_status
describe_waitpid_status(2)
# WIFEXITED - False - Return True if the process returning status exited via the exit() system call.
# WEXITSTATUS - 0 - Return the process return code from status.
# WIFSIGNALED - True - Return True if the process returning status was terminated by a signal.
# WTERMSIG - 2 - Return the signal that terminated the process that provided the status value.
# WIFSTOPPED - False - Return True if the process returning status was stopped.
# WSTOPSIG - 0 - Return the signal that stopped the process that provided the status value.
```

See also: [Helpful things for
knight](https://github.com/xonsh/xonsh/pull/5361#issuecomment-2078826181).

### Before

```xsh
$RAISE_SUBPROC_ERROR = True

sleep 100
# Ctrl+C
_.rtn
# 0  # It's wrong and RAISE_SUBPROC_ERROR ignored.

for i in range(5):
    print(i)
    sleep 5
# 0
# Ctrl+C  # Can't interrupt
# 1
# 2 
```

### After
```xsh
sleep 100
# Ctrl+C
_.rtn
# -2  # Like in default Popen

$RAISE_SUBPROC_ERROR = True
for i in range(5):
    print(i)
    sleep 5
# 0
# Ctrl+C
# subprocess.CalledProcessError
```

### Notes

* We need to refactor `xonsh.jobs`. It's pretty uncomfortable work with
module.
* The logic is blurry between Specs, Pipelines and Jobs. We need to
bring more clear functions.
* The `captured` variable looks like "just the way of capturing (stdout,
object)" but in fact it affects all logic very much. We need to create
table where we can see the logic difference for every type of capturing.
E.g. in `captured=stdout` mode we use `xonsh.jobs` to monitor the
command but in `captured=object` we avoid this and some logic from
`xonsh.jobs` applied in `stdout` mode but missed in `object` mode. We
need clear map.

## 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-02 22:10:53 +02:00
Andy Kipp
89a8457de3
Update built_ins.py: comment fix (#5384)
wip

Co-authored-by: a <1@1.1>
2024-05-02 21:07:19 +02:00
Andy Kipp
a5f0308a5a
CommandPipeline: clean repr + a bit of code cleaning (#5369)
* XONSH_TRACE_SUBPROC returns more useful details.

* update

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Name obj to thread because it's thread!

* update

* wip

* wip

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

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-03 00:09:31 +05:30
Andy Kipp
c4c7d1cbd7
Xonfig: show sensitive env variables that could affect the shell behavior. (#5374)
* wip

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added XONSH_SUBPROC_OUTPUT_FORMAT

---------

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-02 22:46:22 +05:30
Andy Kipp
4906ba8598
Update tutorial.rst: remove new line chars (#5382)
Update tutorial.rst
2024-05-02 18:01:06 +02:00
Andy Kipp
c5cb7044b5
feat: add subproc output format, autostrip singleline output (#5377)
### Motivation

* To have an ability to manage the output format added ``$XONSH_SUBPROC_OUTPUT_FORMAT`` to switch the way to return the output lines. Default ``stream_lines`` to return text. Alternative ``list_lines`` to return the list of lines. Also supported custom lambda function.
* Additionally the [proposal to change default behavior](https://github.com/xonsh/xonsh/pull/5377#discussion_r1587627131) for a single line case.
* Closes #3924 as soft solution.

### Before

```xsh
mkdir -p /tmp/tst && cd /tmp/tst && touch 1 2 3

$(ls)
# '1\n2\n3\n'

id $(whoami)
# id: ‘pc\n’: no such user: Invalid argument

du $(ls)
# du: cannot access '1'$'\n''2'$'\n''3'$'\n': No such file or directory

ls $(fzf)
# ls: cannot access 'FUNDING.yml'$'\n': No such file or directory
```

### After

```xsh
mkdir -p /tmp/tst && cd /tmp/tst && touch 1 2 3

$XONSH_SUBPROC_OUTPUT_FORMAT = 'list_lines'

$(ls)
# ['1', '2', '3']

[f for f in $(ls)]
# ['1', '2', '3']

id $(whoami)
# uid=501(user) gid=20(staff)

du $(ls)
# 0 1
# 0 2
# 0 3

ls $(fzf)
# FUNDING.yml

# etc
mkdir -p /tmp/@($(whoami))/dir
cat /etc/passwd | grep $(whoami)
```

### Notes

* It will be good to improve parser for cases like `mkdir -p /tmp/$(whoami)/dir`. PR is welcome!
* I named the default mode as `stream_lines` (instead of just `stream` or `raw`) because in fact we transform raw output into stream of lines and possibly reduce the length of output ([replacing `\r\n` to `\n`](c3a12b2a9c/xonsh/procs/pipelines.py (L380-L383))). May be some day we need to add raw "stream" output format.
* Now anybody can implement bash `IFS` behavior in [bashisms](https://github.com/xonsh/xontrib-bashisms).

---------

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-02 11:48:25 -04:00
doronz88
9ae34e140c which: fix handling of None results (#5358) 2024-05-01 13:07:38 +05:30
Noorhteen Raja NJ
b8f91cdf22
fix: trace help on empty args
fixes #5373
2024-04-30 18:52:00 +05:30
pre-commit-ci[bot]
3ab2c967c2
[pre-commit.ci] pre-commit autoupdate (#5376)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.4.1 → v0.4.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.4.1...v0.4.2)
- [github.com/pre-commit/mirrors-mypy: v1.9.0 → v1.10.0](https://github.com/pre-commit/mirrors-mypy/compare/v1.9.0...v1.10.0)

* fix riff warnings

* fix riff warnings

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix riff warnings

* update

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix riff warnings

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix riff warnings

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix riff warnings

* update

* fix riff warnings

* update

* update

* fix riff warnings

* fix riff warnings

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: a <1@1.1>
2024-04-30 13:42:32 +02:00
Jason R. Coombs
d835a8a1e8
Leverage sort for sorting items. (#5378) 2024-04-30 11:21:31 +02:00
Andy Kipp
c3a12b2a9c
feat: add --no-env flag to avoid inheriting parent-shell env (#5370)
### Motivation

Basically we use `xonsh --no-rc` to have pure xonsh. 
I noticed many times when parent environment can affect `xonsh --no-rc` e.g. `$XONSH_HISTORY_FILE`.
Current workaround is `env -i @$(which xonsh) --no-rc` but I think we need to have pure xonsh way.

Closes #4921

### Before

```xsh
xonsh --no-rc
$QWE = 1
xonsh --no-rc
$QWE
# 1
```

### After
```xsh
xonsh --no-rc
$QWE = 1
xonsh --no-rc --no-env
$QWE
# Unknown environment variable: $QWE

$XONSH_ENV_INHERITED  # Marker to have a way to catch this situation.
# False
```

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-04-29 12:29:22 -04:00
Gil Forsyth
81865354a1 chore(README): remove old CI status badges, light language polish 2024-04-29 21:16:17 +05:30
Andy Kipp
f71b5adde8
Xonsh Zulip Community started (#5372)
* wip

* wip

---------

Co-authored-by: a <1@1.1>
2024-04-29 10:01:02 -04:00
Andy Kipp
61751c2319
jobs: catching ChildProcessError (#5365)
* Update jobs.py

* Create jobs_catch_no_process.rst

* Update jobs.py

* Update jobs_catch_no_process.rst

* Update jobs.py
2024-04-26 10:34:31 +02:00
Andy Kipp
8ab1b9a0ee
jobs: default representation changed to dict (#5363)
* update

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: a <1@1.1>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-04-26 10:26:24 +02:00
pre-commit-ci[bot]
874ad9ffe6 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-04-26 13:37:19 +05:30
a
a8a604d4c5 wip 2024-04-26 13:37:19 +05:30
a
134f313d73 wip 2024-04-26 13:37:19 +05:30
a
a769689515 wip 2024-04-26 13:37:19 +05:30
a
52c96c9dd5 wip 2024-04-26 13:37:19 +05:30
pre-commit-ci[bot]
0aceced733 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-04-26 13:37:19 +05:30
a
c9d87ab9b5 wip 2024-04-26 13:37:19 +05:30
pre-commit-ci[bot]
71ab4d2aeb [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-04-26 13:37:19 +05:30
a
d1f043e956 XONSH_TRACE_SUBPROC returns more useful details. 2024-04-26 13:37:19 +05:30
pre-commit-ci[bot]
c52ddd55ac [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-04-26 13:37:19 +05:30
a
ddd4bd93c9 XONSH_TRACE_SUBPROC returns more useful details. 2024-04-26 13:37:19 +05:30
pre-commit-ci[bot]
8921715379 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-04-26 13:37:19 +05:30
a
4250cce9fd XONSH_TRACE_SUBPROC returns more useful details. 2024-04-26 13:37:19 +05:30
pre-commit-ci[bot]
983a7c51d1 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-04-26 13:37:19 +05:30
a
24fdfece1e XONSH_TRACE_SUBPROC returns more useful details. 2024-04-26 13:37:19 +05:30
Andy Kipp
26c6e119e2
Shortcut for shell-type (#5367)
* Shortcut for shell-type

* Shortcut for shell-type

---------

Co-authored-by: a <1@1.1>
2024-04-25 20:10:18 +02:00
Andy Kipp
4dc17ca600
Downgrade AppImage to 3.11 (#5364)
* Update rever.xsh

* Create appimage_py311.rst
2024-04-25 11:46:36 +02:00
Andy Kipp
273f12d329
Add thread details to the exception (#5360)
* thread details

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: a <1@1.1>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-04-24 11:15:40 +02:00
Andy Kipp
af9c3afa23
Added detailed info about thread to thread exceptions (#5357)
* update

* update

* update

* update

* update

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: a <1@1.1>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-04-24 08:46:04 +02:00
Noorhteen Raja NJ
56e0257697
chore: Update publish.yml python versions (#5359) 2024-04-24 08:43:04 +02:00
Noortheen Raja
c071112584 chore: use uv for docs action 2024-04-24 09:16:33 +05:30
Noortheen Raja
a61860e623 chore: use uv for docs action 2024-04-24 09:16:33 +05:30
Noortheen Raja
499f35428a chore: use uv for docs action 2024-04-24 09:16:33 +05:30
Noortheen Raja
3b5f0b4a0d chore: uv to use system python 2024-04-24 09:16:33 +05:30
Noortheen Raja
93900e7239 feat: use uv for installing test deps
and use PuPI OICD to publish packages
2024-04-24 09:16:33 +05:30
Gil Forsyth
c508e0de60
Updated CHANGELOG for 0.16.0 2024-04-23 14:34:31 -04:00
Gil Forsyth
91b80bb664
bumped version to 0.16.0 2024-04-23 14:34:31 -04:00