Skip to content

Commit

Permalink
Added api.get_plugin_information()
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-david committed Jan 14, 2022
1 parent fd5aa9b commit 0e7c87e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/fastoad/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""This module gathers key FAST-OAD classes and functions for convenient import."""
# This file is part of FAST-OAD : A framework for rapid Overall Aircraft Design
# Copyright (C) 2021 ONERA & ISAE-SUPAERO
# Copyright (C) 2022 ONERA & ISAE-SUPAERO
# FAST is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
Expand All @@ -17,6 +17,8 @@


from fastoad.cmd.api import (
get_plugin_information,
generate_notebooks,
evaluate_problem,
generate_configuration_file,
generate_inputs,
Expand Down
32 changes: 27 additions & 5 deletions src/fastoad/cmd/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
from collections import defaultdict
from collections.abc import Iterable
from time import time
from typing import IO, List, Union
from typing import Dict, IO, List, Union

import openmdao.api as om
import pandas as pd
from IPython import InteractiveShell
from IPython.display import HTML, clear_output, display
from tabulate import tabulate
Expand All @@ -43,21 +44,42 @@
from fastoad.io.variable_io import DataFile
from fastoad.io.xml import VariableLegacy1XmlFormatter
from fastoad.module_management._bundle_loader import BundleLoader
from fastoad.module_management._plugins import FastoadLoader
from fastoad.module_management._plugins import DistributionPluginDefinition, FastoadLoader
from fastoad.module_management.service_registry import RegisterOpenMDAOSystem, RegisterPropulsion
from fastoad.openmdao.problem import FASTOADProblem
from fastoad.openmdao.variables import VariableList

DEFAULT_WOP_URL = "https://ether.onera.fr/whatsopt"
_LOGGER = logging.getLogger(__name__)

SAMPLE_FILENAME = "fastoad.yml"
MAX_TABLE_WIDTH = 200 # For variable list text output

# Used for test purposes only
_PROBLEM_CONFIGURATOR = None


def get_plugin_information(print_data=False) -> Dict[str, DistributionPluginDefinition]:
"""
Provides information about available FAST-OAD plugins.
:param print_data: if True, plugin data are displayed.
:return: a dict with installed package names as keys and matching FAST-OAD
plugin definitions as values.
"""
plugin_definitions = FastoadLoader().distribution_plugin_definitions
if print_data:
table_dicts = [plugin_def.to_dict() for plugin_def in plugin_definitions.values()]

if table_dicts:
table = pd.DataFrame(table_dicts)
if InteractiveShell.initialized():
display(HTML(table.to_html(index=False)))
else:
print(table.to_markdown(index=False))
else:
print("No available FAST-OAD plugin.")

return plugin_definitions


def generate_notebooks(
destination_path: str,
overwrite: bool = False,
Expand Down
12 changes: 1 addition & 11 deletions src/fastoad/cmd/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,7 @@ def fast_oad():
@fast_oad.command(name="plugin_info")
def plugin_info():
"""Provides list of installed FAST-OAD plugins."""

plugin_definitions = FastoadLoader().distribution_plugin_definitions
table_dicts = [
dist_plugin_definitions.to_dict() for dist_plugin_definitions in plugin_definitions.values()
]

if table_dicts:
table = pd.DataFrame(table_dicts)
print(table.to_markdown(index=False))
else:
print("No available FAST-OAD plugin.")
api.get_plugin_information(print_data=True)


@fast_oad.command(name="gen_conf")
Expand Down

0 comments on commit 0e7c87e

Please sign in to comment.