Skip to content

Commit

Permalink
Merge pull request #404 from FAIRmat-NFDI/fix_clickopt_configfile_def…
Browse files Browse the repository at this point in the history
…ault
  • Loading branch information
mkuehbach authored Aug 26, 2024
2 parents 2d678b5 + 5fd863a commit 2610b60
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 33 deletions.
24 changes: 0 additions & 24 deletions src/pynxtools/dataconverter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,6 @@ user@box:~$ pip install pynxtools[convert]
```console
Usage: dataconverter [OPTIONS] COMMAND [ARGS]...

Options:
--help Show this message and exit.
--input-file TEXT Deprecated: Please use the positional file
arguments instead. The path to the input
data file to read. (Repeat for more than one
file.)
--reader [example|json_map|json_yml]
The reader to use. default="example"
--nxdl TEXT The name of the NXDL file to use without
extension.This option is required if no '--
params-file' is supplied.
--output TEXT The path to the output NeXus file to be
generated.
--params-file FILENAME Allows to pass a .yaml file with all the
parameters the converter supports.
--ignore-undocumented Ignore all undocumented fields during
validation.
--fail Fail conversion and don't create an output
file if the validation fails.
--skip-verify Skips the verification routine during
conversion.
--mapping TEXT Takes a <name>.mapping.json file and
converts data from given input files.

Commands:
convert* This command allows you to use the converter...
generate-template Generates and prints a template to use for your nxdl.
Expand Down
28 changes: 19 additions & 9 deletions src/pynxtools/dataconverter/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ def convert(
-------
None.
"""

nxdl_root, nxdl_f_path = helpers.get_nxdl_root_and_path(nxdl)

data = transfer_data_into_template(
Expand Down Expand Up @@ -288,28 +287,32 @@ def main_cli():
default=[],
multiple=True,
help=(
"Deprecated: Please use the positional file arguments instead. "
"The path to the input data file to read. (Repeat for more than one file.)"
"Deprecated: Please use the positional file arguments instead. The path to the "
"input data file to read. Repeat for more than one file. default=[] This option "
"is required if no '--params-file' is supplied."
),
)
@click.option(
"--reader",
default="json_map",
type=click.Choice(get_names_of_all_readers(), case_sensitive=False),
help='The reader to use. default="example"',
help=(
"The reader to use. Examples are json_map or readers from a pynxtools plugin. "
"default='json_map' This option is required if no '--params-file' is supplied."
),
)
@click.option(
"--nxdl",
default=None,
help=(
"The name of the NXDL file to use without extension."
"This option is required if no '--params-file' is supplied."
"The name of the NeXus application definition file to use without the extension "
"nxdl.xml. This option is required if no '--params-file' is supplied."
),
)
@click.option(
"--output",
default="output.nxs",
help="The path to the output NeXus file to be generated.",
help="The path to the output NeXus file to be generated. default='output.nxs'",
)
@click.option(
"--params-file",
Expand Down Expand Up @@ -342,7 +345,9 @@ def main_cli():
@click.option(
"-c",
"--config",
"config_file",
type=click.Path(exists=True, dir_okay=False, file_okay=True, readable=True),
default=None,
help="A json config file for the reader",
)
# pylint: disable=too-many-arguments
Expand All @@ -356,8 +361,9 @@ def convert_cli(
ignore_undocumented: bool,
skip_verify: bool,
mapping: str,
config: str,
config_file: str,
fail: bool,
**kwargs,
):
"""This command allows you to use the converter functionality of the dataconverter."""
if params_file:
Expand All @@ -379,6 +385,10 @@ def convert_cli(
if mapping:
reader = "json_map"
input_file = input_file + tuple([mapping])
# needs own call

if config_file:
kwargs["config_file"] = config_file

file_list = []
for file in files:
Expand All @@ -402,9 +412,9 @@ def convert_cli(
nxdl,
output,
skip_verify,
config_file=config,
ignore_undocumented=ignore_undocumented,
fail=fail,
**kwargs,
)
except FileNotFoundError as exc:
raise click.BadParameter(str(exc)) from exc
Expand Down

0 comments on commit 2610b60

Please sign in to comment.