feat: add xontrib-django

This commit is contained in:
Noortheen Raja 2022-04-09 10:31:20 +05:30 committed by Noorhteen Raja NJ
parent 18d655e16f
commit 1476f1adaa
4 changed files with 37 additions and 19 deletions

23
news/xontrib-django.rst Normal file
View file

@ -0,0 +1,23 @@
**Added:**
* new `xontrib-django <https://github.com/jnoortheen/xontrib-django>`_ for django management completions
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* <news item>
**Security:**
* <news item>

View file

@ -1,15 +0,0 @@
"""Completers for pip."""
from xonsh.completers.tools import comp_based_completer
from xonsh.parsers.completion_context import CommandContext
def xonsh_complete(ctx: CommandContext):
"""Completes python's package manager pip."""
# adapted from https://github.com/django/django/blob/main/extras/django_bash_completion
# todo: find a way to get description for the completions like here
# 1. https://github.com/apie/fish-django-completions/blob/master/fish_django_completions.py
# 2. complete python manage.py invocations
# https://github.com/django/django/blob/main/extras/django_bash_completion
return comp_based_completer(ctx, DJANGO_AUTO_COMPLETE="1")

View file

@ -281,7 +281,7 @@ def complete_from_sub_proc(*args: str, sep=None, filter_prefix=None, **env_vars:
yield comp
def comp_based_completer(ctx: CommandContext, **env: str):
def comp_based_completer(ctx: CommandContext, start_index=0, **env: str):
"""Helper function to complete commands such as ``pip``,``django-admin``,... that use bash's ``complete``"""
prefix = ctx.prefix
@ -290,9 +290,9 @@ def comp_based_completer(ctx: CommandContext, **env: str):
args.append(prefix)
yield from complete_from_sub_proc(
args[0],
*args[: start_index + 1],
sep=shlex.split,
COMP_WORDS=os.linesep.join(args) + os.linesep,
COMP_CWORD=str(ctx.arg_index),
COMP_WORDS=os.linesep.join(args[start_index:]) + os.linesep,
COMP_CWORD=str(ctx.arg_index - start_index),
**env,
)

View file

@ -304,6 +304,16 @@ def define_xontribs():
"distributed",
"The distributed parallel computing library hooks for xonsh.",
),
"django": Xontrib(
url="https://github.com/jnoortheen/xontrib-django",
description="Django management command completions for Xonsh shell",
package=_XontribPkg(
name="xontrib-django",
license="MIT",
install={"pip": "xpip install xontrib-django"},
url="https://github.com/jnoortheen/xontrib-django",
),
),
"jupyter": get_xontrib(
"jupyter-shell",
"Jupyter Notebook kernel for Xonsh",