diff options
author | Frederick Muriuki Muriithi | 2022-07-29 04:00:41 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-07-29 04:00:41 +0300 |
commit | 6b11a267084c131ac7e1be76c4eb602996fd829e (patch) | |
tree | b5003378c4507016a13b9ac38db0e6f53f4d1629 /scripts/argparse_actions.py | |
parent | e3622ac213ef6e1be8a38959f7c6ee082c112c95 (diff) | |
download | genenetwork3-6b11a267084c131ac7e1be76c4eb602996fd829e.tar.gz |
New script to run sample correlations
* README.md: update mypy's invocation
* scripts/argparse_actions.py: new file - implement custom FileCheck action
for argparse
* scripts/sample_correlations.py: new file - implement new script to run
sample correlations in an external process
Diffstat (limited to 'scripts/argparse_actions.py')
-rw-r--r-- | scripts/argparse_actions.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/scripts/argparse_actions.py b/scripts/argparse_actions.py new file mode 100644 index 0000000..d1d1bfd --- /dev/null +++ b/scripts/argparse_actions.py @@ -0,0 +1,26 @@ +"Custom actions for argparse" +from pathlib import Path +from typing import Any, Union, Sequence, Optional +from argparse import Action, Namespace, ArgumentError, ArgumentParser + +class FileCheck(Action): + "Action class to check existence of a given file path." + + def __init__(self, option_strings, dest, **kwargs): + "Initialise the FileCheck action class" + super().__init__(option_strings, dest, **kwargs) + + def __call__(# pylint: disable=[signature-differs] + self, parser: ArgumentParser, namespace: Namespace, + values: Union[str, Sequence[Any], None], + option_string: Optional[str] = "") -> None: + """Check existence of a given file path and set it, or raise an + exception.""" + the_path = str(values or "") + the_file = Path(the_path) + if not the_file.is_file(): + raise ArgumentError( + self, + f"The file '{values}' does not exist or is a folder/directory.") + + setattr(namespace, self.dest, values) |