muteria.repositoryandcode.repository_manager module¶
This module implememts the class RepositoryManager which manages all the access to the project repository. An important use of the class is to avoid races during parallel processing. This also implements methods to keep track of the changes made to the repository during executions: (the repository is backed before any execution and can be restored after)
Each method that manipulate the repository, except backing up and restoring, take one or two optional callback functions and callback arguments as last arguments (callback function mandatory only for custom_read_access), which will be called after locking the repository, with the last parameters:
repository root dir
executable relative path w.r.t the repository root dir
- list of source files of interest
(as relative path from repository root dir)
list of developer test cases of interest
Callbacks signature: :param op_retval: value return by the operation before the callback.
None is the value if no operation occured (ex: RepositorManager.custom_access) Note: this is only present for post processing callbacks
- param callback_args:
data object as understandable by the callback. The same data is passed to the method of RepositoryManager that call the call back. it is then passed to the callback without any change.
- param str repository_rootdir:
full path to the repository root
- param str repo_executables_relpaths:
relative path to the executable w.r.t the repository root dir
- param list source_files_list:
list of source files we care about. each item of the list is a relative path to a source file w.r.t. the repository root dir
- param list dev_tests_list:
list of developer tests we care about. each item of the list is a relative path to a test file w.r.t. the repository root dir.
- return:
The returned value is the returned value of the operation before the call back (in case the callback function is None), or the returned value of the callback function.
>>> def post_process_callback(op_retval, callback_args, repository_rootdir, repo_executables_relpaths, source_files_list, dev_tests_list)
- TODO: IMPORTANT BEFORE ANY PARALLELISM: make sure to avoid deadlock
and release the lock when there is failure (call to error_exit). Implement tools with subprocess for parallelism so as to kill all the subprocess upon error_exit, or continue until join.
- class muteria.repositoryandcode.repository_manager.RepositoryManager(repository_rootdir, repo_executables_relpaths=None, dev_test_runner_func=None, code_builder_func=None, dev_test_program_wrapper=None, test_exec_output_cleaner_func=None, source_files_to_objects=None, dev_tests_list=None, delete_created_on_revert_as_initial=False, test_branch_name='_tests_tmp_muteria_')[source]¶
Bases:
object- DEFAULT_MUTERIA_REPO_META_FOLDER = '.muteria'¶
- DEFAULT_TESTS_BRANCH_NAME = '_tests_tmp_muteria_'¶
- build_code(compiler=None, flags_list=None, clean_tmp=False, reconfigure=False, callback_object=None)[source]¶
Build the code in repository dir to obtain the executable
- type compiler:
str
- param compiler:
name of the compiler to usei. default to None.
- type flags_list:
list
- param flags_list:
list of strings to use as compiler flags. default to None.
- type clean_tmp:
bool
- param clean_tmp:
enable clean any build temporary files, such as object files in C/C++ . Default to False.
:type
- econfigure: bool
:param
- econfigure: enable reconfigure the project repository before
building. may be usefule if using a different compiler on different runs. default to False.
- type pre_process_callback:
funtion
- param pre_process_callback:
function that will be called before the code is build. the first argument is the pre_callback_args passed to the function. the remaining four arguments are the project element (repos rootdir absolute path, executable relative path, list of source files, list of developer tests). Default to None. The build script and post_process_callback are called if and only if this function return True.
- type pre_callback_args:
anything
- param pre_callback_args:
data that will be passed (untouched) to the callback function pre_process_callback. Default to None.
- type post_process_callback:
funtion
- param post_process_callback:
function that will be called after the code is build. The call pass first the returned value of the build (True is succeed, False if failed). the second argument is the callback_args passed to the function. the remaining four arguments are the project element (repos rootdir absolute path, executable relative path, list of source files, list of developer tests). Default to None.
- type post_callback_args:
anything
- param post_callback_args:
data that will be passed (untouched) to the callback function post_process_callback. Default to None.
- raises:
Terminates execution with error if the specified self.code_builder_func is None.
- rtype:
The returned value is the pair of returned value of pre_process_callback and post_process_callback. if pre_process_callback is None, the default return is True. if post_process_callback is None, the default return is None.
- custom_read_access(callback_object)[source]¶
- Execute the read only callback function and
return its returned value
- Parameters:
process_callback (function) – function that will be called after the code is build. The call pass first the returned value of the build (True is succeed, False if failed). the second argument is the callback_args passed to the function. the remaining four arguments are the project element (repos rootdir absolute path, executable relative path, list of source files, list of developer tests). Default to None.
callback_args (anything) – data that will be passed (untouched) to the callback function process_callback. Default to None.
- Raises:
error if process_callback is None
- Return type:
any