API Documentation

This documentation covers the interfaces exposed by Pyrepo.


class pyrepo.repo.Repository(command=None, url=None, import_path=None)[source]

Representation of a repository which is managed by a Command object, and hosted at some url.

A Repository object may be constructed from a command and url directly, or a respository import_path can be provided which will resolve the command or url, if they aren’t provided.


from pyrepo import git_command as git

repo = Repository(command=git, 

# autodetects the correct repository url
repo = Repository(command=git, 

# autdetects the correct command and repository url
repo = Repository(import_path='github.com/dghubble/pyrepo')

Provide either the command and url or provide an import_path.

  • command (Command) – (optional) Command for managing the repository
  • url (str) – (optional) url where the repo can be found
  • import_path (str) – (optional) import path of the repository (e.g. github.com/dghubble/pyrepo)

ValueError, ImportPathError

clone(*args, **kwargs)[source]

Calls Command.clone with the repository url positional argument, followed by the given positional args and keyword kwargs.


target_dir = os.path.expanduser('~')
# clone the repository into the target directory (e.g. home)
update(*args, **kwargs)[source]

Arguments are the same as Command.update arguments.

tag_list(*args, **kwargs)[source]

Arguments are the same as Command.tag_list arguments.

class pyrepo.repo.RepoImporter(hosts=None, commands=None)[source]

Utility for resolving an import path to a url and a Command.

  • hosts (list) – list of Host objects to compare import paths against. Defaults to default_hosts.
  • commands (list) – list of Command objects to consider. Defaults to default_commands.

Resolves an import path to a (Command, url) tuple.

Parameters:import_path (str) – import path identifying a repository.
Returns:(Command, url) tuple corresponding to the import_path

Checks the import_path against hosts by matching starting characters against the host’s prefix and matching the full import_path against the host’s pattern.

Parameters:import_path (str) – import path identifying a repository
Returns:matching Host
_match_command(import_path, host)[source]

Determines the name of the command that should be used to interact with the host‘s import_path repository. Simple hosts have a command_name that should be used (e..g. Github -> git). More complex hosts call command_name_func to determine the command name to use for the repository.

  • import_path (str) – import path identifying a repository
  • hostHost of the repository, based on the import_path

name of the Command for interacting with the repository



_build_url(import_path, host, scheme)[source]

Constructs the url from which the import_path repository can be fetched.

  • import_path (str) – import path identifying a repository
  • hostHost of the repository, based on the import_path
  • scheme (str) – url scheme of the repository
exception pyrepo.repo.ImportPathError[source]

Raised when a RepoImporter cannot resolve an import_path.


class pyrepo.commands.Command(**kwargs)[source]

Represents a repository management command (e.g. Git, Mercurial) and its usage.

Make a repository management command.

  • name (str) – executable binary command name (e.g. ‘hg’)
  • long_name (str) – long command name (e.g. ‘Mercurial’)
  • init_cmd (str) – command to initialize a repository
  • add_cmd (str) – command to add a {path} to staging
  • commit_cmd (str) – commit a changeset to the repo with a commit {message}
  • create_cmd (str) – command to clone a fresh repository copy from {repo_url} to {target_path}
  • update_cmd (str) – command to download updates into existing repository
  • tag_list_cmd (TagCommand) – command to list repository tags
  • tag_sync_cmd (str) – command to sync to a specific tag
  • tag_sync_default_cmd (str) – command to sync to the default tag
  • schemes (list) – scheme names
  • ping_cmd (str) – command to ping for scheme

Initializes a repository in the given directory.

clone(repo_url, target_path)[source]

Runs the command to clone/create a new repository. :params repi_url: url to remote repo or path to local repo :params target: path to intended destination for repo


Runs the command to update a repo, from the given cwd directory


Runs the command to list tags, from the given cwd directory.

ping(scheme, repo, cwd='.')[source]
class pyrepo.commands.TagCommand(cmd, pattern)[source]

Represents a command to list tags to sync onto.

  • cmd – command to list tags
  • pattern – regex to extract tags
pyrepo.commands.git_command = <pyrepo.commands.Command object>

Git command definition

pyrepo.commands.hg_command = <pyrepo.commands.Command object>

Mercurial command definition

pyrepo.commands.default_commands = [<pyrepo.commands.Command object>, <pyrepo.commands.Command object>]

default set of commands for repositories


class pyrepo.hosts.Host(command_name_func=None, **kwargs)[source]

Represents a host of repositories and how import_path identifiers of repositories are mapped to the host’s urls.

  • name (str) – name of the repository host
  • prefix (str) – prefix to matching import paths should have
  • pattern (str) – regex pattern for the import path
  • command_name (str) – name of the command for interacting with hosted repositories
  • command_name_func (func) – func(import_path) which returns the str name of a command to be used for the host’s import_path repository. May raise ImportPathError. Defaults to None and command_name is used directly.
  • url_format (str) – format string for the repository url, which should contain a import_path format specifier.


pyrepo.hosts.github_host = <pyrepo.hosts.Host object>

github.com repository host definition

pyrepo.hosts.bitbucket_host = <pyrepo.hosts.Host object>

bitbucket.org repository host definition

pyrepo.hosts.default_hosts = [<pyrepo.hosts.Host object>, <pyrepo.hosts.Host object>]

default set of repository hosts