Skip to content

Commit

Permalink
Ml2 dto (#14)
Browse files Browse the repository at this point in the history
* add func dto

* separated into files
  • Loading branch information
Farhan-Faisal authored Jan 15, 2025
1 parent 8e5cde8 commit 783309c
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 96 deletions.
99 changes: 3 additions & 96 deletions src/fml_doc_gen/fml_doc_gen.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import Callable
from fml_doc_gen import FunctionDTO

from fml_doc_gen import write_docstring_to_file
from fml_doc_gen import read_user_function
from fml_doc_gen import generate_template

def generate_docstring_template(func: Callable, output_file: str, auto_generate: bool = False) -> str:
"""
Expand Down Expand Up @@ -39,98 +41,3 @@ def generate_docstring_template(func: Callable, output_file: str, auto_generate:
"""

pass


def read_user_function(func: Callable) -> FunctionDTO:
"""
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: FunctionDTO) -> 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
36 changes: 36 additions & 0 deletions src/fml_doc_gen/generate_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from typing import Callable
from fml_doc_gen import FunctionDTO

def generate_template(func_signature: FunctionDTO) -> 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

29 changes: 29 additions & 0 deletions src/fml_doc_gen/read_user_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from typing import Callable
from fml_doc_gen import FunctionDTO


def read_user_function(func: Callable) -> FunctionDTO:
"""
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

34 changes: 34 additions & 0 deletions src/fml_doc_gen/write_docstring_to_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

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

0 comments on commit 783309c

Please sign in to comment.