Skip to content

Commit

Permalink
Redesign the template of nplinker config file
Browse files Browse the repository at this point in the history
This PR redesigned the template of nplinker config file `nplinker.toml`.

The new design does not allow users to specify the path to their data files, instead they should always put data files to default paths defined by NPLinker (the default paths will be provided in the next PR).

To keep it simple, some settings related to code that has not been refactored are not included in the new design. They can be added later if really needed.


### Major changes:
- redesign the template of config file `nplinker.toml`.
- update default config values in `nplinker_default.toml`
- add validations for all configs/settings
- update unit tests for new configs/settings

Note: This PR only updated the template config file, but the usage of the configs in relevant code is not updated. Next PR will update the usage. So it's OK to see the failed test tests on `tests/scorings` and `tests/test_nplinker_local.py` .
  • Loading branch information
CunliangGeng authored Feb 27, 2024
1 parent a0b5883 commit 0e7138b
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 359 deletions.
44 changes: 40 additions & 4 deletions src/nplinker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,46 @@
# Validataor parameter `required=False` means the setting (e.g. "loglevel") must not exist rather
# than being optional. So don't set the parameter `required` if the key is optional.
validators = [
Validator("loglevel", is_type_of=str),
Validator("logfile", is_type_of=str),
Validator("repro_file", is_type_of=str),
Validator("log_to_stdout", is_type_of=bool),
# General settings
## `root_dir` value is transformed to a `pathlib.Path` object and must be a directory.
Validator("root_dir", required=True, cast=Path, condition=lambda v: v.is_dir()),
Validator("mode", required=True, cast=lambda v: v.lower(), is_in=["local", "podp"]),
## `podp_id` must be set if `mode` is "podp"; must not be set if `mode` is "local".
Validator("podp_id", required=True, when=Validator("mode", eq="podp")),
Validator("podp_id", required=False, when=Validator("mode", eq="local")),
# Log
## `loglevel` must be a string and must be one of the supported levels. It is transformed to
## uppercase to avoid case sensitivity.
Validator(
"log.level",
is_type_of=str,
cast=lambda v: v.upper(),
is_in=["NOTSET", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
),
Validator("log.file", is_type_of=str, cast=Path),
Validator("log.to_stdout", is_type_of=bool),
# Mibig
Validator("mibig.to_use", required=True, is_type_of=bool),
Validator(
"mibig.version",
required=True,
is_type_of=str,
when=Validator("mibig.to_use", eq=True),
),
# BigScape
Validator("bigscape.parameters", required=True, is_type_of=str),
Validator("bigscape.cutoff", required=True, is_type_of=float),
# Scoring
## `scoring.methods` must be a list of strings and must contain at least one of the
## supported scoring methods.
Validator(
"scoring.methods",
required=True,
cast=lambda v: [i.lower() for i in v],
is_type_of=list,
len_min=1,
condition=lambda v: set(v).issubset({"metcalf", "rosetta"}),
),
]
config.validators.register(*validators)
config.validators.validate()
Loading

0 comments on commit 0e7138b

Please sign in to comment.