2016-10-02 12:59:27 -04:00
|
|
|
#!/usr/bin/env python3
|
2015-11-16 15:06:57 -08:00
|
|
|
# Note: Do not embed any non-ASCII characters in this file until pip has been
|
2016-06-28 12:29:42 +08:00
|
|
|
# fixed. See https://github.com/xonsh/xonsh/issues/487.
|
2015-03-07 12:02:04 -06:00
|
|
|
import os
|
2016-06-26 09:46:43 -04:00
|
|
|
import subprocess
|
2022-05-10 21:09:43 +05:30
|
|
|
import sys
|
2016-02-25 17:57:29 -05:00
|
|
|
|
2022-03-23 21:18:09 +05:30
|
|
|
from setuptools import setup
|
2020-08-16 13:03:57 -05:00
|
|
|
from setuptools.command.build_py import build_py
|
2022-05-10 21:09:43 +05:30
|
|
|
from setuptools.command.develop import develop
|
|
|
|
from setuptools.command.install import install
|
2020-07-29 15:53:13 -04:00
|
|
|
from setuptools.command.install_scripts import install_scripts
|
2022-05-10 21:09:43 +05:30
|
|
|
from setuptools.command.sdist import sdist
|
|
|
|
from wheel.bdist_wheel import bdist_wheel
|
2015-03-07 12:02:04 -06:00
|
|
|
|
2018-08-30 09:17:34 -05:00
|
|
|
TABLES = [
|
|
|
|
"xonsh/lexer_table.py",
|
|
|
|
"xonsh/parser_table.py",
|
Completion context (#4017)
* completion-context: Add CompletionContextParser placeholder
Implements the xonsh (tab-)completion context parser.
This parser is meant to parse a (possibly incomplete) command line.
* completers: tools: Implement ``contextual_completer`` decorator
This is used to mark completers that want to use the parsed completion context.
* completers: Enable using contextual completers in xonsh/completer.py
* completers: readline, ptk, jupyter: Enable using contextual completers
Pass ``multiline_text`` and ``cursor_index`` to ``Completer.complete()``
* parsers: base: Refactor out a ``raise_parse_error`` function
* tokenize: Enable ``tolerant`` mode
If ``tolerant`` is True, yield ERRORTOKEN instead of
throwing an exception when encountering an error.
* lexer: Enable ``tolerant`` mode
Tokenize without extra checks (e.g. paren matching).
When True, ERRORTOKEN contains the erroneous string instead of an error msg.
* tests: lexer: Test ``tolerant`` mode
* completion-context: Implement simple CommandContext parsing
* completion-context: tests: Test simple CommandContext parsing
* completion-context: Implement parsing sub-commands
* completion-context: tests: Test parsing sub-commands
* completion-context: Add news file
* completion-context: parser: Add parser table path to relevant locations
Code-coverage, mypy ignore list, etc.
* completion-context: Implement parsing partial strings and line continuations
* completion-context: tests: Test parsing partial strings and line continuations
* completion-context: Convert ``Span`` object to a ``slice``
* completion-context: Refactor out ``create_command`` and ``cursor_in_span``
* completion-context: Implement handling empty commands
* completion-context: tests: Test handling empty commands
* completion-context: Implement handling multiple commands
Separated by newlines, `;`, `and`, `or`, `|`, `&&`, `||`
* completion-context: tests: Test handling multiple commands
Separated by newlines, `;`, `and`, `or`, `|`, `&&`, `||`
* completion-context: Implement handling python context
* completion-context: tests: Test handling python context
* completers: tools: Add `contextual_command_completer`
* completers: Make `complete_skipper` contextual
* completers: Make `complete_from_man` contextual
* completers: Make `complete_from_bash` contextual and add test
* completers: Make `complete_pip` contextual and update tests
* completers: Keep opening string quote if it exists
* completion-context: Handle cursor after a closing quote
For example - cursor at the end of ``ls "/usr/"``.
1. The closing quote will be appended to all completions.
I.e the completion ``/usr/bin`` will turn into ``/usr/bin"``
2. If not specified, lprefix will cover the closing prefix.
I.e for ``ls "/usr/"``, the default lprefix will be 6 to include the closing quote.
* completion-context: tests: Test handling cursor after a closing quote
* completion-context: Fix bug with multiple empty commands
e.g. `;;;`
* completion-context: tests: Speed up tests
From ~15 seconds to ~500 ms
* completion-context: Expand commands and subcommands
* completion-context: Simplify `commands` rules
* completion-context: Simplify `sub_expression` rules
* completion-context: Simplify editing a multi-command token
* completion-context: Inline `create_command`
* completion-context: Implement `contextual_command_completer_for` helper
* completers: Make `complete_cd`/`complete_rmdir` contextual and add tests
* completers: path: Don't append a double-backslash in a raw string
When completing a path, if a raw string is used (e.g. `r"C:\Windows\"`),
there's no reason to append a double-backslash (e.g. `r"C:\Windows\\"`).
* completers: Make `complete_xonfig`/`complete_xontrib` contextual and add tests
* completers: Make `complete_completer` contextual and add tests
* completers: Make `complete_import` contextual and add tests
* completion-context: Add python `ctx` attribute
* completion: tools: Simplify `RichCompletion` attributes handling
* completers: Make `base`, `python`, and `commands` contextual
* Add tests
* No need for `python_mode` completer anymore
* completion: tools: Add `append_space` attribute to `RichCompletion`
* completion-context: Get all lines in a main python context
* xontrib: jedi: Make the `jedi` completer contextual
* completers: tools: Remove `get_ptk_completer` and `PromptToolkitCompleter.current_document`
These aren't needed anymore now that contextual completers can access the multiline code (via `PythonContext.multiline_code`).
* completion-context: ptk: Expand aliases
* completion-context: jupyter: Expand aliases and fix line handling
* completer: Preserve custom prefix after closing quote
* completers: bash: Ensure bash completion uses the complete prefix
* completers: pip: Append a space after a pip command
* completers: pip: Prevent bad package name completions
* completers: Remove a common prefix from `RichCompletion` if `display` wasn't provided
* completion-context: Treat cursor at edge of `&& || | ;` as normal args
This will be used for completing a space
* completers: Complete end proc keywords correctly
2021-03-30 20:37:56 +03:00
|
|
|
"xonsh/completion_parser_table.py",
|
2018-08-30 09:17:34 -05:00
|
|
|
]
|
2015-03-07 13:24:44 -06:00
|
|
|
|
2015-09-30 15:26:44 +02:00
|
|
|
|
2022-05-10 21:09:43 +05:30
|
|
|
def python_tag():
|
|
|
|
ver = sys.version_info
|
|
|
|
return f"py{ver.major}{ver.minor}"
|
|
|
|
|
|
|
|
|
2015-03-07 13:24:44 -06:00
|
|
|
def clean_tables():
|
2015-11-16 15:06:57 -08:00
|
|
|
"""Remove the lexer/parser modules that are dynamically created."""
|
2015-03-07 13:24:44 -06:00
|
|
|
for f in TABLES:
|
|
|
|
if os.path.isfile(f):
|
|
|
|
os.remove(f)
|
2018-08-30 09:17:34 -05:00
|
|
|
print("Removed " + f)
|
2015-03-07 13:24:44 -06:00
|
|
|
|
2015-09-30 00:56:14 -04:00
|
|
|
|
2018-08-30 09:17:34 -05:00
|
|
|
os.environ["XONSH_DEBUG"] = "1"
|
2016-07-18 11:30:57 +02:00
|
|
|
|
2016-06-15 00:44:01 -04:00
|
|
|
|
2015-03-07 13:24:44 -06:00
|
|
|
def build_tables():
|
2015-11-16 15:06:57 -08:00
|
|
|
"""Build the lexer/parser modules."""
|
2021-01-05 20:28:02 +05:30
|
|
|
print("Building lexer and parser tables.", file=sys.stderr)
|
|
|
|
root_dir = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
sys.path.insert(0, root_dir)
|
2024-07-03 10:33:17 +02:00
|
|
|
from xonsh.parser import Parser
|
2021-07-05 20:59:44 +03:00
|
|
|
from xonsh.parsers.completion_context import CompletionContextParser
|
2018-08-30 09:17:34 -05:00
|
|
|
|
|
|
|
Parser(
|
|
|
|
yacc_table="parser_table",
|
2021-01-05 20:28:02 +05:30
|
|
|
outputdir=os.path.join(root_dir, "xonsh"),
|
2018-08-30 09:17:34 -05:00
|
|
|
yacc_debug=True,
|
|
|
|
)
|
2021-07-05 20:59:44 +03:00
|
|
|
CompletionContextParser(
|
|
|
|
yacc_table="completion_parser_table",
|
|
|
|
outputdir=os.path.join(root_dir, "xonsh"),
|
|
|
|
debug=True,
|
|
|
|
)
|
2016-07-23 20:48:34 +03:00
|
|
|
sys.path.pop(0)
|
2015-03-07 13:24:44 -06:00
|
|
|
|
2015-09-30 00:56:14 -04:00
|
|
|
|
2016-06-26 09:46:43 -04:00
|
|
|
def dirty_version():
|
|
|
|
"""
|
|
|
|
If install/sdist is run from a git directory (not a conda install), add
|
|
|
|
a devN suffix to reported version number and write a gitignored file
|
|
|
|
that holds the git hash of the current state of the repo to be queried
|
|
|
|
by ``xonfig``
|
|
|
|
"""
|
|
|
|
try:
|
2018-08-30 09:17:34 -05:00
|
|
|
_version = subprocess.check_output(["git", "describe", "--tags"])
|
2016-06-30 13:30:16 -04:00
|
|
|
except Exception:
|
2018-08-30 09:17:34 -05:00
|
|
|
print("failed to find git tags", file=sys.stderr)
|
2016-06-26 09:54:08 -04:00
|
|
|
return False
|
2018-08-30 09:17:34 -05:00
|
|
|
_version = _version.decode("ascii")
|
2016-06-26 11:45:55 -04:00
|
|
|
try:
|
2018-08-30 09:17:34 -05:00
|
|
|
_, N, sha = _version.strip().split("-")
|
2016-07-27 14:51:36 +08:00
|
|
|
except ValueError: # tag name may contain "-"
|
2018-08-30 09:17:34 -05:00
|
|
|
print("failed to parse git version", file=sys.stderr)
|
2016-06-26 11:45:55 -04:00
|
|
|
return False
|
2018-08-30 09:17:34 -05:00
|
|
|
sha = sha.strip("g")
|
2016-07-26 18:53:36 +08:00
|
|
|
replace_version(N)
|
2018-08-30 09:17:34 -05:00
|
|
|
_cmd = ["git", "show", "-s", "--format=%cd", "--date=local", sha]
|
2016-11-02 12:24:43 +08:00
|
|
|
try:
|
|
|
|
_date = subprocess.check_output(_cmd)
|
2018-08-30 09:17:34 -05:00
|
|
|
_date = _date.decode("ascii")
|
2016-11-02 12:24:43 +08:00
|
|
|
# remove weekday name for a shorter string
|
2018-08-30 09:17:34 -05:00
|
|
|
_date = " ".join(_date.split()[1:])
|
2016-11-02 12:24:43 +08:00
|
|
|
except:
|
2018-08-30 09:17:34 -05:00
|
|
|
_date = ""
|
|
|
|
print("failed to get commit date", file=sys.stderr)
|
|
|
|
with open("xonsh/dev.githash", "w") as f:
|
2021-12-07 01:12:26 +05:30
|
|
|
f.write(f"{sha}|{_date}")
|
2018-08-30 09:17:34 -05:00
|
|
|
print("wrote git version: " + sha, file=sys.stderr)
|
2016-06-26 09:54:08 -04:00
|
|
|
return True
|
|
|
|
|
2016-06-26 09:46:43 -04:00
|
|
|
|
2016-06-27 23:31:15 -04:00
|
|
|
ORIGINAL_VERSION_LINE = None
|
|
|
|
|
2016-07-18 11:30:57 +02:00
|
|
|
|
2016-07-26 18:53:36 +08:00
|
|
|
def replace_version(N):
|
2016-06-26 09:46:43 -04:00
|
|
|
"""Replace version in `__init__.py` with devN suffix"""
|
2016-06-27 23:31:15 -04:00
|
|
|
global ORIGINAL_VERSION_LINE
|
2021-12-07 01:12:26 +05:30
|
|
|
with open("xonsh/__init__.py") as f:
|
2016-06-26 09:46:43 -04:00
|
|
|
raw = f.read()
|
|
|
|
lines = raw.splitlines()
|
2018-08-30 09:17:34 -05:00
|
|
|
msg_assert = "__version__ must be the first line of the __init__.py"
|
|
|
|
assert "__version__" in lines[0], msg_assert
|
2016-06-27 23:31:15 -04:00
|
|
|
ORIGINAL_VERSION_LINE = lines[0]
|
2021-12-07 01:12:26 +05:30
|
|
|
lines[0] = lines[0].rstrip(' "') + f'.dev{N}"'
|
2018-08-30 09:17:34 -05:00
|
|
|
upd = "\n".join(lines) + "\n"
|
|
|
|
with open("xonsh/__init__.py", "w") as f:
|
2016-06-26 09:46:43 -04:00
|
|
|
f.write(upd)
|
|
|
|
|
|
|
|
|
2016-06-27 23:31:15 -04:00
|
|
|
def restore_version():
|
|
|
|
"""If we touch the version in __init__.py discard changes after install."""
|
2016-07-26 18:53:36 +08:00
|
|
|
if ORIGINAL_VERSION_LINE is None:
|
|
|
|
return
|
2021-12-07 01:12:26 +05:30
|
|
|
with open("xonsh/__init__.py") as f:
|
2016-06-27 23:31:15 -04:00
|
|
|
raw = f.read()
|
|
|
|
lines = raw.splitlines()
|
|
|
|
lines[0] = ORIGINAL_VERSION_LINE
|
2018-08-30 09:17:34 -05:00
|
|
|
upd = "\n".join(lines) + "\n"
|
|
|
|
with open("xonsh/__init__.py", "w") as f:
|
2016-06-27 23:31:15 -04:00
|
|
|
f.write(upd)
|
2016-06-26 09:54:08 -04:00
|
|
|
|
|
|
|
|
2020-08-16 13:03:57 -05:00
|
|
|
class xbuild_py(build_py):
|
|
|
|
"""Xonsh specialization of setuptools build_py class."""
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
clean_tables()
|
|
|
|
build_tables()
|
|
|
|
# add dirty version number
|
|
|
|
dirty = dirty_version()
|
|
|
|
super().run()
|
|
|
|
if dirty:
|
|
|
|
restore_version()
|
|
|
|
|
|
|
|
|
2022-05-10 21:09:43 +05:30
|
|
|
class xbdist(bdist_wheel):
|
|
|
|
def initialize_options(self):
|
|
|
|
super().initialize_options()
|
2022-07-23 09:12:46 +10:00
|
|
|
# because XonshParser will be build for each minor python version, we need separate builds
|
2022-05-10 21:09:43 +05:30
|
|
|
self.python_tag = python_tag()
|
|
|
|
|
|
|
|
|
2015-03-09 22:42:34 -05:00
|
|
|
class xinstall(install):
|
2020-08-11 12:25:17 -04:00
|
|
|
"""Xonsh specialization of setuptools install class.
|
2020-08-16 13:03:57 -05:00
|
|
|
For production, let setuptools generate the
|
2020-08-11 12:25:17 -04:00
|
|
|
startup script, e.g: `pip installl .' rather than
|
|
|
|
relying on 'python setup.py install'."""
|
2018-08-30 09:17:34 -05:00
|
|
|
|
2015-03-09 22:42:34 -05:00
|
|
|
def run(self):
|
|
|
|
clean_tables()
|
2016-07-23 20:48:34 +03:00
|
|
|
build_tables()
|
2016-06-26 09:46:43 -04:00
|
|
|
# add dirty version number
|
2016-06-26 09:54:08 -04:00
|
|
|
dirty = dirty_version()
|
2020-08-16 13:03:57 -05:00
|
|
|
|
2016-07-29 17:49:06 +02:00
|
|
|
super().run()
|
2016-06-26 09:54:08 -04:00
|
|
|
if dirty:
|
2016-06-27 23:31:15 -04:00
|
|
|
restore_version()
|
2016-06-26 09:54:08 -04:00
|
|
|
|
2015-03-09 22:42:34 -05:00
|
|
|
|
|
|
|
class xsdist(sdist):
|
2015-11-16 15:06:57 -08:00
|
|
|
"""Xonsh specialization of setuptools sdist class."""
|
2018-08-30 09:17:34 -05:00
|
|
|
|
2015-03-09 22:42:34 -05:00
|
|
|
def make_release_tree(self, basedir, files):
|
|
|
|
clean_tables()
|
2016-07-23 20:48:34 +03:00
|
|
|
build_tables()
|
2016-06-26 09:54:08 -04:00
|
|
|
dirty = dirty_version()
|
2020-08-16 13:03:57 -05:00
|
|
|
files.extend(TABLES)
|
2016-07-29 17:49:06 +02:00
|
|
|
super().make_release_tree(basedir, files)
|
2016-06-26 09:54:08 -04:00
|
|
|
if dirty:
|
2016-06-27 23:31:15 -04:00
|
|
|
restore_version()
|
2015-09-30 00:56:14 -04:00
|
|
|
|
2016-06-26 09:46:43 -04:00
|
|
|
|
2016-05-13 22:13:09 +01:00
|
|
|
# Hack to overcome pip/setuptools problem on Win 10. See:
|
|
|
|
# https://github.com/tomduck/pandoc-eqnos/issues/6
|
|
|
|
# https://github.com/pypa/pip/issues/2783
|
|
|
|
|
|
|
|
# Custom install_scripts command class for setup()
|
|
|
|
class install_scripts_quoted_shebang(install_scripts):
|
|
|
|
"""Ensure there are quotes around shebang paths with spaces."""
|
2018-08-30 09:17:34 -05:00
|
|
|
|
2016-05-13 22:13:09 +01:00
|
|
|
def write_script(self, script_name, contents, mode="t", *ignored):
|
|
|
|
shebang = str(contents.splitlines()[0])
|
2018-08-30 09:17:34 -05:00
|
|
|
if (
|
|
|
|
shebang.startswith("#!")
|
|
|
|
and " " in shebang[2:].strip()
|
|
|
|
and '"' not in shebang
|
|
|
|
):
|
2016-05-13 22:13:09 +01:00
|
|
|
quoted_shebang = '#!"%s"' % shebang[2:].strip()
|
|
|
|
contents = contents.replace(shebang, quoted_shebang)
|
|
|
|
super().write_script(script_name, contents, mode, *ignored)
|
|
|
|
|
2016-07-29 17:49:06 +02:00
|
|
|
|
|
|
|
class install_scripts_rewrite(install_scripts):
|
2016-07-30 20:38:18 +02:00
|
|
|
"""Change default python3 to the concrete python binary used to install/develop inside xon.sh script"""
|
2018-08-30 09:17:34 -05:00
|
|
|
|
2016-07-29 17:49:06 +02:00
|
|
|
def run(self):
|
|
|
|
super().run()
|
2016-07-30 20:38:18 +02:00
|
|
|
if not self.dry_run:
|
2016-07-29 17:49:06 +02:00
|
|
|
for file in self.get_outputs():
|
2018-08-30 09:17:34 -05:00
|
|
|
if file.endswith("xon.sh"):
|
2016-07-30 20:38:18 +02:00
|
|
|
# this is the value distutils use on its shebang translation
|
2018-08-30 09:17:34 -05:00
|
|
|
bs_cmd = self.get_finalized_command("build_scripts")
|
|
|
|
exec_param = getattr(bs_cmd, "executable", None)
|
2016-07-29 17:49:06 +02:00
|
|
|
|
2021-12-07 01:12:26 +05:30
|
|
|
with open(file) as f:
|
2016-07-29 17:49:06 +02:00
|
|
|
content = f.read()
|
|
|
|
|
2021-12-07 01:12:26 +05:30
|
|
|
processed = content.replace(" python3 ", f' "{exec_param}" ')
|
2016-07-29 17:49:06 +02:00
|
|
|
|
2018-08-30 09:17:34 -05:00
|
|
|
with open(file, "w") as f:
|
2016-07-29 17:49:06 +02:00
|
|
|
f.write(processed)
|
|
|
|
|
2018-08-30 09:17:34 -05:00
|
|
|
|
2020-07-29 15:53:13 -04:00
|
|
|
class xdevelop(develop):
|
|
|
|
"""Xonsh specialization of setuptools develop class."""
|
2018-08-30 09:17:34 -05:00
|
|
|
|
2020-07-29 15:53:13 -04:00
|
|
|
def run(self):
|
|
|
|
clean_tables()
|
|
|
|
build_tables()
|
|
|
|
dirty = dirty_version()
|
|
|
|
develop.run(self)
|
|
|
|
if dirty:
|
|
|
|
restore_version()
|
2015-04-06 23:21:03 -05:00
|
|
|
|
2020-07-29 15:53:13 -04:00
|
|
|
def install_script(self, dist, script_name, script_text, dev_path=None):
|
|
|
|
if script_name == "xon.sh":
|
|
|
|
# change default python3 to the concrete python binary used to install/develop inside xon.sh script
|
2021-12-07 01:12:26 +05:30
|
|
|
script_text = script_text.replace(" python3 ", f' "{sys.executable}" ')
|
2020-07-29 15:53:13 -04:00
|
|
|
super().install_script(dist, script_name, script_text, dev_path)
|
2016-07-29 17:49:06 +02:00
|
|
|
|
2015-04-06 23:21:03 -05:00
|
|
|
|
2022-05-10 21:09:43 +05:30
|
|
|
# The custom install needs to be used on Windows machines
|
|
|
|
cmdclass = {
|
|
|
|
"install": xinstall,
|
|
|
|
"sdist": xsdist,
|
|
|
|
"build_py": xbuild_py,
|
|
|
|
"develop": xdevelop,
|
|
|
|
"bdist_wheel": xbdist,
|
|
|
|
}
|
|
|
|
if os.name == "nt":
|
|
|
|
cmdclass["install_scripts"] = install_scripts_quoted_shebang
|
|
|
|
else:
|
|
|
|
cmdclass["install_scripts"] = install_scripts_rewrite
|
|
|
|
|
|
|
|
|
2015-03-07 12:02:04 -06:00
|
|
|
def main():
|
2015-11-16 15:06:57 -08:00
|
|
|
"""The main entry point."""
|
2015-03-23 01:40:44 -05:00
|
|
|
try:
|
2018-08-30 09:17:34 -05:00
|
|
|
if "--name" not in sys.argv:
|
|
|
|
logo_fname = os.path.join(os.path.dirname(__file__), "logo.txt")
|
|
|
|
with open(logo_fname, "rb") as f:
|
|
|
|
logo = f.read().decode("utf-8")
|
2015-08-07 22:39:22 +02:00
|
|
|
print(logo)
|
2015-03-23 01:40:44 -05:00
|
|
|
except UnicodeEncodeError:
|
|
|
|
pass
|
2022-05-10 21:09:43 +05:30
|
|
|
setup(
|
2016-06-16 10:35:26 -04:00
|
|
|
cmdclass=cmdclass,
|
2018-08-30 09:17:34 -05:00
|
|
|
)
|
2015-03-07 12:02:04 -06:00
|
|
|
|
2015-03-07 17:32:13 -06:00
|
|
|
|
2018-08-30 09:17:34 -05:00
|
|
|
if __name__ == "__main__":
|
2015-03-07 12:02:04 -06:00
|
|
|
main()
|