diff --git a/README.md b/README.md index 7cb0119..6970e00 100644 --- a/README.md +++ b/README.md @@ -30,169 +30,17 @@ pip install write-the Write-the offers the following AI-driven features: -- Write-the Docs: Automatically generate documentation for your codebase, including class and function descriptions, parameter explanations, and examples. -- Write-the Tests: Create test cases for your code, ensuring thorough test coverage and better code quality. -- Write-the Convert: Convert code and data from any format into another. +- [Write-the Docs](https://write-the.wytamma.com/commands/docs/): Automatically generate documentation for your codebase, including class and function descriptions, parameter explanations, and examples. +- [Write-the Tests](https://write-the.wytamma.com/commands/tests/): Create test cases for your code, ensuring thorough test coverage and better code quality. +- [Write-the Convert](https://write-the.wytamma.com/commands/convert/): Convert code and data from any format into another. + +In addition write-the can also [manage OpenAI models](https://write-the.wytamma.com/commands/model/) and [scaffold MkDocs websites](https://write-the.wytamma.com/commands/mkdocs/). ## Requirements - Python 3.9 or higher - OpenAI API key -## Usage - -To use `write-the` you must set an OPENAI_API_KEY environment variable (e.g. `export OPENAI_API_KEY=...`). - -### Docs: - -Add google style docstrings to you Python code with AI. - -```bash -write-the docs [OPTIONS] [PATH_TO_SOURCE_CODE] -``` - -By default the `write-the docs` command will add docstrings to all the `nodes` in the source code that are not already documented. - -```bash -write-the docs write_the -``` - -#### Save -By default the docstrings will be printed to the console, you can use the `--save` flag to write the docstrings to the source code. - -```bash -write-the docs --save write_the -``` - -#### Generate docs for specific nodes - -A node is a function, class or class.method block. You can use the `--node` (`-n`) flag to specify which nodes to document (this will overwrite existing docstrings). - -```bash -write-the docs -n function_name -n class_name -n class.method_name write_the -``` - -#### Force and Update - -You can also use the `--force` flag to overwrite all existing docstrings in the specified folder or file. - -```bash -write-the docs --force write_the/some_file.py -``` - -You can use the `--update` flag to update existing docstrings. For example the command that was used to update the docstrings in the `write-the` codebase in [this commit](https://github.com/Wytamma/write-the/commit/862928a4467b9afd30443fc2332384c88c780d24) was: - -```bash -write-the docs --update --save write_the -``` - -### Model - -View and set the default model that `write-the` uses to generate documentation and tests. - -```bash -write-the model [OPTIONS] [DESIRED_MODEL] -``` - -The default model that `write-the` uses to generate documentation and tests is `gpt-3.5-turbo-instruct`. - -You can also use the `write-the model ` command to set the default model that `write-the` uses to generate documentation and tests. - -```bash -write-the model gpt-4 -``` - -Use the `--list` flag to view all available models. - -```bash -write-the model --list -``` - -### MkDocs: - -Generate a Markdown based [MkDocs website with material theme](https://squidfunk.github.io/mkdocs-material/) for a project including an API reference page. - -```bash -write-the mkdocs [OPTIONS] [PATH_TO_SOURCE_CODE] -``` - -The `write-the mkdocs` command will generate a `mkdocs.yml` file and a `docs` folder in the specified directory. In addition a github action workflow file will be generated to automatically build and deploy the documentation to github pages. The `--readme` flag can be used to specify the path to the readme file that will be used as the homepage for the documentation site. - -```bash -write-the mkdocs write_the --readme README.md -``` -The above command will generate the following file structure: - -```bash -. -├── mkdocs.yml -├── docs -│ ├── index.md -│ └── reference -│ ├── cli.md -│ ├── commands.md -│ ├── cst.md -│ ├── errors.md -│ ├── llm.md -│ ├── models.md -│ └── utils.md -└── .github - └── workflows - └── mkdocs.yml -``` - -You can see the documentation site that was generated for the `write-the` codebase [here](https://write-the.wytamma.com/). - -### Tests: - -Automatically generate test cases for your codebase using AI. - -```bash -write-the tests [OPTIONS] [PATH_TO_SOURCE_CODE] -``` - -The write-the tests command will generate test cases for all the functions in the specified directory that are not already tested. By default the tests will be printed to the console, you can use the `--save` flag to write the tests to the `--out` directory (default is `tests`). - -```bash -write-the tests --save write_the -``` - -### Convert: - -Convert code and data from any format into another using AI. - -```bash -write-the convert [OPTIONS] IN_FILE [OUT_FILE] -``` - -By default the `write-the convert` command will convert the input file to the output file format using the file extension to determine the input and output format. You can use the `--force` flag to overwrite the output file if it already exists. - -```bash -write-the convert tests/data/multiply.py multiply.rs -``` -```console -$ cat multiply.rs -fn multiply(a: i32, b: i32) -> i32 { - a * b -} -``` - -To give the llm model a hint about the input and output format you can use the `--input-format` and `--output-format` flags. - -```bash -write-the convert tests/data/multiply.py multiply.rs -o "Verbose Rust with lots of comments" -``` -```console -$ cat multiply.rs -// This is a function named 'multiply' that takes two parameters, 'a' and 'b'. -// Both 'a' and 'b' are of type i32, which is a 32-bit integer. -// The function returns a value of type i32. -fn multiply(a: i32, b: i32) -> i32 { - // The function body consists of a single expression, 'a * b'. - // This expression multiplies 'a' by 'b' and returns the result. - // In Rust, the last expression in a function is automatically returned. - a * b -} -``` +To use `write-the` you must set an `OPENAI_API_KEY` environment variable (e.g. `export OPENAI_API_KEY=...`). ## Documentation diff --git a/docs/commands/convert.md b/docs/commands/convert.md new file mode 100644 index 0000000..509182a --- /dev/null +++ b/docs/commands/convert.md @@ -0,0 +1,43 @@ +--- +title: Convert +--- +# Convert code and data from any format into another using AI + +You can use the `write-the convert` command to convert code and data from any format into another. + +```bash +write-the convert [OPTIONS] IN_FILE [OUT_FILE] +``` + +By default the `write-the convert` command will convert the input file to the output file format using the file extension to determine the input and output format. You can use the `--force` flag to overwrite the output file if it already exists. + +```bash +write-the convert tests/data/multiply.py multiply.rs +``` +```console +$ cat multiply.rs +fn multiply(a: i32, b: i32) -> i32 { + a * b +} +``` + +To give the llm model a hint about the input and output format you can use the `--input-format` and `--output-format` flags. + +```bash +write-the convert \ + tests/data/multiply.py \ + multiply.rs \ + -o "Verbose Rust with lots of comments" +``` +```console +$ cat multiply.rs +// This is a function named 'multiply' that takes two parameters, 'a' and 'b'. +// Both 'a' and 'b' are of type i32, which is a 32-bit integer. +// The function returns a value of type i32. +fn multiply(a: i32, b: i32) -> i32 { + // The function body consists of a single expression, 'a * b'. + // This expression multiplies 'a' by 'b' and returns the result. + // In Rust, the last expression in a function is automatically returned. + a * b +} +``` \ No newline at end of file diff --git a/docs/commands/docs.md b/docs/commands/docs.md new file mode 100644 index 0000000..1276ee6 --- /dev/null +++ b/docs/commands/docs.md @@ -0,0 +1,71 @@ +--- +title: Docstrings +--- + +# Automatically Generate Docstrings for yor Python Code With AI + +The primary use case for `write-the` is to add docstrings to your Python code. You can do this using the `write-the docs` command. + +```bash +write-the docs [OPTIONS] [PATH_TO_SOURCE_CODE] +``` + +By default the `write-the docs` command will add docstrings to all the `nodes` in the source code that are not already documented. You can run the docs command on an entire directory or a single file. + +```bash +❯ write-the docs src/ +✅ src/multiply.py +def multiply(a, b): + """ + Multiplies 2 numbers. + + Args: + a (int or float): The first number to multiply. + b (int or float): The second number to multiply. + + Returns: + int or float: The product of a and b. + + Examples: + >>> multiply(2, 3) + 6 + >>> multiply(1.5, 4) + 6.0 + """ + return a * b +``` + +The ✅ indicates that the docstrings were added created. If there is an error (❌) adding the docstrings, the error message will be printed to the console. Any nodes that already have docstrings will be skipped (⏭️). + +## Save + +By default the docstrings will be printed to the console, you can use the `--save` flag to write the docstrings to the source code. + +```bash +❯ write-the docs --save src/ +⏭️ src/multiply_docstring.py - No nodes found, skipping file... +✅ src/multiply.py +✅ src/calculate.py +``` + +## Generate docs for specific nodes + +A node is a function, class or class.method block. You can use the `--node` (`-n`) flag to specify which nodes to document (this will overwrite existing docstrings). + +```bash +write-the docs src/ -n function_name -n class_name -n class.method_name +``` + +## Force and Update + +You can also use the `--force` flag to overwrite all existing docstrings in the specified folder or file. + +```bash +write-the docs --force src/some_file.py +``` + +You can use the `--update` flag to update existing docstrings. For example the command that was used to update the docstrings in the `write-the` codebase in [this commit](https://github.com/Wytamma/write-the/commit/862928a4467b9afd30443fc2332384c88c780d24) was: + +```bash +write-the docs --update --save src/ +``` diff --git a/docs/commands/mkdocs.md b/docs/commands/mkdocs.md new file mode 100644 index 0000000..ecf09af --- /dev/null +++ b/docs/commands/mkdocs.md @@ -0,0 +1,38 @@ +--- +title: MkDocs website +--- + +# Use write-the to generate a fully featured MkDocs website for your project + +Generate a Markdown based [MkDocs website with material theme](https://squidfunk.github.io/mkdocs-material/) for a project including an API reference page. + +```bash +write-the mkdocs [OPTIONS] [PATH_TO_SOURCE_CODE] +``` + +The `write-the mkdocs` command will generate a `mkdocs.yml` file and a `docs` folder in the specified directory. In addition a github action workflow file will be generated to automatically build and deploy the documentation to github pages. The `--readme` flag can be used to specify the path to the readme file that will be used as the homepage for the documentation site. + +```bash +write-the mkdocs write_the --readme README.md +``` +The above command will generate the following file structure: + +```bash +. +├── mkdocs.yml +├── docs +│ ├── index.md +│ └── reference +│ ├── cli.md +│ ├── commands.md +│ ├── cst.md +│ ├── errors.md +│ ├── llm.md +│ ├── models.md +│ └── utils.md +└── .github + └── workflows + └── mkdocs.yml +``` + +You can see the documentation site that was generated for the `write-the` codebase [here](https://write-the.wytamma.com/). diff --git a/docs/commands/model.md b/docs/commands/model.md new file mode 100644 index 0000000..a26851c --- /dev/null +++ b/docs/commands/model.md @@ -0,0 +1,25 @@ +--- +title: Mange OpenAI Models +--- + +# Mange the default model used by `write-the` + +View and set the default model that `write-the` uses to generate documentation and tests. + +```bash +write-the model [OPTIONS] [DESIRED_MODEL] +``` + +The default model that `write-the` uses to generate documentation and tests is `gpt-3.5-turbo-instruct`. + +You can also use the `write-the model ` command to set the default model that `write-the` uses to generate documentation and tests. + +```bash +write-the model gpt-4 +``` + +Use the `--list` flag to view all available models. + +```bash +write-the model --list +``` \ No newline at end of file diff --git a/docs/commands/tests.md b/docs/commands/tests.md new file mode 100644 index 0000000..45d3682 --- /dev/null +++ b/docs/commands/tests.md @@ -0,0 +1,17 @@ +--- +title: Tests +--- + +# Automatically generate test cases for your codebase using AI + +You can use the `write-the tests` command to automatically generate test cases for your codebase. The tests will use the `pytest` framework. + +```bash +write-the tests [OPTIONS] [PATH_TO_SOURCE_CODE] +``` + +The write-the tests command will generate test cases for all the functions in the specified directory that are not already tested. By default the tests will be printed to the console, you can use the `--save` flag to write the tests to the `--out` directory (default is `tests`). + +```bash +write-the tests --save write_the +``` \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index 46fe3b0..afaede9 100644 --- a/docs/index.md +++ b/docs/index.md @@ -33,169 +33,20 @@ pip install write-the Write-the offers the following AI-driven features: -- Write-the Docs: Automatically generate documentation for your codebase, including class and function descriptions, parameter explanations, and examples. -- Write-the Tests: Create test cases for your code, ensuring thorough test coverage and better code quality. -- Write-the Convert: Convert code and data from any format into another. +- [Write-the Docs](https://write-the.wytamma.com/commands/docs/): Automatically generate documentation for your codebase, including class and function descriptions, parameter explanations, and examples. +- [Write-the Tests](https://write-the.wytamma.com/commands/tests/): Create test cases for your code, ensuring thorough test coverage and better code quality. +- [Write-the Convert](https://write-the.wytamma.com/commands/convert/): Convert code and data from any format into another. + +In addition write-the can also [manage OpenAI models](https://write-the.wytamma.com/commands/model/) and [scaffold MkDocs websites](https://write-the.wytamma.com/commands/mkdocs/). ## Requirements - Python 3.9 or higher - OpenAI API key -## Usage - -To use `write-the` you must set an OPENAI_API_KEY environment variable (e.g. `export OPENAI_API_KEY=...`). - -### Docs: - -Add google style docstrings to you Python code with AI. - -```bash -write-the docs [OPTIONS] [PATH_TO_SOURCE_CODE] -``` - -By default the `write-the docs` command will add docstrings to all the `nodes` in the source code that are not already documented. - -```bash -write-the docs write_the -``` - -#### Save -By default the docstrings will be printed to the console, you can use the `--save` flag to write the docstrings to the source code. - -```bash -write-the docs --save write_the -``` - -#### Generate docs for specific nodes - -A node is a function, class or class.method block. You can use the `--node` (`-n`) flag to specify which nodes to document (this will overwrite existing docstrings). - -```bash -write-the docs -n function_name -n class_name -n class.method_name write_the -``` - -#### Force and Update - -You can also use the `--force` flag to overwrite all existing docstrings in the specified folder or file. - -```bash -write-the docs --force write_the/some_file.py -``` - -You can use the `--update` flag to update existing docstrings. For example the command that was used to update the docstrings in the `write-the` codebase in [this commit](https://github.com/Wytamma/write-the/commit/862928a4467b9afd30443fc2332384c88c780d24) was: - -```bash -write-the docs --update --save write_the -``` - -### Model - -View and set the default model that `write-the` uses to generate documentation and tests. - -```bash -write-the model [OPTIONS] [DESIRED_MODEL] -``` - -The default model that `write-the` uses to generate documentation and tests is `gpt-3.5-turbo-instruct`. - -You can also use the `write-the model ` command to set the default model that `write-the` uses to generate documentation and tests. - -```bash -write-the model gpt-4 -``` - -Use the `--list` flag to view all available models. - -```bash -write-the model --list -``` - -### MkDocs: - -Generate a Markdown based [MkDocs website with material theme](https://squidfunk.github.io/mkdocs-material/) for a project including an API reference page. - -```bash -write-the mkdocs [OPTIONS] [PATH_TO_SOURCE_CODE] -``` - -The `write-the mkdocs` command will generate a `mkdocs.yml` file and a `docs` folder in the specified directory. In addition a github action workflow file will be generated to automatically build and deploy the documentation to github pages. The `--readme` flag can be used to specify the path to the readme file that will be used as the homepage for the documentation site. - -```bash -write-the mkdocs write_the --readme README.md -``` -The above command will generate the following file structure: - -```bash -. -├── mkdocs.yml -├── docs -│ ├── index.md -│ └── reference -│ ├── cli.md -│ ├── commands.md -│ ├── cst.md -│ ├── errors.md -│ ├── llm.md -│ ├── models.md -│ └── utils.md -└── .github - └── workflows - └── mkdocs.yml -``` - -You can see the documentation site that was generated for the `write-the` codebase [here](https://write-the.wytamma.com/). - -### Tests: - -Automatically generate test cases for your codebase using AI. - -```bash -write-the tests [OPTIONS] [PATH_TO_SOURCE_CODE] -``` +!!! note -The write-the tests command will generate test cases for all the functions in the specified directory that are not already tested. By default the tests will be printed to the console, you can use the `--save` flag to write the tests to the `--out` directory (default is `tests`). + To use `write-the` you must set an `OPENAI_API_KEY` environment variable (e.g. `export OPENAI_API_KEY=...`). -```bash -write-the tests --save write_the -``` - -### Convert: - -Convert code and data from any format into another using AI. - -```bash -write-the convert [OPTIONS] IN_FILE [OUT_FILE] -``` - -By default the `write-the convert` command will convert the input file to the output file format using the file extension to determine the input and output format. You can use the `--force` flag to overwrite the output file if it already exists. - -```bash -write-the convert tests/data/multiply.py multiply.rs -``` -```console -$ cat multiply.rs -fn multiply(a: i32, b: i32) -> i32 { - a * b -} -``` - -To give the llm model a hint about the input and output format you can use the `--input-format` and `--output-format` flags. - -```bash -write-the convert tests/data/multiply.py multiply.rs -o "Verbose Rust with lots of comments" -``` -```console -$ cat multiply.rs -// This is a function named 'multiply' that takes two parameters, 'a' and 'b'. -// Both 'a' and 'b' are of type i32, which is a 32-bit integer. -// The function returns a value of type i32. -fn multiply(a: i32, b: i32) -> i32 { - // The function body consists of a single expression, 'a * b'. - // This expression multiplies 'a' by 'b' and returns the result. - // In Rust, the last expression in a function is automatically returned. - a * b -} -``` ## Documentation diff --git a/mkdocs.yml b/mkdocs.yml index 1ed0c37..3054bef 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -44,3 +44,6 @@ markdown_extensions: - pymdownx.inlinehilite - pymdownx.snippets - pymdownx.superfences + - admonition + - pymdownx.details + diff --git a/write_the/cli/main.py b/write_the/cli/main.py index 493ef59..dea7092 100644 --- a/write_the/cli/main.py +++ b/write_the/cli/main.py @@ -123,7 +123,8 @@ async def docs( if f.is_dir(): files.extend(list_python_files(f)) else: - assert f.suffix == ".py" + if f.suffix != ".py": + raise typer.BadParameter("File must be a .py file or a directory.") files.append(f) with Progress( SpinnerColumn(), @@ -221,7 +222,8 @@ async def tests( if file.is_dir(): files = list_python_files(file) else: - assert file.suffix == ".py" + if file.suffix != ".py": + raise typer.BadParameter("File must be a .py file or a directory.") files = [file] for file in files: if file.stem.startswith("_"):