Pre commit ci (#4863)

This commit is contained in:
Noorhteen Raja NJ 2022-07-01 21:17:01 +05:30 committed by GitHub
parent 8b9a7e2782
commit cbf23e60fb
Failed to generate hash of commit
30 changed files with 186 additions and 232 deletions

View file

@ -3,4 +3,4 @@ contact_links:
- name: GitHub Community Support
url: https://github.com/xonsh/xonsh/discussions/categories/q-a
about: Please ask and answer questions here.

View file

@ -54,9 +54,7 @@ jobs:
timeout-minutes: 15
- name: Run QA Checks
if: ${{ startsWith(matrix.os, 'ubuntu') && startsWith(matrix.python-version, '3.10') }}
run: |
python -m pip install -e ".[lint]"
python -m xonsh run-tests.xsh qa
run: python -m xonsh run-tests.xsh validate-news-items
- name: Run tests
if: ${{ !startsWith(matrix.python-version, '3.10') }}
run: |

View file

@ -1,49 +1,80 @@
repos:
- repo: local
hooks:
- id: black
name: black
# this gets run within development environment.
# Otherwise will raise command not found or use system level binary
entry: black xonsh/ xontrib/ tests/
language: system
stages: [ commit ]
types:
- python
- id: isort
name: isort
# this gets run within development environment.
# Otherwise will raise command not found or use system level binary
entry: isort xonsh/ xontrib/ tests/
language: system
stages: [ commit ]
types:
- python
- id: qa
name: qa
entry: xonsh run-tests.xsh qa
language: system
stages: [ push ]
pass_filenames: false
types:
- python
default_language_version:
# force all unspecified python hooks to run python3
python: python3.10
ci:
autofix_prs: false
repos:
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black
entry: black xonsh xontrib tests xompletions
pass_filenames: false
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
entry: isort xonsh xontrib tests xompletions
pass_filenames: false
name: isort (python)
- repo: https://github.com/pycqa/flake8
rev: '4.0.1' # pick a git hash / tag to point to
hooks:
- id: flake8
additional_dependencies:
- flake8-docstrings
- flake8-bugbear
# Check for debugger imports and py37+ breakpoint() calls in python source.
- flake8-debugger
exclude: |
(?x)^(
xonsh/ply/.+|
docs/.+
)$
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.961' # Use the sha / tag you want to point at
hooks:
- id: mypy
name: mypy xonsh
pass_filenames: false
entry: mypy xonsh
additional_dependencies:
- types-ujson
- id: mypy
name: mypy xontrib
pass_filenames: false
entry: mypy xontrib --namespace-packages --explicit-package-bases
additional_dependencies:
- types-ujson
- id: mypy
name: mypy xompletions
pass_filenames: false
entry: mypy xompletions --namespace-packages --explicit-package-bases
additional_dependencies:
- types-ujson
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.3.0
hooks:
- id: trailing-whitespace
exclude: |
(?x)^(
docs/_static/.+
)$
- id: check-case-conflict
- id: check-merge-conflict
- id: check-yaml
- id: check-toml
# Check for debugger imports and py37+ breakpoint() calls in python source.
- id: debug-statements
- id: check-added-large-files
- repo: https://github.com/asottile/pyupgrade
rev: v2.32.1
rev: v2.34.0
hooks:
- id: pyupgrade
args: [--py37-plus]
args: [--py38-plus]
exclude: |
(?x)^(
xonsh/ply/.+|
tests/bin/.+
)$

View file

@ -336,7 +336,7 @@ by executing the command::
This will generate html files for the website in the ``_build/html/`` folder.
There is also a helper utility in the ``docs/`` folder that will watch for changes and automatically rebuild the documentation. You can use this instead of running ``make html`` manually::
There is also a helper utility in the ``docs/`` folder that will watch for changes and automatically rebuild the documentation. You can use this instead of running ``make html`` manually::
$ python docs/serve_docs.py
@ -347,7 +347,7 @@ favorite browser, e.g.::
Once the developer is satisfied with the changes, the changes should be
committed and pull-requested per usual. The docs are built and deployed using
GitHub Actions.
GitHub Actions.
Docs associated with the latest release are hosted at
https://xon.sh while docs for the current ``main`` branch are available at

View file

@ -23,7 +23,7 @@ semantics are not encouraged by the built-in methods.
So how do I handle results?
===========================
``Event.fire()`` returns a list of the returns from the handlers. You should merge this list in an
``Event.fire()`` returns a list of the returns from the handlers. You should merge this list in an
appropriate way.
What are Species?
@ -34,7 +34,7 @@ behave differently.
This was done because load hooks look like events and quack like events, but they have different
semantics. See `LoadEvents <api/events.html#xonsh.events.LoadEvent>`_ for details.
In order to turn an event from the default ``Event``, you must transmogrify it, using
In order to turn an event from the default ``Event``, you must transmogrify it, using
``events.transmogrify()``. The class the event is turned in to must be a subclass of ``AbstractEvent``.
(Under the hood, transmogrify creates a new instance and copies the handlers and docstring from the

View file

@ -1,7 +1,7 @@
AppImage
========
`AppImage <https://appimage.org/>`_ is a format for distributing portable software on Linux without needing superuser permissions to install the application. It tries also to allow Linux distribution-agnostic binary software deployment for application developers, also called Upstream packaging.
`AppImage <https://appimage.org/>`_ is a format for distributing portable software on Linux without needing superuser permissions to install the application. It tries also to allow Linux distribution-agnostic binary software deployment for application developers, also called Upstream packaging.
In short the AppImage is one executable file which contains both xonsh and Python. AppImage allows xonsh to be run on any AppImage supported Linux distribution without installation or root access.
@ -36,7 +36,7 @@ The best way to build xonsh AppImage in 5 minutes is to using `python-appimage <
cd xonsh/appimage
echo 'xonsh' > requirements.txt
cat pre-requirements.txt >> requirements.txt # here you can add your additional PyPi packages to pack them into AppImage
cd ..
cd ..
pip install git+https://github.com/niess/python-appimage
python -m python_appimage build app ./appimage
./xonsh-x86_64.AppImage

View file

@ -14,22 +14,22 @@ line is ``#!/usr/bin/env xonsh``.
* - Bash
- Xonsh
- Notes
* - ``echo --arg="val"``
* - ``echo --arg="val"``
``echo {}``
``echo \;``
- ``echo --arg "val"``
``echo "{}"``
``echo ";"``
- Read `Subprocess Strings <https://xon.sh/tutorial_subproc_strings.html>`_ tutorial
to understand how strings become arguments in xonsh.
- Read `Subprocess Strings <https://xon.sh/tutorial_subproc_strings.html>`_ tutorial
to understand how strings become arguments in xonsh.
There is no notion of an escaping character in xonsh like the backslash (``\``) in bash.
Single or double quotes can be used to remove the special meaning of certain
Single or double quotes can be used to remove the special meaning of certain
characters, words or brackets.
* - ``$NAME`` or ``${NAME}``
- ``$NAME``
@ -39,7 +39,7 @@ line is ``#!/usr/bin/env xonsh``.
- Setting an environment variable. See also :ref:`$UPDATE_OS_ENVIRON <update_os_environ>`.
* - ``unset NAME``
- ``del $NAME``
- Unsetting/deleting an environment variable.
- Unsetting/deleting an environment variable.
* - ``echo "$HOME/hello"``
- ``echo "$HOME/hello"``
- Construct an argument using an environment variable.
@ -55,7 +55,7 @@ line is ``#!/usr/bin/env xonsh``.
this may be any valid expression.
* - ``ENV1=VAL1 command``
- ``$ENV1=VAL1 command``
or ``with ${...}.swap(ENV1=VAL1): command``
- Set temporary environment variable(s) and execute the command.
Use the second notation with an indented block to execute many commands in the same context.
@ -76,11 +76,11 @@ line is ``#!/usr/bin/env xonsh``.
- Print colored text as easy as possible.
* - ``shopt -s dotglob``
- ``$DOTGLOB = True``
- Globbing files with ``*`` or ``**`` will also match dotfiles, or those hidden files whose names
- Globbing files with ``*`` or ``**`` will also match dotfiles, or those hidden files whose names
begin with a literal `.`. Such files are filtered out by default like in bash.
* - ``if [ -f "$FILE" ];``
- ``p'/path/to/file'.exists()`` or ``pf'{file}'.exists()``
- Path objects can be instantiated and checked directly using p-string syntax.
- Path objects can be instantiated and checked directly using p-string syntax.
* - ``set -e``
- ``$RAISE_SUBPROC_ERROR = True``
- Cause a failure after a non-zero return code. Xonsh will raise a
@ -99,39 +99,39 @@ line is ``#!/usr/bin/env xonsh``.
- Get PID of the current shell.
* - ``$?``
- ``_.rtn``
- Returns the exit code, or status, of the previous command. The underscore ``_`` is working
in the prompt mode. To get the exit code of the command in xonsh script
- Returns the exit code, or status, of the previous command. The underscore ``_`` is working
in the prompt mode. To get the exit code of the command in xonsh script
use captured subprocess ``!().rtn``.
* - ``!$``
- ``__xonsh__.history[-1, -1]``
- Get the last argument of the last command
* - ``$<n>``
- ``$ARG<n>``
- Command line argument at index ``n``,
- Command line argument at index ``n``,
so ``$ARG1`` is the equivalent of ``$1``.
* - ``$@``
- ``$ARGS``
- List of all command line argument and parameter strings.
* - ``while getopts``
- ``import argparse``
- Start from `argparse <https://docs.python.org/3/library/argparse.html>`_ library to describe
the command line arguments in your script. Next try
`xontrib-argcomplete <https://github.com/anki-code/xontrib-argcomplete>`_ to activate
- Start from `argparse <https://docs.python.org/3/library/argparse.html>`_ library to describe
the command line arguments in your script. Next try
`xontrib-argcomplete <https://github.com/anki-code/xontrib-argcomplete>`_ to activate
tab completion for your script.
* - ``complete``
- ``completer list``
- As with many other shells, xonsh ships with the ability to complete partially-specified arguments
- As with many other shells, xonsh ships with the ability to complete partially-specified arguments
upon hitting the “tab” key.
* - OhMyBash or BashIt
- `Xontribs <https://xon.sh/xontribs.html>`_
- Xontributions, or ``xontribs``, are a set of tools and conventions for extending the functionality
- Xontributions, or ``xontribs``, are a set of tools and conventions for extending the functionality
of xonsh beyond what is provided by default.
* - Display completions as list
- ``$COMPLETIONS_DISPLAY = 'readline'``
- Display completions will emulate the behavior of readline.
* - ``docker run -it bash``
- ``docker run -it xonsh/xonsh:slim``
- Xonsh publishes a handful of containers, primarily targeting CI and automation use cases.
- Xonsh publishes a handful of containers, primarily targeting CI and automation use cases.
All of them are published on `Docker Hub <https://hub.docker.com/u/xonsh>`_.
* - ``exit 1``
- ``exit(1)``
@ -147,6 +147,6 @@ to set :ref:`$XONSH_TRACE_SUBPROC <xonsh_trace_subproc>` to ``True``:
TRACE SUBPROC: (['echo', 'hello'],)
TRACE SUBPROC: (['echo', 'hello\n', 'world'], '|', ['grep', 'hello'])
If after time you still try to type ``export``, ``unset`` or ``!!`` commands
If after time you still try to type ``export``, ``unset`` or ``!!`` commands
there are the `bashisms <https://xon.sh/xontribs.html#bashisms>`_
and `sh <https://xon.sh/xontribs.html#sh>`_ xontribs.

View file

@ -1,7 +1,7 @@
Package Manager
===============
You can install xonsh using ``conda``, ``pip`` or the package manager for
You can install xonsh using ``conda``, ``pip`` or the package manager for
your operating system distribution.
For the fullest interactive user experience, these additional packages should also be installed:
@ -10,8 +10,8 @@ For the fullest interactive user experience, these additional packages should al
:pygments: for xonsh and Python syntax-specific highlighting
:setproctitle: updates process title (in terminal window and process monitor) to match Xonsh arguments.
Installing with these packages is the recommended configuration and is documented first.
If you are operating in a specialized or restricted environment, you can install just the xonsh package, as
Installing with these packages is the recommended configuration and is documented first.
If you are operating in a specialized or restricted environment, you can install just the xonsh package, as
described in `fewer prerequisites`_
@ -23,8 +23,8 @@ described in `fewer prerequisites`_
$ conda install xonsh
**pip:** Typically you will activate a virtual environment and install xonsh there. This will ensure that you invoke the
correct Python interpreter and ``pip`` module.
**pip:** Typically you will activate a virtual environment and install xonsh there. This will ensure that you invoke the
correct Python interpreter and ``pip`` module.
.. code-block:: console
@ -38,7 +38,7 @@ This uses the pip 'extras' syntax, and is equivalent to:
The above ``pip`` commands may have to be spelled ``pip3`` or ``sudo pip3`` if you are not installing in a virtual environment.
**source:** Pip can also install the most recent xonsh source code from the
**source:** Pip can also install the most recent xonsh source code from the
`xonsh project repository <https://github.com/xonsh/xonsh>`_.
.. code-block:: console
@ -48,7 +48,7 @@ The above ``pip`` commands may have to be spelled ``pip3`` or ``sudo pip3`` if y
Spelling of ``pip`` command may likewise have to be amended as noted above.
**platform package managers**
Various operating system distributions have platform-specific package managers which may offer a xonsh package.
Various operating system distributions have platform-specific package managers which may offer a xonsh package.
This may not be the most current version of xonsh, but it should have been tested for stability on that platform
by the distribution managers.
@ -71,18 +71,18 @@ If you run into any problems, please let us know!
Fewer Prerequisites
--------------------
A design goal of Xonsh is to run in any environment that supports a (supported) Python interpreter, you
A design goal of Xonsh is to run in any environment that supports a (supported) Python interpreter, you
can install just the ``xonsh`` package (using any package manager).
.. code-block:: console
pip install xonsh
When it starts up, if xonsh does not find ``pygments`` or ``setproctitle`` packages, it simply does not colorize
or highlight syntax or set process title, respectively.
When it starts up, if xonsh does not find ``pygments`` or ``setproctitle`` packages, it simply does not colorize
or highlight syntax or set process title, respectively.
If it does not find ``prompt-toolkit`` package, it will
use the Python ``readline`` module (which reads configuration file ``.inputrc`` in a manner compatible with ``GNU readline``).
If it does not find ``prompt-toolkit`` package, it will
use the Python ``readline`` module (which reads configuration file ``.inputrc`` in a manner compatible with ``GNU readline``).
To ensure xonsh uses ``readline`` even if ``prompt-toolkit`` is installed, configure this in your
``.xonshrc`` file:

View file

@ -37,8 +37,8 @@ MacOS, OSX
readline
^^^^^^^^
[ed note: This recommendation seems to be `out of date <https://pypi.org/project/gnureadline/>`_.
It's retained in the current docs in case you have an older version of Python or macOS. But if
[ed note: This recommendation seems to be `out of date <https://pypi.org/project/gnureadline/>`_.
It's retained in the current docs in case you have an older version of Python or macOS. But if
you have Mac platform experience and can clarify, please open an issue or even a PR to correct the documentation.]
On macOS, it is *strongly* recommended to install the ``gnureadline`` library if using the readline shell. ``gnureadline`` can be installed via pip:
@ -72,8 +72,8 @@ To incorporate the whole functionality of ``/etc/profile``:
Tab completion
^^^^^^^^^^^^^^
Xonsh has support for using bash completion files on the shell, to use it you need to install
the bash-completion package.
Xonsh has support for using bash completion files on the shell, to use it you need to install
the bash-completion package.
The regular bash-completion package uses v1 which mostly works, but `occasionally has rough edges <https://github.com/xonsh/xonsh/issues/2111>`_ so we recommend using bash-completion v2.
Bash completion comes from <https://github.com/scop/bash-completion> which suggests you use a package manager to install it, this manager will also install a new version of bash without affecting /bin/bash. Xonsh also needs to be told where the bash shell file that builds the completions is, this has to be added to $BASH_COMPLETIONS. The package includes completions for many Unix commands.
@ -85,7 +85,7 @@ Common packaging systems for macOS include
.. code-block:: console
$ brew install bash-completion2
This will install the bash_completion file in `/usr/local/share/bash-completion/bash_completion` which is in the current xonsh code and so should just work.
- `MacPorts <https://trac.macports.org/wiki/howto/bash-completion>`_ where the bash-completion port needs to be installed.
@ -93,7 +93,7 @@ Common packaging systems for macOS include
.. code-block:: console
$ sudo port install bash-completion
This includes a bash_completion file that needs to be added to the environment.
@ -111,12 +111,12 @@ Windows
Windows Terminal
^^^^^^^^^^^^^^^^
If you are running a supported version of Windows (which is now Windows 10, version 2004 or later),
If you are running a supported version of Windows (which is now Windows 10, version 2004 or later),
we recommend the Windows Terminal (``wt.exe``) rather than the time-honored ``cmd.exe``. This provides
unicode rendering, better ansi terminal compatibility and all the conveniences you expect
unicode rendering, better ansi terminal compatibility and all the conveniences you expect
from the terminal application in other platforms.
You can install it from the `Microsoft Store <https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701>`_
You can install it from the `Microsoft Store <https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701>`_
or from `Github <https://github.com/microsoft/terminal>`_.
By default Windows Terminal runs Powershell, but you can add a profile tab to run Xonsh and even configure it
@ -128,7 +128,7 @@ to open automatically in xonsh. Here is a sample settings.json:
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
// To learn more about global settings, visit https://aka.ms/terminal-global-settings
// To learn more about profiles, visit https://aka.ms/terminal-profile-settings
"profiles":
@ -171,10 +171,10 @@ The dark red and blue colors are completely unreadable in `cmd.exe`.
Xonsh has some tricks to fix colors. This is controlled by the
:ref:`$INTENSIFY_COLORS_ON_WIN <intensify_colors_on_win>`
environment variable which is ``True`` by default.
environment variable which is ``True`` by default.
:ref:`$INTENSIFY_COLORS_ON_WIN <intensify_colors_on_win>` has the following effect:b
:ref:`$INTENSIFY_COLORS_ON_WIN <intensify_colors_on_win>` has the following effect:b
On Windows 10:
Windows 10 supports true color in the terminal, so on Windows 10 Xonsh will use
@ -190,14 +190,14 @@ Avoid locking the working directory
Python (like other processes on Windows) locks the current working directory so
it can't be deleted or renamed. ``cmd.exe`` has this behaviour as well, but it
is quite annoying for a shell.
is quite annoying for a shell.
The :ref:`free_cwd <free_cwd>` xontrib (add-on) for xonsh solves some of this problem. It
works by hooking the prompt to reset the current working directory to the root
drive folder whenever the shell is idle. It only works with the prompt-toolkit
back-end. To enable that behaviour run the following:
back-end. To enable that behaviour run the following:
Add this line to your ``~/.xonshrc`` file to have it always enabled.
Add this line to your ``~/.xonshrc`` file to have it always enabled.
.. code-block:: xonshcon

View file

@ -31,7 +31,7 @@ You may also set the interpreter used to create the virtual environment by passi
Under the hood, vox uses Python 3's ``venv`` module to create Python 3 virtualenvs. [this is the default]
If a Python 2 intrepreter is chosen, it will use the Python 2 interpreter's ``virtualenv`` module.
If a Python 2 intrepreter is chosen, it will use the Python 2 interpreter's ``virtualenv`` module.
By default, environments are stored in ``~/.virtualenvs``, but you can override it by setting the ``$VIRTUALENV_HOME`` environment variable.

View file

@ -20,7 +20,7 @@ Tab completion from man pages
---------------------------------
One of the more genius ideas I first encountered from ``fish`` is the idea
that man pages can be used to supply matches to tab-completion. In principle
this is not that hard. First, we just need to use ``man2html`` and then
this is not that hard. First, we just need to use ``man2html`` and then
parse the html.

View file

@ -1513,7 +1513,7 @@ detail is available on the `Tab Completion page <tutorial_completers.html>`_.
Customizing the Prompt
======================
Customizing the prompt by modifying ``$PROMPT``, ``$RIGHT_PROMPT`` or ``$BOTTOM_TOOLBAR``
Customizing the prompt by modifying ``$PROMPT``, ``$RIGHT_PROMPT`` or ``$BOTTOM_TOOLBAR``
is probably the most common reason for altering an environment variable.
.. note:: Note that the ``$PROMPT`` variable will never be inherited from a
@ -1571,7 +1571,7 @@ By default, the following variables are available for use:
* ``localtime``: The current, local time as given by ``time.localtime()``.
This is formatted with the time format string found in ``time_format``.
* ``time_format``: A time format string, defaulting to ``"%H:%M:%S"``.
* ``last_return_code``: The return code of the last issued command.
* ``last_return_code``: The return code of the last issued command.
* ``last_return_code_if_nonzero``: The return code of the last issued command if it is non-zero, otherwise ``None``. This is useful for only printing the code in case of errors.
.. note:: See the section below on ``PROMPT_FIELDS`` for more information on changing.
@ -1579,7 +1579,7 @@ By default, the following variables are available for use:
xonsh obeys the ``$VIRTUAL_ENV_DISABLE_PROMPT`` environment variable
`as defined by virtualenv <https://virtualenv.pypa.io/en/latest/reference/
#envvar-VIRTUAL_ENV_DISABLE_PROMPT>`__. If this variable is truthy, xonsh
will *always* substitute an empty string for ``{env_name}``. Note that unlike
will *always* substitute an empty string for ``{env_name}``. Note that unlike
other shells, ``$VIRTUAL_ENV_DISABLE_PROMPT`` takes effect *immediately*
after being set---it is not necessary to re-activate the environment.

View file

@ -7,7 +7,7 @@ What's the best way to keep informed in xonsh? Subscribe to an event!
Overview
========
Simply, events are a way for various pieces of xonsh to tell each other what's going on. They're
Simply, events are a way for various pieces of xonsh to tell each other what's going on. They're
fired when something of note happens, eg the current directory changes or just before a command is
executed.
@ -26,7 +26,7 @@ or several other commands)::
with open(g`~/.dirhist`[0], 'a') as dh:
print(newdir, file=dh)
The exact arguments passed and returns expected vary from event to event; see the
The exact arguments passed and returns expected vary from event to event; see the
`event list <events.html>`_ for the details.
Note that the event system is keyword only. Event handlers must match argument names and must have a
@ -50,5 +50,5 @@ Further Reading
For a complete list of available events, see `the events reference <events.html>`_.
If you want to know more about the gory details of what makes events tick, see
If you want to know more about the gory details of what makes events tick, see
`Advanced Events <advanced_events.html>`_.

View file

@ -407,7 +407,7 @@ Xonsh has a second built-in history backend powered by sqlite (other than
the JSON version mentioned all above in this tutorial). It shares the same
functionality as the JSON version in most ways, except it currently doesn't
support the ``history diff`` action and does not store the output of commands,
as the json-backend does. E.g.
as the json-backend does. E.g.
`__xonsh__.history[-1].out` will always be `None`.
The Sqlite history backend can provide a speed advantage in loading history

View file

@ -48,10 +48,10 @@ functionality (in less you take the time to rebind them elsewhere).
- ``<Tab>``
- Indent, autocomplete
* - ``Control R``
-
-
- Backwards history search
* - ``Control Z``
-
-
- SIGSTOP current job
* - ``Control C``
-
@ -72,13 +72,13 @@ Custom keyload function
We need our additional keybindings to load after the shell is initialized, so we
define a function that contains all of the custom keybindings and decorate it
with the appropriate event, in this case ``on_ptk_create``.
with the appropriate event, in this case ``on_ptk_create``.
We'll start with a toy example that just inserts the text "hi" into the current line of the prompt::
@events.on_ptk_create
def custom_keybindings(bindings, **kw):
@bindings.add(Keys.ControlW)
def say_hi(event):
event.current_buffer.insert_text('hi')

View file

@ -1,6 +1,6 @@
Run Control File
=========================
Xonsh allows you to customize your shell behavior with run control files, called "xonshrc" files.
Xonsh allows you to customize your shell behavior with run control files, called "xonshrc" files.
These files are written either in the Xonsh language (a superset of Python) or in Python and are executed
exactly once at startup.
@ -11,7 +11,7 @@ The control file usually contains:
* Xonsh function definitions
* `Alias definitions <aliases.html>`_, many of which invoke the above functions with specified arguments.
The system-wide ``xonshrc`` file controls options that are applied to all users of Xonsh on a given system.
The system-wide ``xonshrc`` file controls options that are applied to all users of Xonsh on a given system.
You can create this file in ``/etc/xonshrc`` for Linux and OSX and in ``%ALLUSERSPROFILE%\xonsh\xonshrc`` on Windows.
Xonsh also allows a per-user run control file in your home directory, either
@ -29,11 +29,11 @@ steps you through all the available options.
xonfig web
-----------
This helps you choose a color theme, customized prompt and add-in packages ("xontribs"). It
This helps you choose a color theme, customized prompt and add-in packages ("xontribs"). It
initializes your personal run control file (usually at ``~/.xonshrc``). To invoke it (from a xonsh prompt):
.. code-block:: xonshcon
>>> xonfig web
Web config started at 'http://localhost:8421'. Hit Crtl+C to stop.
127.0.0.1 - - [23/Aug/2020 15:04:39] "GET / HTTP/1.1" 200 -
@ -41,24 +41,24 @@ initializes your personal run control file (usually at ``~/.xonshrc``). To invo
This will open your default browser on a page served from a local server. You can exit the server by typing ``Ctrl+c`` at any time.
The page has:
:Colors: shows the color themes built into Xonsh.
Simply click on a sample to select it. Although color names are standardized across various terminal applications,
their actual appearance is not and do vary widely. Seeing is believing!
:Prompts: shows various sample prompts. It is recommended to select one but to then edit
:Colors: shows the color themes built into Xonsh.
Simply click on a sample to select it. Although color names are standardized across various terminal applications,
their actual appearance is not and do vary widely. Seeing is believing!
:Prompts: shows various sample prompts. It is recommended to select one but to then edit
the ``xonshrc`` file to further refine your prompt.
:Xontribs: are community-contributed add-ins often used to enhance command completion and line editing,
but can affect any aspect of Xonsh behavior.
:Xontribs: are community-contributed add-ins often used to enhance command completion and line editing,
but can affect any aspect of Xonsh behavior.
Choose one or more to suit your needs but note that they will require installation of additional
packages. You can extend Xonsh by `writing your own xontrib <tutorial_xontrib.html>`_, and are invited/urged to do so!
:Save: Click to write the configuration choices to your ``~/.xonshrc``. This will add a few tagged lines to your run control file, but will not
:Save: Click to write the configuration choices to your ``~/.xonshrc``. This will add a few tagged lines to your run control file, but will not
overwrite it completely, so you can run `xonfig web` at any time.
xonfig wizard
--------------
This imports settings and tools you have defined in your existing (ordinary) shell such as ``bash``.
It also walks you through setting all known environment variables and xontribs
This imports settings and tools you have defined in your existing (ordinary) shell such as ``bash``.
It also walks you through setting all known environment variables and xontribs
in a question-and-answer format:
.. code-block:: xonshcon
@ -214,19 +214,19 @@ The colors of the ``ls`` command may be hard to read in a dark terminal. If so,
.. code-block:: xonshcon
>>> $LS_COLORS='rs=0:di=01;36:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:'
Make JSON data directly pastable
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
With the following snippet, xonsh will understand JSON data such as ``{ "name": "Tyler", "active": false, "age": null }``.
With the following snippet, xonsh will understand JSON data such as ``{ "name": "Tyler", "active": false, "age": null }``.
Note that, though practical, this is rather hacky and might break other functionality. Use at your own risk.
.. code-block:: xonshcon
>>> import builtins
>>> import builtins
>>> builtins.true = True
>>> builtins.false = False
>>> builtins.null = None
Display different date information every 10th time
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
For a compact shell prompts, some people prefer a very condensed time format. But when you have a lengthy shell session you might want the date to show up in your logs every now and then...
@ -235,15 +235,15 @@ For a compact shell prompts, some people prefer a very condensed time format. Bu
>>> import time
>>> def get_shelldate():
>>> get_shelldate.fulldate %= 10
>>> get_shelldate.fulldate %= 10
>>> get_shelldate.fulldate += 1
>>> if get_shelldate.fulldate == 1:
>>> return time.strftime('%d%m%Y')
>>> return time.strftime('%H:%M')
>>> get_shelldate.fulldate = 0
>>>
>>>
>>> $PROMPT_FIELDS['shelldate'] = get_shelldate
Use the Nix Package manager with Xonsh
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
To users of the `Nix Package Manager <https://www.nixos.org/>`_ these few lines might be life-savers:
@ -259,16 +259,16 @@ To users of the `Nix Package Manager <https://www.nixos.org/>`_ these few lines
>>> $NIX_PATH="nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixpkgs:/nix/var/nix/profiles/per-user/root/channels"
>>> $PATH += [f"{$HOME}/.nix-profile/bin", "/nix/var/nix/profiles/default/bin"]
Btw. a hacky solution to install xontribs that do not yet ship with ``nixpkgs`` is:
Btw. a hacky solution to install xontribs that do not yet ship with ``nixpkgs`` is:
.. code-block:: xonshcon
>>> for p in map(lambda s: str(s.resolve()), p"~/.local/lib/".glob("python*/site-packages")):
>>> if p not in sys.path:
>>> sys.path.append(p)
>>>
>>>
>>> $PYTHONPATH = "$USER/.local/lib/python3.7/site-packages"
>>>
>>>
>>> python -m ensurepip --user
>>> xonsh
>>> python -m pip install --user -U pip xontrib-z xonsh-direnv

View file

@ -95,18 +95,6 @@ full = [
"setproctitle; platform_system=='Windows'",
"gnureadline; platform_system=='Darwin'",
]
format = [
"black==22.3.0",
"isort>=5.10",
]
lint = [
"xonsh[format]",
"flake8",
"flake8-docstrings",
"flake8-bugbear",
"mypy==0.941",
"types-ujson",
]
bestshell = [
"prompt_toolkit>=3.0.29",
"pygments>=2.2",
@ -128,10 +116,8 @@ test = [
"amalgamate",
]
dev = [
"xonsh[lint,test,doc]",
"xonsh[test,doc]",
"pre-commit",
"sniffer",
"pyinotify; sys_platform == \"linux\"",
"re-ver",
"tomli",
]

View file

@ -20,7 +20,7 @@ $VERSION_BUMP_PATTERNS = [
$CHANGELOG_FILENAME = 'CHANGELOG.rst'
$CHANGELOG_TEMPLATE = 'TEMPLATE.rst'
$PYTEST_COMMAND = "./run-tests.xsh -- test"
$PYTEST_COMMAND = "./run-tests.xsh test"
$TAG_REMOTE = 'git@github.com:xonsh/xonsh.git'
$TAG_TARGET = 'main'

View file

@ -60,28 +60,17 @@ def test(
![pytest @(_replace_args(pytest_args, 0)) --durations=5]
def qa():
"""QA checks"""
$XONSH_NO_AMALGAMATE = True
$XONSH_TRACE_SUBPROC_FUNC = colored_tracer
$XONSH_TRACE_SUBPROC = True
black --check xonsh xontrib tests xompletions
isort --check xonsh xontrib tests xompletions
python -m flake8
mypy xonsh
mypy xontrib --namespace-packages --explicit-package-bases
mypy xompletions --namespace-packages --explicit-package-bases
pytest -m news
def validate_news_items(
pytest_args: xcli.Arg(nargs='*') = (),
):
![pytest -m news @(pytest_args)]
if __name__ == '__main__':
parser = xcli.make_parser("test commands")
parser.add_command(test)
parser.add_command(qa)
parser.add_command(validate_news_items)
try:
xcli.dispatch(parser)

View file

@ -1,47 +0,0 @@
"""Configuration file for sniffer."""
import time
import subprocess
from sniffer.api import select_runnable, file_validator, runnable
try:
from pync import Notifier
except ImportError:
notify = None
else:
notify = Notifier.notify
watch_paths = ['.']
@select_runnable('python')
@file_validator
def py_files(filename):
return "TemplateDemo" not in filename
@runnable
def python(*_):
group = int(time.time()) # unique per run
for count, (command, title) in enumerate((
(('dmypy', 'run', "--", "xonsh"), "type-check"),
(('flake8', '.'), "Lint"),
(('xonsh', 'run-tests.xsh', 'test'), "test"),
), start=1):
print(f"\n$ {' '.join(command)}")
failure = subprocess.call(command)
if failure:
if notify and title:
mark = "" * count
notify(mark + " [FAIL] " + mark, title=title, group=group)
return False
else:
if notify and title:
mark = "" * count
notify(mark + " [PASS] " + mark, title=title, group=group)
return True

View file

@ -119,8 +119,9 @@ pretty = True
ignore_errors = True
# 3rd party libraries that we dont have control over
[mypy-zmq.*,setproctitle,xonsh.ply.*,jupyter_client.*,winreg.*,pygments.*,prompt_toolkit.*,importlib_resources.*,nt.*,prompt_toolkit.*,distro.*,conda_suggest.*,_winreg.*,*.__amalgam__.*]
[mypy-zmq.*,setproctitle,xonsh.ply.*,winreg.*,pygments.*,importlib_resources.*,nt.*,prompt_toolkit.*,distro.*,conda_suggest.*,_winreg.*,*.__amalgam__.*]
ignore_missing_imports = True
ignore_errors = True
[tool:pytest]
cache_dir = .cache/pytest

View file

@ -43,7 +43,7 @@ def _windows_bash_command(env=None):
out = subprocess.check_output(
[bash_on_path, "--version"],
stderr=subprocess.PIPE,
universal_newlines=True,
text=True,
)
except subprocess.CalledProcessError:
bash_works = False
@ -387,7 +387,7 @@ def bash_completions(
try:
out = subprocess.check_output(
[command, "-c", script],
universal_newlines=True,
text=True,
stderr=subprocess.PIPE,
env=env,
)

View file

@ -109,9 +109,7 @@ def _unc_map_temp_drive(unc_path) -> str:
for dord in range(ord("z"), ord("a"), -1):
d = chr(dord) + ":"
if not os.path.isdir(d): # find unused drive letter starting from z:
subprocess.check_output(
["NET", "USE", d, unc_share], universal_newlines=True
)
subprocess.check_output(["NET", "USE", d, unc_share], text=True)
_unc_tempDrives[d] = unc_share
return os.path.join(d, rem_path)
@ -136,9 +134,7 @@ def _unc_unmap_temp_drive(left_drive, cwd):
return
_unc_tempDrives.pop(left_drive)
subprocess.check_output(
["NET", "USE", left_drive, "/delete"], universal_newlines=True
)
subprocess.check_output(["NET", "USE", left_drive, "/delete"], text=True)
events.doc(

View file

@ -99,7 +99,7 @@ def DEFAULT_SETERRPOSTCMD():
return {"bash": "", "zsh": "", "cmd": "if errorlevel 1 exit 1"}
@functools.lru_cache()
@functools.lru_cache
def foreign_shell_data(
shell,
interactive=True,
@ -246,7 +246,7 @@ def foreign_shell_data(
# start new session to avoid hangs
# (doesn't work on Cygwin though)
start_new_session=((not ON_CYGWIN) and (not ON_MSYS)),
universal_newlines=True,
text=True,
)
except (subprocess.CalledProcessError, FileNotFoundError):
if not safe:

View file

@ -381,7 +381,7 @@ def windows_bash_command():
out = subprocess.check_output(
[bash_on_path, "--version"],
stderr=subprocess.PIPE,
universal_newlines=True,
text=True,
)
except subprocess.CalledProcessError:
bash_works = False

View file

@ -222,7 +222,7 @@ def hg_dirty_working_directory():
stderr=subprocess.PIPE,
cwd=cwd,
timeout=vcbt,
universal_newlines=True,
text=True,
env=denv,
)
return s.strip(os.linesep).endswith("+")

View file

@ -57,7 +57,7 @@ def skip_if_not_has(exe: str):
def sp(cmd):
return subprocess.check_output(cmd, universal_newlines=True)
return subprocess.check_output(cmd, text=True)
class DummyStyler:

View file

@ -867,7 +867,7 @@ def debian_command_not_found(cmd):
c = "{0} {1}; exit 0"
s = subprocess.check_output(
c.format(cnf, shlex.quote(cmd)),
universal_newlines=True,
text=True,
stderr=subprocess.STDOUT,
shell=True,
)
@ -902,7 +902,7 @@ def command_not_found(cmd, env):
return rtn
@functools.lru_cache()
@functools.lru_cache
def suggest_commands(cmd, env):
"""Suggests alternative commands given an environment and aliases."""
if not env.get("SUGGEST_COMMANDS"):

View file

@ -10,7 +10,7 @@ from xonsh.built_ins import XSH
from xonsh.xoreutils import _which
@functools.lru_cache()
@functools.lru_cache
def _which_create_parser():
desc = "Parses arguments to which wrapper"
parser = argparse.ArgumentParser("which", description=desc)

View file

@ -6,9 +6,9 @@ from xonsh.built_ins import XonshSession
def handle_sigusr1(sig, frame):
print("\nSIGUSR1 signal received. Starting interactive debugger...", flush=True)
import pdb
import pdb # noqa
pdb.Pdb().set_trace(frame)
pdb.Pdb().set_trace(frame) # noqa
def _load_xontrib_(xsh: XonshSession, **_):