pydoit_nb.tasks_copy_source#

Generation of tasks for copying source into the outputs

ActionDef#

class ActionDef(name, action, targets)[source]#

Bases: object

Definition of an action

action: tuple[collections.abc.Callable[..., typing.Any], list[typing.Any], dict[str, typing.Any]]#

Action to execute with doit

name: str#

Name of the action

targets: tuple[pathlib.Path, ...]#

Files that this action creates

CopyReadmeCallable#

class CopyReadmeCallable(*args, **kwargs)[source]#

Bases: Protocol

Callable which can be used for copying READMEs

CopyZenodoCallable#

class CopyZenodoCallable(*args, **kwargs)[source]#

Bases: Protocol

Callable which can be used for copying Zenodo JSON files

CopyFileCallable#

class CopyFileCallable(*args, **kwargs)[source]#

Bases: Protocol

Callable which can be used for copying files

CopyTreeCallable#

class CopyTreeCallable(*args, **kwargs)[source]#

Bases: Protocol

Callable which can be used for copying file trees

GetPydoitNBRunCommandCallable#

class GetPydoitNBRunCommandCallable(*args, **kwargs)[source]#

Bases: Protocol

Callable that supports inference of the run command to use with the pydoit-nb output bundle

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:
Yields:

Tasks for copying the source files into the output directory

Return type:

collections.abc.Iterable[dict[str, typing.Any]]

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_copy is an absolute path. Paths in other_files_to_copy are assumed to be relative to repo_root_dir hence 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 directory

  • raw_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.

  • ValueErrorconfig_file_raw is an absolute path. It should always be a relative path to ensure portability.

Return type:

None

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 command

  • raw_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 file

  • out_path (pathlib.Path) – Path to output Zenodo file in the bundle

  • version (str) – Version to write in the Zenodo file

Return type:

None