pydoit_nb.tasks_copy_source#
Generation of tasks for copying source into the outputs
ActionDef#
- class ActionDef(name, action, targets)[source]#
Bases:
objectDefinition of an action
-
action:
tuple[collections.abc.Callable[...,typing.Any],list[typing.Any],dict[str,typing.Any]]# Action to execute with doit
-
targets:
tuple[pathlib.Path,...]# Files that this action creates
-
action:
CopyReadmeCallable#
CopyZenodoCallable#
CopyFileCallable#
CopyTreeCallable#
GetPydoitNBRunCommandCallable#
gen_copy_source_into_output_tasks#
- gen_copy_source_into_output_tasks(all_preceeding_tasks, repo_root_dir, root_dir_output_run, run_id, root_dir_raw_notebooks, config_file_raw, readme='README.md', zenodo='zenodo.json', other_files_to_copy=('dodo.py', 'poetry.lock', 'pyproject.toml'), src_dir='src', copy_readme=None, copy_zenodo=None, copy_file=None, copy_tree=None)[source]#
Generate tasks to copy the source into the output directory
- Parameters:
all_preceeding_tasks (
collections.abc.Iterable[dict[str,typing.Any]]) – All tasks preceeding this one. The targets of these tasks are set as dependencies of this task to ensure that this task runs after them.repo_root_dir (
pathlib.Path) – Root directory of the repository. This is used to know where to copy files from.root_dir_output_run (
pathlib.Path) – Root directory of the run’s output. This is used to know where to copy files to.run_id (
str) – ID of the run.root_dir_raw_notebooks (
pathlib.Path) – Root directory to the raw notebooks (these are copied into the output bundle to ensure that the bundle can be run standalone)config_file_raw (
pathlib.Path) – Path to the raw configuration fileconfig_file_raw_output_name – Name to use when saving the raw configuration file to the output bundle (must be different to the hydrated configuration file to avoid a clash)
readme (
str) – Name of the README file to copy into the outputzenodo (
str) – Name of the zenodo JSON file to copy into the outputother_files_to_copy (
tuple[str|pathlib.Path,...]) – Other files to copy into the output (paths are assumed to be relative to the project’s root)src_dir (
str) – Path to the Python source (this is also copied into the output bundle)copy_readme (
typing.Optional[pydoit_nb.tasks_copy_source.CopyReadmeCallable]) – Callable that copies the README file into the output bundle. If not supplied, we usecopy_readme_default().copy_zenodo (
typing.Optional[pydoit_nb.tasks_copy_source.CopyZenodoCallable]) – Callable that copies the Zenodo JSON file into the output bundle. If not supplied, we usecopy_zenodo_default().copy_file (
typing.Optional[pydoit_nb.tasks_copy_source.CopyFileCallable]) – Callable that copies a file from one location to another. If not supplied, we usecopy_file_default().copy_tree (
typing.Optional[pydoit_nb.tasks_copy_source.CopyTreeCallable]) – Callable that copies a file tree from one location to another. If not supplied, we usecopy_tree_default().
- Yields:
Tasks for copying the source files into the output directory
- Return type:
get_copy_file_action_definitions#
- get_copy_file_action_definitions(repo_root_dir, root_dir_output_run, other_files_to_copy, copy_file)[source]#
Get action definitions for copying other files
- Parameters:
repo_root_dir (
pathlib.Path) – Root directory of the repository. This is used to know where to copy files from.root_dir_output_run (
pathlib.Path) – Root directory of the run’s output. This is used to know where to copy files to.other_files_to_copy (
tuple[str|pathlib.Path,...]) – Other files to copy into the output (paths are assumed to be relative to the project’s root)copy_file (
pydoit_nb.tasks_copy_source.CopyFileCallable) – Callable that copies a file from one location to another.
- Returns:
collections.abc.Iterable[pydoit_nb.tasks_copy_source.ActionDef] – Action definitions for copying the files- Raises:
ValueError – Any of the values in
other_files_to_copyis an absolute path. Paths inother_files_to_copyare assumed to be relative torepo_root_dirhence must be relative.
copy_readme_default#
- copy_readme_default(in_path, out_path, run_id, config_file_raw, raw_run_instruction='poetry run doit run --verbosity=2', get_pydoit_nb_run_command=None)[source]#
Copy the README into the output bundle
This is the default implementation. If you need other behaviour (for example, a different footer), write your own function then inject it as needed (e.g., into
gen_copy_source_into_output_tasks()).- Parameters:
in_path (
pathlib.Path) – Path to the raw README file (normally in the repository’s root directory)out_path (
pathlib.Path) – Path in which to write the README file (normally in the output bundle)run_id (
str) – ID of the run. This is injected into the written README as part of the footer.config_file_raw (
pathlib.Path) – Path to the raw configuration file, relative to the root output directoryraw_run_instruction (
str) – Instructions for how to run the workflow as they appear in the README. These are included to check that the instructions for running in the bundle are (likely) correct.get_pydoit_nb_run_command (
typing.Optional[pydoit_nb.tasks_copy_source.GetPydoitNBRunCommandCallable]) – Callable that can create the run command to put in the pydoit-nb specific section of the copied README (this often differs from the command that is in the README to handle different paths, configuration files etc.).
- Raises:
AssertionError – The run instructions in the README aren’t as expected hence the code injection likely won’t work as expected.
ValueError –
config_file_rawis an absolute path. It should always be a relative path to ensure portability.
- Return type:
get_pydoit_nb_run_command_default#
- get_pydoit_nb_run_command_default(config_file_raw, raw_run_instruction)[source]#
Get run command
This is the default implementation, based on how we have typically set up our pydoit-nb based repositories.
- Parameters:
config_file_raw (
pathlib.Path) – Path to raw configuration file as it should be used in the run commandraw_run_instruction (
str) – The command to run the analysis in the README (before the pydoit specific instructions are added).
- Returns:
str– Run command for use in the pydoit-nb created bundle
copy_zenodo_default#
- copy_zenodo_default(in_path, out_path, version)[source]#
Copy Zenodo JSON file to the output bundle
This is the default implementation that updates the version information too. If you need other behaviour, write your own function then inject it as needed (e.g., into
gen_copy_source_into_output_tasks()).More information about the metadata that can be uploaded via the zenodo API can be found under the “Deposit metadata” heading in the zenodo API docs.
- Parameters:
in_path (
pathlib.Path) – Path to raw Zenodo fileout_path (
pathlib.Path) – Path to output Zenodo file in the bundleversion (
str) – Version to write in the Zenodo file
- Return type: