Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docstrings with help from copilot #52

Merged
merged 10 commits into from
Aug 2, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The changelog format is based on [Keep a Changelog](https://keepachangelog.com/e

### Changed

* Added missing docstrings for py/cpp/h files with help of Github Copilot
* Moved CMake + conan + c++ package files and folders with cpp code inside src folder to be included in package
* Replace pkg_resources with importlib.metadata for getting packages version to work in python 3.12
* Replace deprecated root_validator with model_validator in pydanitc class
Expand Down
46 changes: 10 additions & 36 deletions src/mlfmu/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,13 @@ def __init__(
logger.debug(f"Created temp folder: {self.temp_folder_path}")

def __del__(self):
"""
Destructor for the MlFmuBuilder class.

This method is automatically called when the object is about to be destroyed.
The destructor should automatically delete the temporary directory (goes out of scope).
"""
logger.debug("MlFmuBuilder: destructor called, removing temporary build directory.")
# The destructor should automatically delete the temporary directory (goes out of scope).

def build(self):
"""
Expand Down Expand Up @@ -191,7 +196,7 @@ def build(self):

def generate(self):
"""
Generate FMU c++ source code and model description from ml_model_file and interface_file and saves it to source_folder.
Generate FMU C++ source code and model description from ml_model_file and interface_file and saves it to source_folder.

If the paths to the necessary files and directories are not given the function will try to find files and directories that match the ones needed.

Expand Down Expand Up @@ -232,7 +237,7 @@ def generate(self):

def compile(self):
"""
Compile FMU from FMU c++ source code and model description contained in source_folder and saves it to fmu_output_folder.
Compile FMU from FMU C++ source code and model description contained in source_folder and saves it to fmu_output_folder.

If the paths to the necessary files and directories are not given the function will try to find files and directories that match the ones needed.

Expand Down Expand Up @@ -416,7 +421,8 @@ def __init__(
)

def run(self):
"""Run the mlfmu process.
"""
Run the mlfmu process.

Runs the mlfmu process in a self-terminated loop.
"""
Expand All @@ -433,38 +439,6 @@ def run(self):

return

@property
def run_number(self) -> int:
"""Example for a read only property."""
return self._run_number

@property
def max_number_of_runs(self) -> int:
"""Example for a read/write property implemented through a pair of explicit
getter and setter methods (see below for the related setter method).
"""
return self._max_number_of_runs

@max_number_of_runs.setter
def max_number_of_runs(self, value: int):
"""Setter method that belongs to above getter method.

Note that implementing specific getter- and setter methods is in most cases not necessary.
The same can be achieved by simply making the instance variable a public attribute.
I.e., declaring the instance variable in __init__() not as
self._max_number_of_runs: int = .. # (-> private instance variable)
but as
self.max_number_of_runs: int = .. # (-> public attribute)

However, in some cases the additional effort of implementing explicit getter- and setter- methods
as in this example can be reasoned, for instance if you have a need for increased control
and want be able to cancel or alter code execution, or write log messages whenever a property
gets reads or written from outside.
"""

self._max_number_of_runs = value
return

def _run_process(self):
"""Execute a single run of the mlfmu process."""
self._run_number += 1
Expand Down
11 changes: 10 additions & 1 deletion src/mlfmu/cli/mlfmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@


def _argparser() -> argparse.ArgumentParser:
"""
Create and return an ArgumentParser object for parsing command line arguments.

Returns
-------
argparse.ArgumentParser: The ArgumentParser object.
"""

parser = argparse.ArgumentParser(
prog="mlfmu",
epilog="_________________mlfmu___________________",
Expand Down Expand Up @@ -128,7 +136,8 @@ def _argparser() -> argparse.ArgumentParser:


def main():
"""Entry point for console script as configured in setup.cfg.
"""
Entry point for console script as configured in setup.cfg.

Runs the command line interface and parses arguments and options entered on the console.
"""
Expand Down
1 change: 1 addition & 0 deletions src/mlfmu/cli/publish_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@


def main():
"""Start the publishing process for the mlfmu interface docs, by calling the publish_interface_schema function."""
logger.info("Start publish-interface-docs.py")
publish_interface_schema()
33 changes: 31 additions & 2 deletions src/mlfmu/fmu_build/templates/fmu/fmu_template.cpp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is a bit weird since it is a template string file and a cpp file at the same time. I see that some linting has made some changes that I think breaks its use as a template string. I suggest some changes below to fix it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, suggestions accepted, and template/examples removed. Let me know if there's more!

Thanks for making the suggestions as you did, it was super easy to just accept/commit those :)

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,41 @@
#include <onnxFmu.hpp>


/**
* \class {FmuName}
* \brief A class representing an {FmuName} FMU.
*
* This class is derived from the OnnxFmu class and provides functionality specific to the {FmuName} FMU.
*/
class {FmuName} : public OnnxFmu {{
public :
{FmuName}(cppfmu::FMIString fmuResourceLocation) : OnnxFmu(fmuResourceLocation) {{}} private :
}};
/**
* \brief Constructs a new {FmuName} object.
*
* \param fmuResourceLocation The location of the resources of the FMU.
*/
{FmuName}(cppfmu::FMIString fmuResourceLocation) : OnnxFmu(fmuResourceLocation) {{}}

private :
// Add private members and functions here
}};

/**
* \brief Instantiate a `slave` instance of the FMU.
*
* \param instanceName The name of the FMU instance.
* \param fmuGUID The GUID of the FMU.
* \param fmuResourceLocation The location of the FMU resource.
StephanieKemna marked this conversation as resolved.
Show resolved Hide resolved
* \param mimeType The MIME type of the FMU.
* \param timeout The timeout value for the instantiation process.
* \param visible Flag indicating whether the FMU should be visible.
* \param interactive Flag indicating whether the FMU should be interactive.
* \param memory The memory to be used for the FMU instance.
* \param logger The logger to be used for logging messages.
* \returns A unique pointer to the instantiated slave instance.
*
* \throws std::runtime_error if the FMU GUID does not match.
*/
cppfmu::UniquePtr<cppfmu::SlaveInstance> CppfmuInstantiateSlave(
cppfmu::FMIString /*instanceName*/, cppfmu::FMIString fmuGUID, cppfmu::FMIString fmuResourceLocation,
cppfmu::FMIString /*mimeType*/, cppfmu::FMIReal /*timeout*/, cppfmu::FMIBoolean /*visible*/,
Expand Down
Loading