Package schrodinger :: Package application :: Package matsci :: Module parserutils
[hide private]
[frames] | no frames]

Module parserutils

Utilities for working with argument parsers

Copyright Schrodinger, LLC. All rights reserved.

Functions [hide private]
float or int
type_ranged_num(arg, top=None, bottom=0.0, top_allowed=False, bottom_allowed=False, typer=<type 'float'>)
Validate that the argument is a number over a given range.
 
type_ranged_int(*args, **kwargs)
Validate that the argument is an int over a given range
 
type_positive_float(arg)
Validate that the argument is a positive float
 
type_positive_int(arg)
Validate that the argument is a positive int
str
type_file(arg)
Validate that the argument is an existing filename
Variables [hide private]
  __package__ = 'schrodinger.application.matsci'
Function Details [hide private]

type_ranged_num(arg, top=None, bottom=0.0, top_allowed=False, bottom_allowed=False, typer=<type 'float'>)

 

Validate that the argument is a number over a given range.

Parameters:
  • arg (str) - The argument to validate
  • top (float or int) - The upper limit of the allowed range
  • bottom (float or int) - The lower limit of the allowed range
  • top_allowed (bool) - Whether arg may take the top value or not (whether the upper limit is inclusive or exclusive)
  • bottom_allowed (bool) - Whether arg may take the bottom value or not (whether the bottom limit is inclusive or exclusive)
  • typer (callable) - Should be one of the built-in float or int functions and defines the type of the value returned from this function.
Returns: float or int
The argument converted to a float or int, depending on the value of the typer keyword argument

@raise argparse.ArgumentTypeError: If the argument cannot be converted to a ranged floating point number in the given range

type_ranged_int(*args, **kwargs)

 

Validate that the argument is an int over a given range

see type_ranged_num for documentation of arguments, return values and exceptions raised

type_positive_float(arg)

 

Validate that the argument is a positive float

see type_ranged_num for documentation of arguments, return values and exceptions raised

type_positive_int(arg)

 

Validate that the argument is a positive int

see type_ranged_num for documentation of arguments, return values and exceptions raised

type_file(arg)

 

Validate that the argument is an existing filename

Parameters:
  • arg (str) - The argument to validate
Returns: str
The unaltered argument

@raise argparse.ArgumentTypeError: If the given filename does not exist