corelp.main module

corelp.main()[source]

This function can decorate the main function of a script. User inputs parameters shoud be put in the beginning of the main file, and the decorated function will recognize them. Decorated function can change the values of these parameters with keyword arguments when called. Section can be created bellow the mainfunction.

Global parameters

import_pathPath or str or None

Path where to import script data to process. If None, will manually ask user to select it. If not existent, will be ignored.

export_pathPath or str or None

Path where to export script data to process. A new folder will be created inside at the call time as name. If None, will save in import_path. If not existent, will be ignored. If a previous call was already made in this same folder, and new is False, will try to reload data from this last folder.

newbool

Overrides Decorator new parameter.

bulkfunction

function(import_path) that returns a dictionnary of {import_subfolder:export_subfolder} for multiple decorated function run. If bulk is not None, the decorated function will run with import_subfolder, export_subfolder instead of import_path, export_path (see below). The import_subfolders and export_subfolder are defined from import_path and export_path respectively (they are not absolute from root path).

overnightbool

If True and exception occurs, will skip and pass to the next run in bulk processing. To use for example for overnight bulk processing.

run_namestr or None

Prefix to use for the output folder, if None takes the name of function decorated.

Examples

>>> from corelp import main
...
>>> import_path = None # will be asked via a GUI
>>> export_path = None # will create inside import_path
>>> new = False # True to create a new export folder, False to reload precalculated data
>>> bulk = None # function(import_path) that returns a dictionnary of {import_subfolder:export_subfolder} for multiple decorated function run.
>>> overnight= False # If True and exception occurs, will skip and pass to the next run in bulk processing.
>>> main_string = "Hello from main!" # User input parameter
...
>>> @main(new=True) # if previous new is not defined, new is defined here
... def myscript() :
...     print(main_string) # By default prints "Hello from main!"
...     result = mysection() # Section defined bellow, result can be reloaded from previous run
...     return result
...
... @main.section()
... def mysection() :
...     print("Hello from section!")
...     return True # Will be saved into export_path and can be reuploaded at next run with same inputs
...
>>> # Launch
>>> if __name__ == "__main__" :
...     myscript() # prints "Hello from main!"
...     myscript(main_string = "Hello changed!!") # prints "Hello changed!!" and loads section result from first run