Skip to content

Commit

Permalink
fix docstring format & pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
Farhan-Faisal committed Jan 10, 2025
1 parent dd48a08 commit c6b34cc
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 89 deletions.
2 changes: 1 addition & 1 deletion docs/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if "%SPHINXBUILD%" == "" (
)
set SOURCEDIR=.
set BUILDDIR=_build
set SPHINXPROJ=fml
set SPHINXPROJ=FML_doc_generator

if "%1" == "" goto help

Expand Down
24 changes: 24 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 'fml'
channels:
- conda-forge
- defaults
dependencies:
- python=3.9
- pip
- ipykernel
- nb_conda_kernels
- otter-grader=6.*
- scipy
- matplotlib>=3.2.2
- scikit-learn
- requests>=2.24.0
- graphviz
- python-graphviz
- eli5
- jinja2
- nltk
- imbalanced-learn
- quarto=1.5.57
- pip:
- mglearn
- spacymoji
77 changes: 72 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
[tool.poetry]
name = "fml"
name = "FML_doc_generator"
version = "0.0.1"
description = "doc string generator"
authors = ["Farhan Faisal"]
authors = ["Farhan Faisal", "Michael Suriawan", "Lukman Lateef"]
license = "MIT"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.9"
poetry = "^2.0.0"

[tool.poetry.group.dev.dependencies]
pytest = "^8.3.4"

[tool.semantic_release]
version_toml = [
"pyproject.toml:tool.poetry.version",
Expand Down
134 changes: 134 additions & 0 deletions src/FML_doc_generator/FML_doc_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
from typing import Callable

def generate_docstring_template(func: Callable, output_file: str, auto_generate: bool = False) -> str:
"""
Generates a docstring template for a given user-defined function.
Parameters
----------
func : Callable
The user-defined function for which the docstring template (or full docstring) needs to be generated.
output_file : str
Writes the generated docstring to the given file. Defaults to None.
auto_generate : bool, optional
If True, automatically generates the full docstring using an OpenAI API call. Defaults to False.
Returns
-------
str
The generated docstring template or complete docstring.
Examples
--------
>>> def example_func(a, b):
... return a + b
>>> docstring = generate_docstring_template(example_func)
>>> print(docstring)
\"\"\"Parameters
----------
a : type
b : type
Returns
-------
return_type
\"\"\"
"""

pass


def read_user_function(func: Callable) -> str:
"""
Reads the source code of the user-provided function and extracts its signature and existing docstring (if any).
Parameters
----------
func : Callable
The user-defined function.
Returns
-------
str
The function signature as a string.
Examples
--------
>>> def example_func(a, b):
... return a + b
...
>>> read_user_function(example_func)
'example_func(a, b)'
"""

pass


def generate_template(func_signature: str) -> str:
"""
Generates a docstring template with placeholders for parameters, return values, and a brief description
based on the provided function signature.
Parameters
----------
func_signature : str
The signature of the user-defined function.
Returns
-------
str
The docstring template with placeholders.
Examples
--------
>>> func_signature = "example_func(a, b)"
>>> template = generate_template(func_signature)
>>> print(template)
\"\"\"Parameters
----------
a : type
b : type
Returns
-------
return_type
\"\"\"
"""

pass


def write_docstring_to_file(docstring: str, output_file: str) -> None:
"""
Writes the generated docstring to a specified output file.
Parameters
----------
docstring : str
The docstring to be written to the file.
output_file : str
The path to the output file.
Returns
-------
None
This function does not return anything.
Examples
--------
>>> docstring = \"\"\"Parameters
----------
a : int
b : int
Returns
-------
int
\"\"\"
>>> output_file = 'docstring_output.txt'
>>> write_docstring_to_file(docstring, output_file)
# This writes the docstring to 'docstring_output.txt'
"""

pass
File renamed without changes.
Loading

0 comments on commit c6b34cc

Please sign in to comment.