Giter Club home page Giter Club logo

xontrib-template's Introduction

A template for creating the xonsh contributions called xontribs.

If you like the template click ⭐ on the repo.

asciicast

Why use this template?

This template includes good pack of prebuilt files:

  • README with the info and xontrib promotion instructions
  • PEP 621 or poetry based pyproject.toml file to make and install PyPi package easily
  • .gitattributes file to enable Github syntax highlighting for *.xsh files
  • .gitignore file with standard list of directories to ignore
  • .github/workflow/push-test.yml to automatically test the code using Github Actions
  • .github/*_template.md files to create Github templates for the text of issue and PR.
  • .github/FUNDING.yml file with template for Github sponsorship button.
  • .pre-commit-config.yaml file with pre-commit-hooks
  • MANIFEST.in file to make Conda feedstock easily
  • LICENSE file with standard MIT license
  • tests/ with the test suite

Create new xontrib

Install copier:

xpip install copier jinja2-time cookiecutter

# OR using pipx (https://pypa.github.io/pipx/):
pipx install copier>=9
pipx inject copier copier-templates-extensions

Create your new xontrib:

copier copy --trust gh:xonsh/xontrib-template .

Advent of PEP-621

Older projects can use the following tools to upgrade their setup to use pyproject.toml

If you have an idea for xontrib but have no time to implement

Development

  • copier selects the latest tag when --vcs-ref option is not given. So it is important to tag the main branch after important template updates.

How to fix pre-commit-hooks

If you're using .pre-commit-config.yaml and have an error during testing you need fix the code i.e.:

xpip install pre-commit-hooks
pre-commit run --all-files black  # or isort, etc

Links

xontrib-template's People

Contributors

anki-code avatar astraluma avatar drmikecrowe avatar eugenesvk avatar jnoortheen avatar mattmc3 avatar pre-commit-ci[bot] avatar scopatz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

xontrib-template's Issues

Idea: Completer with the list of last edited/created files

Hello! I have an idea!

Example 1:

# Create file `1.txt` somewhere using GUI text editor
cd /tmp
echo "hello" > 1.txt
vim # Press key shortcut to get completer list
vim /path/to/somewhere/1.txt

Example 2:

cd /tmp
echo "hello" > 1
echo "world" > 2
#cat <Tab>
# 2
# 1
cat 2
# world 

Example of the xontrib name: xontrib-completer-last-file.

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

Copier is not working

Hey @jnoortheen !

I tried to run copier to create xontrib but got an error. It looks that current instructions is not working.

docker run -it --rm -v $PWD:/ddd python:3.9-alpine sh
pip install copier jinja2-time cookiecutter
copier gh:xonsh/xontrib-template .
# Unknown sub-command 'gh:xonsh/xontrib-template'

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

Idea: json/yaml/toml format definitions for easier completions

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

Example of an autoloaded xontrib with this template with working poetry tests

upd: This seems to be another issue with autoloading, the tests simply fail with xontrib_x folder structure this template creates by default, they can only load from xontrib/x.py due to some hardcoded names in the load_xontrib function and maybe other reasons

I've decided to check why the CI from this template was failing despite the installation of xontribs working fine and discovered that running poetry run pytest fails with tests/test_xontrib.py::test_it_loads - Exception: Failed to load xontrib: The following xontribs are enabled but not installed:['cd']

Strangely enough, when I load xonsh directly from the pytest path with ~/Library/Caches/pypoetry/virtualenvs/xontrib-cd--vcGhuku-py3.11/bin/xonsh --no-rc (from a non-xonsh shell to avoid any environment contamination) I can load it just fine

from xonsh.xontribs import xontribs_load
xontribs_load(['cd'])
# (None, None, <ExitCode.OK: 0>)

So I don't understand what's going on

Do you maybe have an example of a xontrib that uses this template and also has working tests? I've looked through a bunch of awesome xontrib list, but they either don't use the template, or don't use poetry.
Or maybe you know what's wrong

Idea: xontrib-ask - command template with interactive sections

Hello! I have an idea!

The ability to create command template. Before executing the command the placeholders should be filled interactively.

First step - Ask to input argument and with autocomplete:

echo I am saying @(ask('What to say'))
# What to say: hello
# I am saying hello

echo Give @(ask('Fruit', ['apple', 'banana', 'orange'])) to @(ask('To', [$(whoami).strip()]))
# Fruit: <Tab>
# Fruit: apple
# To: <Tab>
# To: user
# Give apple to user

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

Template XONTRIBS_AUTOLOAD_DISABLED conflict with other xontribs and type conflicts

The template suggests disabling autoloading via
$XONTRIBS_AUTOLOAD_DISABLED = {"ptk_shell", }

There are a few of issues with this:

  • It would override the same variable set by other xontribs instead of appending
  • From the docs, the type of XONTRIBS_AUTOLOAD_DISABLED could either by a bool or a list, but you use a set, so actually appending this variable becomes a challenge due to a difference in updating lists and sets

Idea: fish-like CD to previous/next dir in history with keybinds and "inline" prompt updates

Fish has this very nice trick of a functionality that allows you to CD to previous/next dir in history with / WITHOUT creating any new prompts, so the existing prompt just gets updated in the background

In xonsh it's also possible to update the exising prompts, see the gist below for a sample xontrib that CDs up one folder on ⎈z and updates all 3 prompts (if they exist) "inline", i.e., without generating a new line like the carriage return workaround does

https://gist.github.com/eugenesvk/fb8078d7388fc4d722f2c4b88f63cda1

This xontrib would rely on this, but add env vars to allow changing keybinds and use os-relevant defaults (I think temrinals on Macs map / to Send ^[ [1;5H Send ^[ [1;5F)

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

Idea: xontrib-codex - use OpenAI Codex to translate natural language to code

We’ve created an improved version of OpenAI Codex, our AI system that translates natural language to code, and we are releasing it through our API in private beta starting today.

The example of code for catching key press and add text:

from prompt_toolkit import prompt
from prompt_toolkit.key_binding import KeyBindings

# Define key bindings to replace text on space key press
kb = KeyBindings()
@kb.add(' ')
def _(event):
    event.current_buffer.text = event.current_buffer.text + ' space :)'
    event.current_buffer.cursor_position += len(event.current_buffer.text)  # move coursor to the end

# Start a prompt session with key bindings
text = prompt('> ', key_bindings=kb)
print('You entered:', text)

Draft 1:

import openai

openai.api_key = "YOUR_API_KEY_HERE"  # https://platform.openai.com/account/api-keys

# Example prompt
prompt = "I love Python because"

# Example completion using the GPT-3 model
response = openai.Completion.create(
    engine="davinci", prompt=prompt, max_tokens=50
)

# Print the response
print(response.choices[0].text)

Draft 2:

import os
import requests
import json
import time

from prompt_toolkit.keys import Keys

$OPENAI_API_KEY = '...' # https://platform.openai.com/account/api-keys

@events.on_ptk_create
def custom_keybindings(bindings, **kw):
    @bindings.add('c-k')  # control+k
    def run(event):
        input = event.current_buffer.text
        print('\n# ...')
        
        headers = {
            'Content-Type': 'application/json',
            'Authorization': 'Bearer ' + __xonsh__.env.get('OPENAI_API_KEY'),
        }

        json_data = {
            'model': __xonsh__.env.get('OPENAI_MODEL', 'text-davinci-003'),
            'max_tokens': __xonsh__.env.get('OPENAI_MAX_TOKENS', 1000),
            'temperature': __xonsh__.env.get('OPENAI_TEMPERATURE', 0),
            'prompt': input,            
        }

        output_delay = __xonsh__.env.get('OPENAI_OUTPUT_DELAY', 0.01)
        
        try:
            response = requests.post('https://api.openai.com/v1/completions', headers=headers, json=json_data)     
        except Exception as e:
            print(f'\n# Error request: {str(e)}')
            return        
        
        if response.status_code != 200:
            print(f'\n# Error response: {response.status_code}')
            return
        
        try:
            j = response.json()
        except Exception as e:
            print(f'\n# Error response: {response}')
            print(f'\n# Error exception: {str(e)}')
            return
        
        output = j['choices'][0]['text']
        for w in output.split(' '):
            event.current_buffer.insert_text(w + ' ')
            event.current_buffer.validate()
            time.sleep(output_delay)
            
# git commit <control+k> 

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

Idea: `%autoreload` like functionality for rapid prototyping

Thanks for the fantastic work.

It's very likely that I'm just not good enough in searching issues here/missing the correct keywords so apologies if that's the case in advance.

The one feature that keeps me from switching to xonsh from ipython is the availability of a %autoreload like functionality when using it as a REPL when developing, that recursively imports the modules and its dependencies.

Is there such a function available/in planning?

Thanks!

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.