githandler

Wrappers for interacting with git

Functions

install_gpg_key(key)

Install GPG key

Classes

BiocondaRepo([folder, dry_run, home, fork, ...])

BiocondaRepoMixin(repo, dry_run[, home, ...])

Githandler with logic specific to Bioconda Repo

GitHandler([folder, dry_run, home, fork, ...])

GitHandler for working with a pre-existing local checkout of bioconda-recipes

GitHandlerBase(repo, dry_run[, home, fork, ...])

GitPython abstraction

TempBiocondaRepo([username, password, ...])

TempGitHandler([username, password, ...])

GitHandler for working with temporary working directories created on the fly

Exceptions

GitHandlerFailure

Something went wrong interacting with git

Documentation

bioconda_utils.githandler.install_gpg_key(key)[source]

Install GPG key

Parameters:

key – Key to import to GPG as string

Return type:

str

Returns:

GPG key ID

Raises:

ValueError if importing the key failed

exception bioconda_utils.githandler.GitHandlerFailure[source]

Something went wrong interacting with git

class bioconda_utils.githandler.GitHandlerBase(repo, dry_run, home='bioconda/bioconda-recipes', fork=None, allow_dirty=False)[source]

GitPython abstraction

We have to work with three git repositories, the local checkout, the project primary repository and a working repository. The latter may be a fork or may be the same as the primary.

Parameters:
  • repo (Repo) – GitPython Repo object (created by subclasses)

  • dry_run (bool) – Don’t push anything to remote

  • home – string occurring in remote url marking primary project repo

  • fork – string occurring in remote url marking forked repo

  • allow_dirty – don’t bail out if repo is dirty

repo: Repo

GitPython Repo object representing our repository

dry_run

Dry-Run mode - don’t push or commit anything

home_remote

Remote pointing to primary project repo

fork_remote

Remote to pull from

lock_working_dir

Semaphore for things that mess with working directory

actor: Actor

Committer and Author

close()[source]

Release resources allocated

enable_signing(key=True)[source]

Enable signing of commits

Parameters:

key (Union[bool, str]) – Keyid to use for signing. Set to True to enable using the default key or to False to disable signing.

Return type:

None

get_remote(desc)[source]

Finds first remote containing desc in one of its URLs

async branch_is_current(branch, path, master='master')[source]

Checks if branch has the most recent commit modifying path as compared to master

Return type:

bool

delete_local_branch(branch)[source]

Deletes branch locally

Return type:

None

delete_remote_branch(branch_name)[source]

Deletes branch on fork remote

Return type:

None

get_local_branch(branch_name)[source]

Finds local branch named branch_name

static is_sha(ref)[source]

Checks if ref is a commit checksum

Verifies that ref is a hex value of length 40

Return type:

bool

get_remote_branch(branch_name, try_fetch=False)[source]

Finds fork remote branch named branch_name

read_from_branch(branch, file_name)[source]

Reads contents of file file_name from git branch branch

Return type:

str

create_local_branch(branch_name, remote_branch=None)[source]

Creates local branch from remote branch_name

get_merge_base(ref=None, other=None, try_fetch=False)[source]

Determines the merge base for other and ref

See git merge-base. Returns the commit at which ref split from other and from which point on changes would be merged.

Parameters:
  • ref – One of the two tips for which a merge base is sought. Defaults to the currently checked out HEAD. This is the second argument to git merge-base.

  • other – One of the two tips for which a merge base is sought. Defaults to origin/master (home_remote). This is the first argument to git merge-base.

Returns:

The first merge base for the two references provided if found. May return None if no merge base was found. This may for example be the case if branches were deleted or if the repository is shallow and the merge base commit not available.

list_changed_files(ref=None, other=None)[source]

Lists files that would be added/modified by merge of other into ref

See also get_merge_base().

Parameters:
  • ref – Defaults to HEAD (active branch), one of the tips compared

  • other – Defaults to origin/master, other tip compared

Returns:

Generator over modified or created (not deleted) files.

