Skip to content

Commit

Permalink
Add package setup (#67)
Browse files Browse the repository at this point in the history
* implement setup

* fix document path

* use setup in action

* use action path to run setup

* add missing dependency

* update README

* update version

* use pyproject toml instead of a setup script

* add entrypoint

* add workflow

* test publish workflow

* publish on releases

* update metadata

* delete obsolete files
  • Loading branch information
betogaona7 authored Oct 4, 2023
1 parent 8839046 commit bc443b1
Show file tree
Hide file tree
Showing 8 changed files with 1,532 additions and 23 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Publish

on:
workflow_dispatch: # Allow running on-demand
push:
tags:
- "*"

env:
PYTHON_VERSION: 3.11.4

jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Code checkout
uses: actions/checkout@v3

- name: Setup python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip poetry
poetry install
- name: Set Poetry config
run: poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }}

- name: Publish package
run: poetry publish --build
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Mystral AI

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 7 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,10 @@ https://github.com/mystral-ai/devtale/assets/11546115/e3cb1354-d9ef-406f-90d7-e9

## Installation

Create and enter to a conda env:
Use the following command:

```bash
conda create -n devtale python=3.11 -y
conda activate devtale
```

Install requirements

```bash
pip install -r requirements.txt
pip install devtale
```

## Usage
Expand All @@ -34,7 +27,7 @@ pip install -r requirements.txt
- Run the following command to document a file or document all the files in a folder:

```bash
python cli.py -p [path/to/your/code] -o [path/to/docs]
devtale -p [path/to/your/code] -o [path/to/docs]
```

To document an entire repository/directory include the `-r` (recursive) flag. The program generates a JSON file per code file with the documentation data; If you want to also add the documentation inside a copy of the code file, then please include the `-f` (fuse) flag. In case you already have the JSON docstrings, you can also fuse them separately using the corresponding [script](scripts/)
Expand All @@ -54,7 +47,7 @@ jobs:
permissions: write-all
steps:
- name: Document
uses: mystral-ai/devtale@v0.1.1
uses: mystral-ai/devtale@v0.1.2
with:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
path: ${{ github.workspace }}
Expand All @@ -67,7 +60,7 @@ The `recursive` option allows you to document the entire repository. Alternative

## Cost

You can estimate project documentation costs using the `--estimate` flag with the `devtale` command, which won't make any GPT calls. Please note that this estimate is approximate, as it doesn't include GPT output tokens nor code items JSON tokens generated by the GPT call in the `devtale/utils.py/extract_code_elements` function.
You can estimate project documentation costs using the `--estimate` flag when using the `devtale` command in terminal, which won't make any GPT calls. Please note that this estimate is approximate, as it doesn't include GPT output tokens nor code items JSON tokens generated by the GPT call in the `devtale/utils.py/extract_code_elements` function.

If you skip the estimate and simply run 'devtale,' the final log will display the total cost. This total cost considers GPT output tokens and the tokens added by the code items JSON.

Expand All @@ -76,13 +69,13 @@ For example:
Running the following command:

```bash
python cli.py -r -f -p devtale/devtale --estimate
devtale -r -f -p devtale/devtale --estimate
```

will provide you with a cost estimate of $2.44733 USD. It won't document anything since it doesn't trigger any GPT calls. On the other hand, running:

```bash
python cli.py -r -f -p devtale/devtale
devtale -r -f -p devtale/devtale
```

will give you the total cost of $2.95762 USD. This command triggers GPT calls and, consequently, documents the directory.
Expand Down
6 changes: 3 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ runs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r ${{ github.action_path }}/requirements.txt
pip install devtale
shell: bash

- name: Document
run: |
if ${{ inputs.recursive }}; then
echo "Documenting repository"
python ${{ github.action_path }}/cli.py -r -p ${{ inputs.path }} -o ${{ inputs.path }} -f
devtale -r -p ${{ inputs.path }} -o ${{ inputs.path }} -f
else
echo "Documenting folder/path"
python ${{ github.action_path }}/cli.py -p ${{ inputs.path }} -o ${{ inputs.path }} -f
devtale -p ${{ inputs.path }} -o ${{ inputs.path }} -f
fi
env:
OPENAI_API_KEY: ${{ inputs.openai_api_key }}
Expand Down
4 changes: 2 additions & 2 deletions cli.py → devtale/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os

import click
from dotenv import load_dotenv
from dotenv import find_dotenv, load_dotenv

from devtale.constants import (
ALLOWED_EXTENSIONS,
Expand Down Expand Up @@ -546,7 +546,7 @@ def main(
debug: bool = False,
cost_estimation: bool = False,
):
load_dotenv()
load_dotenv(find_dotenv(usecwd=True))

if not os.environ.get("OPENAI_API_KEY"):
os.environ["OPENAI_API_KEY"] = getpass.getpass(
Expand Down
Loading

0 comments on commit bc443b1

Please sign in to comment.