import_git_files module

Import files from one or more git repositories to local destinations.

class import_git_files.GitExtractedFiles(git_url: str, source_destination_map: Mapping[str, str], **kwargs)[source]

Bases: object

Clone a repository into a temporary directory and then copy files out of it to new, final destinations locally. If the repository is private and requires authentication, either interactively enter the credentials or define ssh_key_path for a deploy key or token for personal access token to enable non-interactive authentication. This class is a context manager ( with GitExtractedFiles(…) as alias:) to be able to operate on the temporary directory containing the cloned repository before it is removed and the return value in the alias is the list of Paths.

Parameters
  • git_url (str) – a git repo URL. The default behavior checks out the default branch or the URL can be suffixed with @{revision} to specify a commit sha, branch, tag, or release.

  • source_destination_map (Mapping[str, str]) – a dictionary defining the source file path as keyword, relative to the root of the repository, and its value as an absolute path or relative path to PWD of where the file should be copied.

Keyword Arguments
  • ssh_key_path – git SSH access key path. This SSH key could be a deploy key. This file should have permissions 600 or will fail. If this is defined, there is not a need to change URLs from HTTPS to SSH as this will update those URLs before doing the clone. This cannot be defined at the same time as token.

  • token – GitHub Personal Access Token optionally provided as a way to authenticate against private registries. Default will use the current git login, so this method is useful in non-interactive methods that are not already logged in and do not support SSH deploy keys. This cannot be defined at the same time as token.

  • temp_dir_base – Optionally define the parent directory path where the temporary directory should be created rather than relying on systems’ defined tmpfs.

Returns

List of PosixPaths for the destination paths of the new files

clone_repo()[source]

Clone the repository. Checkout branch or revision if specified

copy_content() → Iterator[Union[pathlib.Path, os.PathLike]][source]

Copy the files from the cloned repository to a new destination. The source is relative to the repo root location (temporary directory) and the destination can be absolute or relative to the PWD.

static create_parents(path: str)[source]

Create parent directories for the destination path if they don’t already exist.

static get_git(git_url: str) → Tuple[str, Optional[str]][source]

GitPython doesn’t support @revision URLs, so detect when that is specified and split it up to get the base URL and revision separated.

Parameters

git_url (str) – git url which can include the revision (commit sha, branch, tag, or release) with @revision style suffixing the git URL.

Returns

base_git_url, revision if defined else None

import_git_files.command_line()[source]

Command-line interface.

Returns

arguments via a parser.parse_args() object

import_git_files.main()[source]

Main entry point when invoking script via CLI.