list_modified_files()[source]

Lists files modified in working directory

prepare_branch(branch_name)[source]

Checks out branch_name, creating it from home remote master if needed

Return type:

None

commit_and_push_changes(files, branch_name, msg, sign=False)[source]

Create recipe commit and pushes to upstream remote

Return type:

bool

Returns:

Boolean indicating whether there were changes committed

set_user(user, email=None)[source]

Set the user and email to use for committing

Return type:

None

class bioconda_utils.githandler.BiocondaRepoMixin(repo, dry_run, home='bioconda/bioconda-recipes', fork=None, allow_dirty=False)[source]

Githandler with logic specific to Bioconda Repo

recipes_folder = 'recipes'

location of recipes folder within repo

config_file = 'config.yml'

location of configuration file within repo

get_changed_recipes(ref=None, other=None, files=None)[source]

Returns list of modified recipes

Parameters:
  • ref – See get_merge_base. Defaults to HEAD

  • other – See get_merge_base. Defaults to origin/master

  • files – List of files to consider. Defaults to meta.yaml and build.sh

Result:

List of unique recipe folders with changes. Path is from repo root (e.g. recipes/blast). Recipes outside of recipes_folder are ignored.

get_blacklisted(ref=None)[source]

Get blacklisted recipes as of ref

Parameters:

ref – Name of branch or commit (HEAD~1 is allowed), defaults to currently checked out branch

Returns:

set of blacklisted recipes (full path to repo root)

get_unblacklisted(ref=None, other=None)[source]

Get recipes unblacklisted by a merge of ref into other

Parameters:
  • ref – Branch or commit or reference, defaults to current branch

  • other – Same as ref, defaults to origin/master

Returns:

set of unblacklisted recipes (full path to repo root)

get_recipes_to_build(ref=None, other=None)[source]

Returns list of recipes to build for merge of ref into other

This includes all recipes returned by get_changed_recipes and all newly unblacklisted, extant recipes within recipes_folder

Returns:

list of recipes that should be built

repo: Repo

GitPython Repo object representing our repository

actor: Actor

Committer and Author

class bioconda_utils.githandler.GitHandler(folder='.', dry_run=False, home='bioconda/bioconda-recipes', fork=None, allow_dirty=True, depth=1)[source]

GitHandler for working with a pre-existing local checkout of bioconda-recipes

Restores the branch active when created upon calling close().

checkout_master()[source]

Check out master branch (original branch restored by close())

close()[source]

Release resources allocated

Return type:

None

repo: Repo

GitPython Repo object representing our repository

actor: Actor

Committer and Author

class bioconda_utils.githandler.TempGitHandler(username=None, password=None, url_format='https://{userpass}github.com/{user}/{repo}.git', home_user='bioconda', home_repo='bioconda-recipes', fork_user=None, fork_repo=None, dry_run=False)[source]

GitHandler for working with temporary working directories created on the fly

Throw-away copies of a git repo as provided by this class are useful when we might be working in multiple threads and want to avoid blocking waits for a single repo. It also improves robustness: If something goes wrong with this repo, it will not break the entire process.

classmethod set_mirror_dir(dirname)[source]

Set directory where repo mirrors are kept for caching

Use this if you want to preserve a cache across invocations of the Python interpreter.

Parameters:

dirname (str) – Name of directory in which remote repos will be cached.

Return type:

None

close()[source]

Remove temporary clone and cleanup resources

Return type:

None

class bioconda_utils.githandler.BiocondaRepo(folder='.', dry_run=False, home='bioconda/bioconda-recipes', fork=None, allow_dirty=True, depth=1)[source]
repo: Repo

GitPython Repo object representing our repository

actor: Actor

Committer and Author

class bioconda_utils.githandler.TempBiocondaRepo(username=None, password=None, url_format='https://{userpass}github.com/{user}/{repo}.git', home_user='bioconda', home_repo='bioconda-recipes', fork_user=None, fork_repo=None, dry_run=False)[source]