Commit graph

203 commits

Author SHA1 Message Date
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
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
a
79f02e9ea4 update 2024-04-21 17:14:31 +05:30
Andy Kipp
330f150f6a
EnvPath methods (append, remove, add, insert) prepare the path (#5349)
* EnvPath methods (append, remove, add, insert) prepare the path before add.

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

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

* update

* update

* update

* update

* update

---------

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-21 10:03:42 +02:00
pre-commit-ci[bot]
66c0490d37
[pre-commit.ci] pre-commit autoupdate (#5271)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/psf/black: 23.12.1 → 24.1.1](https://github.com/psf/black/compare/23.12.1...24.1.1)

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

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

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-01-30 12:23:50 +01:00
Noorhteen Raja NJ
769dfbe6aa
Py 312 pre-liminary support (#5156)
* refactor: project requires 3.9+

changed as per NEP-29
https://numpy.org/neps/nep-0029-deprecation_policy.html

* test: nose type tests are deprecated in pytest now

* fix: deprecation of ast.Str and ast.Bytes and .s attribute access

* fix: deprecation of ast.Num,ast.NameConstant,ast.Ellipsis

* refactor: upgrade code to be py39+ using ruff

the changes are auto-generated

* refactor: remove typing.Annotated compatibility code

* fix: temporarily disable having xonsh syntax inside f-strings

* test: skip failing tests

there is no workaround for this version. It might get solved in the
final release though

* refactor: make XonshSession.completer lazily populated

this speedsup the tests as cmd_cache would not be actively populated
when used in default_completers function

* refactor: make presence of walrus operator default
2023-07-04 22:18:37 +05:30
austin-yang
ed11f319fa
Fix: Allows user to assign #XONSH_STYLE_OVERRIDES a {Token:str} dictionary #4375 (#4973)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-10-24 10:46:52 -04:00
Blake Ramsdell
b5c42d6716
Add XONSH_HISTORY_IGNORE_REGEX support (#4953)
* Add XONSH_HISTORY_IGNORE_REGEX support

* Add changelog text

* Add cleanup notes for XONSH_HISTORY_IGNORE_REGEX

* Rename should_append to is_ignored

* Change is_ignored to a History method

* Remove unused re imports

* Docstring formatting cleanup, Black compliance

* Move XONSH_HISTORY_IGNORE_REGEX to History class

* Clarify with parenthesis

* Formatting compliance

* Add validate_ignore_regex check

* Remove validation comment

* Remove XONSH_HISTORY_IGNORE_REGEX test comments

* Add __init__ chaining to DummyHistory

* Add broken test for XONSH_IGNORE_REGEX

* Remove extra test variants

* Fix unit test environment variable name

* Add test for bad regex error output

* Remove unneeded __init__ chaining

* Add test_is_ignore

* Add is_regex and associated tests

* Add doc for XONSH_HISTORY_IGNORE_REGEX

* Change validate_ignore_regex to use is_regex

* Compile regex once and use a cached property

* Let cached_property handle saving regex
2022-10-05 00:16:42 +05:30
Noortheen Raja
f2b7d4ed4f style: sort imports 2022-03-24 19:49:30 +05:30
Noortheen Raja
81b65556a5 chore: update tests 2022-03-24 19:49:30 +05:30
Peter Ye
b581edb05d
Fix $XONSH_TRACEBACK_LOGFILE path expansion (#4713) 2022-03-15 00:31:24 +05:30
Noortheen Raja
78091a22f3 style: isort imports
fix #4584
2022-01-31 11:16:51 -05:00
dev2718
1aefbf3b35
Fix: detype None env-vars to '' to fix #4600 (#4649)
* detype untyped and path env-vars to ""; path_to_str("") == None

* update env-var-tutorial, add news

* update test_expandvars, test_expand_path, test_register_custom_var_str

* trigger CI-rerun since unrelated osx test failed

Co-authored-by: Alexander Firbas <alexander.firbas@gmail.com>
2022-01-21 14:46:50 +05:30
Noorhteen Raja NJ
7c4e207abd
update test xsh usage (#4581)
* todo

* test: remove usage of DummyEnv and setting .env attribute on xession fixture

one step closer to making too much of tweaking to xession during tests

* test: fix tests vox and gitstatus-prompt

* docs: update test-fixture usage

* fix: import flake8 error

* test: remove direct access to XSH in tests

* test: remove usage of XSH in test files

* todo

* test: use tmp-dir to create stubs

* refactor: use fixture factory to mock out XonshSession

* refactor: remove direct access of XSH from functions

* refactor: remove direct access of XSH from functions

* fix: qa checks

* refactor: rename variables to match their values

* test: update failing tests because it had no PATH set previously

* fix: remove builtins usage from pyghooks.py

* style:

* refactor: update tests to use fixtures

* fix: env varialbe is setup per function

some tests accidentally update the env variables and that is leaking
into next tests

* fix: failing vox tests

* test: set commands_cache per test

* test: fix failing tests

* fix: failing tests on linux

ptk-highlight

* fix: failing tests on Windows

cwd-prompt

* test: copy env as to not affect original object

* fix: lazily evaluate cmds-cache in pyghooks

* test: fix failing tests

* fix: qa errors import

* test: set commands-cache per test

while caching path results

* test: speedup test_thread_local_swap

* fix: failing tests on windows

* refactor: Execer doesn't control session

* refactor: XSH.unload will take care of reversing builtins attrs set

* test: use env.update over monkeypatch

* Revert "test: use env.update over monkeypatch"

This reverts commit 010a5022247a098f1741966b8af1bf758663480e.
2022-01-07 17:33:22 -05:00
Noorhteen Raja NJ
c2d25ac251
pre-commit hook for pyupgrade (#4583)
* chore: add pyupgrade

* refactor: upgrade code to py3.7+

ran `pre-commit run pyupgrade -a` while excluding changes to ply

* fix: flake errors
2021-12-06 14:42:26 -05:00
Michael Ramsey
c04a0997ed
Fix: EnvPath.add() not maintain uniqueness with Path objects on replace (#4461)
* Fix: EnvPath.add() not maintain uniqueness with Path objects on replace

* Update tools.py

Removed commented out code left in originally

* Add tests for EnvPath.add() function

* Add test for EnvPath.add() function with pathlib path

* Update tests for EnvPath.add() function to support winblows paths

* Fix xontribs meta page so github links clickable and one minor typo

* Update xonsh/xontribs_meta.py

updated as requested

Co-authored-by: Gil Forsyth <gforsyth@users.noreply.github.com>

Co-authored-by: Gil Forsyth <gforsyth@users.noreply.github.com>
2021-09-14 12:54:18 -04:00
Peter Ye
d33d60ee3e
Fix the handling of colons when mixed with comments (#4332)
* Add ends_with_colon_token tool

* Add execer test for comment ending with a colon

* Use ends_with_colon_token() to catch non-indented blocks in execer

* Use ends_with_colon_token() for automatic indentation in prompt_toolkit and readline

* Add news
2021-06-20 12:50:03 +03:00
Noorhteen Raja NJ
38295a1dd9
Remove globals (#4280)
* refactor: remove usage of global variables in abbrevs.py

* chore: add flake8-mutable to prevent mutable defaults

* fix: abbrevs expand test

* refactor: add xonsh session singleton

* refactor: fix circular errors when using xonshSession as singleton

* refactor: remove black magicked builtin attributes

* style: black format tests as well

* refactor: update tests to use xonsh-session singleton

* refactor: update abbrevs to not use builtins

* test: remove DummyCommandsCache and patch orig class

* fix: failing test_command_completers

* test: use monkeypatch to update xession fixture

* fix: failing test_pipelines

* fix: failing test_main

* chore: run test suit as single invocation

* test: fix tests/test_xonsh.xsh

* refactor: remove builtins from docs/conf.py

* fix: mypy error in jobs

* fix: test error from test_main

* test: close xession error in test_command_completers

* chore: use pytest-cov for reporting coverage

this will include subprocess calls, and will increase coverage

* style:
2021-05-20 13:14:26 +03:00
Bob Hyman
b44dc70af7
Add $COMPLETION_MODE='menu-complete' to enable readline menu-complete (#3876)
* Add $COMPLETION_MODE='menu-complete' to enablereadline menu-complete -like behavor in completion.

* Tests

Co-authored-by: Bob Hyman <bob.hyman@bobssoftwareworks.com>
2020-11-05 16:12:15 -05:00
Gyuri Horak
120fc0a154
merge with upstream 2020-10-14 15:09:24 +02:00
Gyuri Horak
a2213d614c
unit tests for xonsh.tools.register_custom_style 2020-10-14 15:03:30 +02:00
Noortheen Raja
a930134ccf fix: env handle optional values
handle None value for ASYNC_PROMPT_THREAD_WORKERS

fixes #3858
2020-10-10 22:14:30 +05:30
a
d88fdc6609 simple_random_choice 2020-10-09 22:08:10 +03:00
a
87ce6bfc4d test 2020-10-09 19:12:48 +03:00
a
9f3170dbe3 fix 3818: Env variables wrong substitution 2020-10-05 13:56:44 +03:00
a
b53df868ce windows tests to the god of windows tests 2020-10-01 00:09:48 +03:00
a
85fc912cf7 tests to the god of tests 2020-09-30 23:34:51 +03:00
Anthony Scopatz
22610f48d6 THREAD_SUBPROCS=None for xonshrc files 2020-08-20 20:11:37 -05:00
Morten Enemark Lund
c7372342da Fix legitimate builtins has no attribute __xonsh__ errors 2020-08-10 13:24:10 +02:00
Bob Hyman
26475146e2
Flake8 1 (#3550)
* flake8 fixes -- tests only

* fix ci failure

* integrate fix from is_3551 so tests will pass.

* Update tests/test_builtins.py

Co-authored-by: Gil Forsyth <gforsyth@users.noreply.github.com>
2020-05-05 06:42:28 -04:00
Anthony Scopatz
f1127ed916 Revert "updated setup.py for Python 3.4 (revert of 91ec14bb6d)"
This reverts commit 002a317951.
2019-05-14 17:41:35 -04:00
Anthony Scopatz
002a317951 updated setup.py for Python 3.4 (revert of 91ec14bb6d) 2019-05-14 17:32:31 -04:00
Rodrigo Oliveira
91ec14bb6d Drop support for Python 3.4
Minimal required Python version is now 3.5.
2019-05-06 16:51:32 -03:00
Anthony Scopatz
2bb787411d some color modifier additions, but it is too slow now 2019-03-06 17:49:22 -08:00
Anthony Scopatz
1c6b1e1ea4 black 2019-02-13 18:49:39 -05:00
Anthony Scopatz
396dce8088 some windows test fixes and skips 2018-12-06 13:35:43 -05:00
Anthony Scopatz
609370d48e try this 2018-12-05 20:17:38 -05:00
Anthony Scopatz
3e72fb06c7 path tests 2018-11-08 13:19:21 -05:00
Anthony Scopatz
84a5b05a36 partial andadh fix 2018-11-07 17:32:53 -05:00
Morten Enemark Lund
37d375260e Fix deprecation warnings when running pytest 2018-10-03 09:52:03 +02:00
Anthony Scopatz
4c91df2abc many test fixes 2018-09-13 14:03:35 -04:00
Anthony Scopatz
b23d6eccdb black 2018-09-12 19:19:36 -04:00
Anthony Scopatz
d62a44d2c5 skip on v34 2018-09-12 18:17:58 -04:00
Anthony Scopatz
a444093290 dotfile matching 2018-09-12 18:12:02 -04:00
Anthony Scopatz
634a8ec9f2 black tests 2018-08-30 09:18:49 -05:00
Anthony Scopatz
3b0fe9144d fixed multiline autowrapping in @(expr) 2018-07-19 21:01:11 -04:00
Anthony Scopatz
38cffd2bdc Py v3.4 compat 2017-12-07 17:17:53 -05:00
Anthony Scopatz
70d7ef7c31 added test for iglobpath 2017-12-07 16:44:01 -05:00
Anthony Scopatz
70b5b85d37 fix for running tests as root 2017-11-22 19:19:22 -05:00
Anthony Scopatz
b1ec6c7069 fix for echo * spam ; echo spam 2017-11-09 20:20:40 -05:00