Skip to main content
Markata

Lockhart

PyPI - Version PyPI - Python Version


Table of Contents

Installation

pip install lockhart
## or with pipx
pipx install lockhart

Instructions

You will need an openai key, you can obtain one from their website. Once you have it then set your OPENAI_API_KEY environment variable.

export OPENAI_API_KEY='sk-***'

Lockhart it currently very crude, it works out of the clipboard. Copy a function to your clipboard, run lockhart docstring then paste the docstring in.

lockhart tui

lockhart tui

https://user-images.githubusercontent.com/22648375/217840817-04626da4-8558-4fc4-8b05-ff0e57a2a28b.mp4

keys

  • C - Create new code
  • e - edit return value from history item
  • E - open an empty edit template
  • o - open the current prompt from history
  • j - next item from history
  • k - prev item from history
  • q - quit
  • d - toggle dark mode
  • b - toggle sidebar of preset prompts
  • G - open an empty prompt for writing a git commit

Editing prompts

Currently the tui runs the users configured $EDITOR in a subprocess, waits for the editor to close, and if the file was changed then it runs the prompt. If the file was not changed then it does not run the prompt.

## mac/linux
export EDITOR=vim
 
## windows
set EDITOR=notepad

closing vim

:x without a change to the content will not trigger a file change and the prompt will not run. If you want to use the prompt as-is without edit close vim with :wq.

CLI

lockhart prompt run

You can also run stored prompts from the command line without the tui.

## pipe text into your prompt
echo 'write a python3.10 hello world function' | lockhart prompt run code-create

## use the --text flag
lockhart prompt run code-create --text 'write a python3.10 hello world function' 

## directly edit your prompt with the editor
lockhart prompt run code-create --edit

The cli also handles text being piped into a prompt run. You can still --edit it, or pipe the results somewhere. Many of the commit messages in this repo were created using this.

## pre-populate your commit message
git diff --staged | lockhart prompt run commit | git commit -evF -

## write a changelog entry for your current pr
gh pr diff | lockhart prompt run changelog --edit

## write a changelog entry for your current staged changes
git diff --staged | lockhart prompt run changelog --edit

listing prompts

The cli can list all of the prompts configured in ~/.config/lockhart/lockhart.toml using the cli.

lockhart prompt list

lockhart history

The cli can output your entire history as json.

lockhart history list

Original features that need re-implemented

These shouldn't be too bad to get re-implemented, but I think we need a pre-processor to be able to get this working.

Docstring Examples

def add(a, b):
    """

    Add two numbers together.

    Args:
        a (int): The first number to add.
        b (int): The second number to add.

    Returns:
        int: The sum of the two numbers.

    Example:
        add(2, 3) -> 5

    """
    return a + b

Without even type hinting the arguments lockhart can see that this function is using pandas.

def get_summary_data(df):
    """
    This function takes a dataframe as an argument and returns a summary of the data grouped by column A.

    Args:
        df (DataFrame): The dataframe to be summarized.

    Returns:
        DataFrame: A summary of the data grouped by column A, containing the sum of columns C and D.

    Example:
        df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9], 'D': [10, 11, 12]})
        get_summary_data(df)
    """
    df.groupby("A")[["C", "D"]].sum()

Here is an example from the fastapi docs. It writes a correct docstring to describe the function, but misses out that its a fastapi route without more context than just the function.

@app.put("/items/{item_id}")
def update_item(item_id: int, item: Item):
    """
    Update an item in the database.

    This function takes an item_id and an item object as parameters and updates the item in the database.

    Args:
        item_id (int): The id of the item to be updated.
        item (Item): The item object to be updated.

    Returns:
        dict: A dictionary containing the item_id and the updated item.

    Example:
        results = update_item(1, {'name': 'Foo', 'price': 10.99})
    """
    results = {"item_id": item_id, "item": item}
    return results

Examples Refactor

def add(a, b):
    return a + b

# refactor the following code to compute the ratio of the two numbers

def ratio(a, b):
    return a / b
# Before
def get_summary_data(df):
    df.groupby("A")[["C", "D"]].sum()

# refactor the following code to also return the averages

# After
def get_summary_data(df):
    df.groupby("A")[["C", "D"]].agg(["sum", "mean"])

Run lockhart refactor, then set the prompt to refactor the following code to accept a parameter item_name. It did a great job at adding it to the arguments list, type hinting it to a string, but again missed that this is a fastapi route and we wanted to also update the decorator.

``` python
# before
@app.put("/items/{item_id}")
def update_item(item_id: int, item: Item):
    results = {"item_id": item_id, "item": item}
    return results

# refactor the following code to accept a parameter item_name

# after
@app.put("/items/{item_id}")
def update_item(item_id: int, item_name: str, item: Item):
    results = {"item_id": item_id, "item_name": item_name, "item": item}
    return results

License

lockhart is distributed under the terms of the MIT license.

Metadata

Release files for lockhart 0.6.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lockhart 0.6.2
File Size Uploaded Provenance Actions
lockhart-0.6.2.tar.gz 20.8 kB Without provenance Details for lockhart-0.6.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lockhart 0.6.2
File Interpreter ABI Platform Actions
lockhart-0.6.2-py3-none-any.whl Python 3 none any Details for lockhart-0.6.2-py3-none-any.whl

Total release size: 36.4 kB

Release files / lockhart-0.6.2.tar.gz

Download URL lockhart-0.6.2.tar.gz
Size 20.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e4a5159907a1daa7181cec6dfeacaaf99a5f294122507ae2d53e30c58470f495
BLAKE2b-256 checksum
How to use checksums
410526d4cad9b717d2795bd7f35839b7b22cdd5161c135ad5aaf6a6458b236ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.23.3

Release files / lockhart-0.6.2-py3-none-any.whl

Download URL lockhart-0.6.2-py3-none-any.whl
Size 15.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a13f5cf73e561f631eb7c73b9ad7ab6840e71d9f4591e4a6d4de2f47ff3601c
BLAKE2b-256 checksum
How to use checksums
6dec42153242774641850c873c47c68fb9d82f52257ad879aaf8820a9e235ef8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.23.3

Security for lockhart 0.6.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.6.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page