Skip to content

Commit

Permalink
Merge pull request #96 from SciCatProject/config
Browse files Browse the repository at this point in the history
Command configuration update.
  • Loading branch information
YooSunYoung authored Dec 4, 2024
2 parents b569fc1 + 5aad590 commit 64ea0b8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- run: python -m pip install --upgrade pip
- run: python -m pip install -r requirements/ci.txt
- run: python -m pip install -e .
- run: validate_ingestor_config resources/config.sample.json
- run: scicat_validate_ingestor_config resources/config.sample.json
- run: docker-compose version
- run: docker-compose -f tests/docker-compose-file-writer.yml up -d
- run: python tests/_scicat_ingestor.py -c resources/config.sample.json --logging.verbose
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ You need to know the path to the nexus file you want to ingest
and also the path to the ``done_writing_message_file`` as a json file.

```bash
background_ingestor \
scicat_background_ingestor \
--logging.verbose \
-c PATH_TO_CONFIGURATION_FILE.yaml \
--nexus-file PATH_TO_THE_NEXUS_FILE.nxs \
Expand Down Expand Up @@ -69,10 +69,10 @@ The template file can be synchronized automatically by ``synchronize_config`` co

### Configuration Validator

You can validate a configuration file with ``validate_ingestor_config`` command.
You can validate a configuration file with ``scicat_validate_ingestor_config`` command.

```bash
validate_ingestor_config
scicat_validate_ingestor_config
```

It tries building nested configuration dataclasses from the configuration file.
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ dynamic = ["version"]

[project.scripts]
scicat_ingestor = "scicat_online_ingestor:main"
background_ingestor = "scicat_offline_ingestor:main"
validate_ingestor_config = "scicat_configuration:validate_config_file"
synchronize_config = "scicat_configuration:synchronize_config_file"
scicat_background_ingestor = "scicat_offline_ingestor:main"
scicat_validate_ingestor_config = "scicat_configuration:validate_config_file"
scicat_synchronize_config = "scicat_configuration:synchronize_config_file"

[project.entry-points."scicat_ingestor.metadata_extractor"]
max = "numpy:max"
Expand Down
14 changes: 13 additions & 1 deletion src/scicat_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ def _parse_nested_input_args(input_args: argparse.Namespace) -> dict:
_SHORTENED_ARG_NAMES = MappingProxyType(
{
"config-file": "c",
"ingestion.dry-run": "d",
}
)

_HELP_TEXT = {
"config-file": "Path to the configuration file.",
"ingestion.dry-run": "Dry run mode. No data will be sent to SciCat.",
}


def _wrap_arg_names(name: str, *prefixes: str) -> tuple[str, ...]:
long_name = (".".join((*prefixes, name)) if prefixes else name).replace("_", "-")
Expand Down Expand Up @@ -90,7 +96,13 @@ def _add_arguments(dataclass_tp: type, prefixes: tuple[str, ...] = ()) -> None:
for name, tp in atomic_types.items():
arg_names = _wrap_arg_names(name, *prefixes)
required = any(arg_name in mandatory_args for arg_name in arg_names)
arg_adder = partial(group.add_argument, *arg_names, required=required)
long_name = arg_names[-1].replace("--", "")
arg_adder = partial(
group.add_argument,
*arg_names,
required=required,
help=_HELP_TEXT.get(long_name),
)
if tp is bool:
arg_adder(action="store_true")
elif tp in (int, float, str):
Expand Down

0 comments on commit 64ea0b8

Please sign in to comment.