radis.misc.utils module¶

@author: Erwan


class Chdir(newPath)[source]¶

Bases: object

because we need to change directory to get into the RADIS folder to find the Git files and version, when imported from another program. This class then ensures we get back in the correct directory.

Examples

Do:

cd = Chdir(os.path.dirname(__file__))
try:
    (...)
except:
    (...)
finally:
    (...)
    cd.__del__()
exception DatabankNotFound[source]¶

Bases: FileNotFoundError

Used when a line database is not found in radis.rc.

class Default(value)[source]¶

Bases: object

Contains a value. Used to know whether a function argument equal to its default value was explicitely given by the user or not. This allows to prevent user errors.

Examples

Check if a value is Default:

from radis.misc.utils import Default
a = Default("42")
isinstance(a, Default)
>>> True

a.value
>>> 42
class NotInstalled(name, info='')[source]¶

Bases: object

A class to deal with optional packages Will raise an error only if the package is used (but not if imported only)

Examples

some function = NotInstalled("you should install C drivers")
a = some_function   # no error
a()             # will raise the NotInstalled error and display the message
getProjectRoot()[source]¶

Return the full path of the project root.

get_default_arg(func, arg)[source]¶

Get default value of argument arg in function func

Adapted from https://stackoverflow.com/questions/12627118/get-a-function-arguments-default-value

get_files_from_regex(path)[source]¶

Returns a list of absolute paths of all the files whose names match the input regular expression.

getarglist(function)[source]¶

Get list of arguments in a function.

See https://stackoverflow.com/a/41188411/5622825

import_from_module(module, name)[source]¶

Import object ‘name’ from module ‘module’ raises AttributeError if name doesnt exist.

Parameters

module, name (str) – module path, object name