Skip to main content

An automatic commenter for Python code, with optional added translations.

Project description

Commentaire

Commentaire is a Python program that generates comments and optional translations for Python code. It uses OpenAI's GPT-3 language model to add high-level explanatory comments and docstrings to Python code.

Usage

To use Commentaire, you must first set up an OpenAI API key. If you already have an API key, you can set it as an environment variable called OPENAI_API_KEY. Otherwise, you can pass your API key as an argument to the commentaire command. (If you do not have one yet, you can get a key here: https://openai.com/api/.)

$ export OPENAI_API_KEY=<your-api-key>

or

$ commentaire <file> <api-key>

Commentaire takes a path to a Python file and an optional language parameter. If language is specified, Commentaire translates each docstring and comment in the code to the specified language and includes the translated text in the output. If language is not specified, Commentaire does not include any translations in the output.

Installation

To install Commentaire, you can use pip:

$ pip install commentaire

Functionality

Commentaire has a single function, process, which takes in a string of Python code and an optional language parameter. If language is specified, the function translates each docstring and comment in the code to the specified language and includes the translated text in the output. If language is not specified, the function does not include any translations in the output. The output text includes the original code, high-level explanatory comments, and any translated text (if language is specified).

The commentaire command uses process to add comments and translations to Python code in a file. It processes each file in a list of files passed as arguments to the commentaire command.

Example

Suppose you have a file called example.py with the following code:

def foo(x):
    y = x + 1
    return y

You can run Commentaire on this file to add comments (and optionally, translations to another language):

$ commentaire example.py --language Spanish

The resulting code will be:

"""
This function takes in a value x and returns its incremented value.

Esta función toma un valor x y devuelve su valor incrementado.
"""
def foo(x):
    y = x + 1
    return y

Note that Commentaire has added high-level explanatory comments and translated the existing docstring and comment to Spanish.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

commentaire-0.0.2.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

commentaire-0.0.2-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file commentaire-0.0.2.tar.gz.

File metadata

  • Download URL: commentaire-0.0.2.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for commentaire-0.0.2.tar.gz
Algorithm Hash digest
SHA256 34a3c97d669e39ebef6b434b7ec87d218474247573bd1f05ab07dc84f00bf7c7
MD5 5c61d7793c3ee0eb490d155dd9f0e98f
BLAKE2b-256 9b30508672a266b22e2246e66ee4c9e1cc97affbbeb058913b653183ccef947a

See more details on using hashes here.

File details

Details for the file commentaire-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: commentaire-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for commentaire-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a53f892078bd345564a8cfd236c5d482a3c22527720de52787a40d09bac1e2e8
MD5 4dbde3d0268c2fa07e7b698d710a3c8e
BLAKE2b-256 8fcafe94e40b21b3be967b6588e96f4369b120c778ea469950bcc60c15547a6d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page