refactoring: create xonsh.api, update xonsh.lib (#5557)

To have clear `./xonsh` directory with the list of components we need to
move common packages that are not components of xonsh to lib directory.
cc #5538

I see that `lib.os` and `lib.subprocess` have a bit different intention.
I think more clearer will be put them to `xonsh.api`. This is the first
step to #5383.



## 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>
This commit is contained in:
Andy Kipp 2024-06-29 11:58:11 +02:00 committed by GitHub
parent 659b404f72
commit 143042aff5
Failed to generate hash of commit
11 changed files with 18 additions and 19 deletions

View file

@ -26,6 +26,7 @@ readme = {file = ["README.rst"]}
[tool.setuptools] [tool.setuptools]
packages = [ packages = [
"xonsh", "xonsh",
"xonsh.api",
"xonsh.shells", "xonsh.shells",
"xonsh.shells.ptk_shell", "xonsh.shells.ptk_shell",
"xonsh.parsers.ply", "xonsh.parsers.ply",
@ -243,9 +244,9 @@ convention = "numpy"
"xonsh/style_tools.py" = ["F821"] "xonsh/style_tools.py" = ["F821"]
"xonsh/xoreutils/*.py" = ["E722"] "xonsh/xoreutils/*.py" = ["E722"]
"xonsh/completers/python.py" = ["E722"] "xonsh/completers/python.py" = ["E722"]
"xonsh/parsers/ast.py" = ["F401"]
"xonsh/shells/ptk_shell/__init__.py" = ["E731"] "xonsh/shells/ptk_shell/__init__.py" = ["E731"]
"xonsh/shells/readline_shell.py" = ["F401"] "xonsh/shells/readline_shell.py" = ["F401"]
"xonsh/parsers/ast.py" = ["F401"]
"xonsh/commands_cache.py" = ["F841"] "xonsh/commands_cache.py" = ["F841"]
"xonsh/shells/ptk_shell/key_bindings.py" = ["F841"] "xonsh/shells/ptk_shell/key_bindings.py" = ["F841"]
"xonsh/tools.py" = [ "xonsh/tools.py" = [

View file

@ -1,7 +1,7 @@
import os import os
import tempfile import tempfile
from xonsh.lib.os import indir, rmtree from xonsh.api.os import indir, rmtree
import pytest import pytest

View file

@ -2,8 +2,8 @@
import tempfile import tempfile
from subprocess import CalledProcessError from subprocess import CalledProcessError
from xonsh.lib.os import indir from xonsh.api.os import indir
from xonsh.lib.subprocess import run, check_call, check_output from xonsh.api.subprocess import run, check_call, check_output
import pytest import pytest

View file

@ -462,7 +462,7 @@ def _echo(args):
print(' '.join(args)) print(' '.join(args))
aliases['echo'] = _echo aliases['echo'] = _echo
from xonsh.lib.subprocess import check_output from xonsh.api.subprocess import check_output
print(check_output(["echo", "hello"]).decode("utf8")) print(check_output(["echo", "hello"]).decode("utf8"))
""", """,

8
xonsh/api/__init__.py Normal file
View file

@ -0,0 +1,8 @@
"""
Originally posted in https://github.com/xonsh/xonsh/issues/2726#issuecomment-406447196 :
Recently @CJ-Wright has started up a ``xonsh.lib`` (``xonsh.api``) sub-package, which is usable from pure Python.
This is meant as a standard library for xonsh and downstream tools.
Currently there are some xonsh-ish wrappers around ``os`` and ``subprocess``.
We'd love to see more contributions to this effort! So if there is something
like ``sh()`` that you'd like to see, by all means please help us add it!
"""

View file

@ -1,8 +1,8 @@
"""Xonsh extension of the standard library subprocess module, using xonsh for """Xonsh extension of the standard library subprocess module, using xonsh for
subprocess calls""" subprocess calls"""
from xonsh.api.os import indir
from xonsh.built_ins import XSH, subproc_captured_hiddenobject, subproc_captured_stdout from xonsh.built_ins import XSH, subproc_captured_hiddenobject, subproc_captured_stdout
from xonsh.lib.os import indir
def run(cmd, cwd=None, check=False): def run(cmd, cwd=None, check=False):

View file

@ -1,9 +1 @@
""" """Libraries of common functions that used in xonsh components as well as modules borrowed from other projects."""
Originally posted by @scopatz in https://github.com/xonsh/xonsh/issues/2726#issuecomment-406447196 :
Recently @CJ-Wright has started up a ``xonsh.lib`` sub-package, which is usable from pure Python.
This is meant as a standard library for xonsh and downstream tools.
Currently there are some xonsh-ish wrappers around ``os`` and ``subprocess``.
We'd love to see more contributions to this effort! So if there is something
like ``sh()`` that you'd like to see, by all means please help us add it!
"""

View file

@ -4,10 +4,8 @@
# pylint: disable=unused-import # pylint: disable=unused-import
import itertools import itertools
import sys import sys
# pylint: disable=unused-import
import textwrap import textwrap
from ast import ( from ast import ( # noqa # pylint: disable=unused-import
AST, AST,
Add, Add,
And, And,