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

Suggestion for fixing the unintentional situation that since v0.6 the… #404

Merged
merged 6 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
52 changes: 35 additions & 17 deletions src/pynxtools/dataconverter/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,28 +284,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",
default=None,
sherjeelshabih marked this conversation as resolved.
Show resolved Hide resolved
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=None 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 NXDL file to use without the "
sherjeelshabih marked this conversation as resolved.
Show resolved Hide resolved
"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/HDF5 file to be generated.",
lukaspie marked this conversation as resolved.
Show resolved Hide resolved
)
@click.option(
"--params-file",
Expand Down Expand Up @@ -333,12 +337,14 @@ def main_cli():
)
@click.option(
"--mapping",
default=None,
sherjeelshabih marked this conversation as resolved.
Show resolved Hide resolved
help="Takes a <name>.mapping.json file and converts data from given input files.",
)
@click.option(
"-c",
"--config",
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 Down Expand Up @@ -375,6 +381,7 @@ def convert_cli(
if mapping:
reader = "json_map"
input_file = input_file + tuple([mapping])
# needs own call

file_list = []
for file in files:
Expand All @@ -392,16 +399,27 @@ def convert_cli(
)

try:
convert(
tuple(file_list) + input_file,
reader,
nxdl,
output,
skip_verify,
config_file=config,
ignore_undocumented=ignore_undocumented,
fail=fail,
)
if config: # most but not all readers demand a config.json file
convert(
tuple(file_list) + input_file,
reader,
nxdl,
output,
skip_verify,
config_file=config,
ignore_undocumented=ignore_undocumented,
fail=fail,
)
else:
convert(
tuple(file_list) + input_file,
reader,
nxdl,
output,
skip_verify,
ignore_undocumented=ignore_undocumented,
fail=fail,
)
sherjeelshabih marked this conversation as resolved.
Show resolved Hide resolved
except FileNotFoundError as exc:
raise click.BadParameter(str(exc)) from exc
except ValidationFailed as exc:
Expand Down
Loading