alleleTools.argtypes module
Custom argument types for argparse validation. It validates file paths, output paths and specific file formats.
- alleleTools.argtypes.check_dir_writable(directory: str) None[source]
Check if a directory is writable and valid.
- Parameters:
directory (str) – The directory path to check.
- Raises:
argparse.ArgumentTypeError – If the directory does not exist, is not writable, or is not a directory.
- alleleTools.argtypes.csv_file(in_string: str) str[source]
Validate that a CSV file exists and has the correct extension.
- Parameters:
in_string (str) – The CSV file path to validate.
- Returns:
The validated CSV file path string.
- Return type:
str
- Raises:
argparse.ArgumentTypeError – If the file doesn’t exist, is not a file, or doesn’t have a .csv extension.
Example
>>> csv_file("/path/to/data.csv") "/path/to/data.csv"
- alleleTools.argtypes.file_path(in_string: str) str[source]
Validate that a file exists and is actually a file (not a directory).
- Parameters:
in_string (str) – The file path to validate.
- Returns:
The validated file path string.
- Return type:
str
- Raises:
argparse.ArgumentTypeError – If the path doesn’t exist or is not a file.
Example
>>> file_path("/path/to/existing_file.txt") "/path/to/existing_file.txt"
- alleleTools.argtypes.output_path(in_string: str) str[source]
Validate that the output directory exists and the file doesn’t already exist.
- Parameters:
in_string (str) – The output file path to validate.
- Returns:
The validated output path string.
- Return type:
str
- Raises:
argparse.ArgumentTypeError – If the parent directory doesn’t exist or if the file already exists.
Example
>>> output_path("/existing/dir/new_file.txt") "/existing/dir/new_file.txt"
- alleleTools.argtypes.path(in_string: str) str[source]
Validate that a given path exists.
- Parameters:
in_string (str) – The path string to validate.
- Returns:
The validated path string.
- Return type:
str
- Raises:
argparse.ArgumentTypeError – If the path does not exist.
Example
>>> path("/existing/path") "/existing/path"