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

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

Bases: bioconda_utils.githandler.GitHandler, bioconda_utils.githandler.BiocondaRepoMixin

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

Bases: bioconda_utils.githandler.GitHandlerBase

Githandler with logic specific to Bioconda Repo

config_file = 'config.yml'

location of configuration file within repo

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_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_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

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)

recipes_folder = 'recipes'

location of recipes folder within repo

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

Bases: bioconda_utils.githandler.GitHandlerBase

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

prev_active_branch = None

Branch to restore after running

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

Bases: object

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

actor = None

Committer and Author

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

close()[source]

Release resources allocated

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

create_local_branch(branch_name, remote_branch=None)[source]

Creates local branch from remote branch_name

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

dry_run = None

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

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

fork_remote = None

Remote to pull from

get_local_branch(branch_name)[source]

Finds local branch named 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.

get_remote(desc)[source]

Finds first remote containing desc in one of its URLs

get_remote_branch(branch_name, try_fetch=False)[source]

Finds fork remote branch named branch_name

home_remote = None

Remote pointing to primary project repo

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

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

lock_working_dir = None

Semaphore for things that mess with working directory

prepare_branch(branch_name)[source]

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

Return type

None

read_from_branch(branch, file_name)[source]

Reads contents of file file_name from git branch branch

Return type

str

repo = None

GitPython Repo object representing our repository

set_user(user, email=None)[source]

Set the user and email to use for committing

Return type

None

exception bioconda_utils.githandler.GitHandlerFailure[source]

Bases: Exception

Something went wrong interacting with git

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]

Bases: bioconda_utils.githandler.TempGitHandler, bioconda_utils.githandler.BiocondaRepoMixin

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]

Bases: bioconda_utils.githandler.GitHandlerBase

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.

close()[source]

Remove temporary clone and cleanup resources

Return type

None

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

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