Skip to content

Commit

Permalink
Now CLI gen_inputs allows to include output variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-david committed Jul 23, 2024
1 parent 28d0bd8 commit bc12bf5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
10 changes: 7 additions & 3 deletions src/fastoad/cmd/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
from fastoad.cmd.exceptions import FastNoAvailableNotebookError
from fastoad.module_management.exceptions import (
FastNoAvailableConfigurationFileError,
FastNoAvailableSourceDataFileError,
FastNoDistPluginError,
FastSeveralConfigurationFilesError,
FastSeveralDistPluginsError,
FastSeveralSourceDataFilesError,
FastUnknownConfigurationFileError,
FastUnknownDistPluginError,
FastNoAvailableSourceDataFileError,
FastSeveralSourceDataFilesError,
FastUnknownSourceDataFileError,
)
from . import api
Expand Down Expand Up @@ -138,10 +138,13 @@ def gen_source_data_file(source_data_file, from_package, source, force):
@click.argument("conf_file", nargs=1)
@click.argument("source_data_file", nargs=1, required=False)
@overwrite_option
@click.option(
"--include_outputs", is_flag=True, help="To be used to have output variables in generated file."
)
@click.option(
"--legacy", is_flag=True, help="To be used if the source data XML file is in legacy format."
)
def gen_inputs(conf_file, source_data_file, force, legacy):
def gen_inputs(conf_file, source_data_file, force, include_outputs, legacy):
"""
Generate the input file (specified in the configuration file) with needed variables.
Expand All @@ -167,6 +170,7 @@ def gen_inputs(conf_file, source_data_file, force, legacy):
source_data_path=source_data_file,
source_data_path_schema=schema,
overwrite=force,
write_output_variables=include_outputs,
)


Expand Down
9 changes: 5 additions & 4 deletions src/fastoad/cmd/tests/data/inputs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
-->

<aircraft>
<f is_input="False">20.0</f>
<g1 is_input="False">-15.0</g1>
<g2 is_input="False">-13.0</g2>
<f is_input="False">32.569100892077444<!--Objective--></f>
<g1 is_input="False">-23.409095627564167</g1>
<g2 is_input="False">-11.845478137832359</g2>
<x is_input="True">2.0<!--input x--></x>
<y2 is_input="False">11.0<!--variable y2--></y2>
<y1 is_input="False">26.569095627564167<!--variable y1--></y1>
<y2 is_input="False">12.154521862167641<!--variable y2--></y2>
<z units="m**2" is_input="True">[5.0, 2.0]<!--variable z--></z>
</aircraft>
9 changes: 5 additions & 4 deletions src/fastoad/cmd/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
from fastoad.cmd.cli import NOTEBOOK_FOLDER_NAME, fast_oad

DATA_FOLDER_PATH = Path(__file__).parent / "data"
RESULTS_FOLDER_PATH = Path(__file__).parent / "results" / Path(__file__).stem
RESULTS_FOLDER_PATH = Path(__file__).parent / "results"


@pytest.fixture(scope="module")
@pytest.fixture(scope="session")
def cleanup():
shutil.rmtree(RESULTS_FOLDER_PATH, ignore_errors=True)
RESULTS_FOLDER_PATH.mkdir(parents=True)
Expand Down Expand Up @@ -446,13 +446,14 @@ def test_gen_source_data_several_plugin(cleanup, with_dummy_plugins, plugin_root

def test_eval(cleanup):
runner = CliRunner()
with runner.isolated_filesystem(temp_dir=RESULTS_FOLDER_PATH) as temp_dir:
with runner.isolated_filesystem(temp_dir=RESULTS_FOLDER_PATH):
result_1 = runner.invoke(
fast_oad,
[
"gen_inputs",
(DATA_FOLDER_PATH / "sellar.yml").as_posix(),
(DATA_FOLDER_PATH / "inputs.xml").as_posix(),
"--include_outputs",
],
)
assert not result_1.exception
Expand All @@ -466,7 +467,7 @@ def test_eval(cleanup):

def test_optim(cleanup):
runner = CliRunner()
with runner.isolated_filesystem(temp_dir=RESULTS_FOLDER_PATH) as temp_dir:
with runner.isolated_filesystem(temp_dir=RESULTS_FOLDER_PATH):
result_1 = runner.invoke(
fast_oad,
[
Expand Down

0 comments on commit bc12bf5

Please sign in to comment.