Downloader Framework¶
Info.json¶
The optional info.json file may exist inside every package folder in the repo, as well as in the root of the repo. The following sections describe the valid keys within an info file (and maybe how the Downloader cog uses them).
Keys common to both repo and cog info.json (case sensitive)¶
author
(list of strings) - list of names of authors of the cog or repo.description
(string) - A long description of the cog or repo. For cogs, this is displayed when a user executes!cog info
.install_msg
(string) - The message that gets displayed when a cog is installed or a repo is addedTip
You can use the
[p]
key in your string to use the prefix used for installing.short
(string) - A short description of the cog or repo. For cogs, this info is displayed when a user executes!cog list
Keys specific to the cog info.json (case sensitive)¶
min_bot_version
(string) - Min version number of Red in the formatMAJOR.MINOR.MICRO
max_bot_version
(string) - Max version number of Red in the formatMAJOR.MINOR.MICRO
, ifmin_bot_version
is newer thanmax_bot_version
,max_bot_version
will be ignoredhidden
(bool) - Determines if a cog is visible in the cog list for a repo.disabled
(bool) - Determines if a cog is available for install.required_cogs
(map of cogname to repo URL) - A map of required cogs that this cog depends on. Downloader will not deal with this functionality but it may be useful for other cogs.requirements
(list of strings) - list of required libraries that are passed to pip on cog install.SHARED_LIBRARIES
do NOT go in this list.tags
(list of strings) - A list of strings that are related to the functionality of the cog. Used to aid in searching.type
(string) - Optional, defaults toCOG
. Must be eitherCOG
orSHARED_LIBRARY
. IfSHARED_LIBRARY
thenhidden
will beTrue
.
API Reference¶
Installable¶
-
class
redbot.cogs.downloader.installable.
Installable
(location)[source]¶ Bases:
redbot.cogs.downloader.json_mixins.RepoJSONMixin
Base class for anything the Downloader cog can install.
- Modules
- Repo Libraries
- Other stuff?
The attributes of this class will mostly come from the installation’s info.json.
-
bot_version
¶ The minimum bot version required for this installation. Right now this is always
3.0.0
.Type: tuple
ofint
-
min_python_version
¶ The minimum python version required for this cog. This field will not apply to repo info.json’s.
Type: tuple
ofint
Whether or not this cog will be hidden from the user when they use
Downloader
’s commands.Type: bool
-
required_cogs
¶ In the form
{cog_name : repo_url}
, these are cogs which are required for this installation.Type: dict
-
await
copy_to
(target_dir) → bool[source]¶ Copies this cog/shared_lib to the given directory. This will overwrite any files in the target directory.
Parameters: target_dir (pathlib.Path) – The installation directory to install to. Returns: Status of installation Return type: bool
Repo¶
-
class
redbot.cogs.downloader.repo_manager.
Repo
(name, url, branch, folder_path, available_modules = (), loop = None)[source]¶ Bases:
redbot.cogs.downloader.json_mixins.RepoJSONMixin
-
available_cogs
¶ All available cogs in this Repo.
This excludes hidden or shared packages.
Type: tuple
ofinstallable
-
available_libraries
¶ All available shared libraries in this Repo.
Type: tuple
ofinstallable
-
await
clone
() → Tuple[str][source]¶ Clone a new repo.
Returns: All available module names from this repo. Return type: tuple
ofstr
-
await
current_branch
() → str[source]¶ Determine the current branch using git commands.
Returns: The current branch name. Return type: str
-
await
current_commit
(branch = None) → str[source]¶ Determine the current commit hash of the repo.
Parameters: branch ( str
, optional) – Override for repo’s branch attribute.Returns: The requested commit hash. Return type: str
-
await
current_url
(folder = None) → str[source]¶ Discovers the FETCH URL for a Git repo.
Parameters: folder (pathlib.Path) – The folder to search for a URL. Returns: The FETCH URL. Return type: str Raises: NoRemoteURL – When the folder does not contain a git repo with a FETCH URL.
-
await
hard_reset
(branch = None) → None[source]¶ Perform a hard reset on the current repo.
Parameters: branch ( str
, optional) – Override for repo branch attribute.
-
await
install_cog
(cog, target_dir) → bool[source]¶ Install a cog to the target directory.
Parameters: - cog (Installable) – The package to install.
- target_dir (pathlib.Path) – The target directory for the cog installation.
Returns: The success of the installation.
Return type:
-
await
install_libraries
(target_dir, req_target_dir, libraries = ()) → bool[source]¶ Install shared libraries to the target directory.
If
libraries
is not specified, all shared libraries in the repo will be installed.Parameters: - target_dir (pathlib.Path) – Directory to install shared libraries to.
- req_target_dir (pathlib.Path) – Directory to install shared library requirements to.
- libraries (
tuple
ofInstallable
) – A subset of available libraries.
Returns: The success of the installation.
Return type:
-
await
install_raw_requirements
(requirements, target_dir) → bool[source]¶ Install a list of requirements using pip.
Parameters: - requirements (
tuple
ofstr
) – List of requirement names to install via pip. - target_dir (pathlib.Path) – Path to directory where requirements are to be installed.
Returns: Success of the installation
Return type: - requirements (
-
await
install_requirements
(cog, target_dir) → bool[source]¶ Install a cog’s requirements.
Requirements will be installed via pip directly into
target_dir
.Parameters: - cog (Installable) – Cog for which to install requirements.
- target_dir (pathlib.Path) – Path to directory where requirements are to be installed.
Returns: Success of the installation.
Return type:
-
Repo Manager¶
-
class
redbot.cogs.downloader.repo_manager.
RepoManager
[source]¶ Bases:
object
-
await
add_repo
(url, name, branch = None) → redbot.cogs.downloader.repo_manager.Repo[source]¶ Add and clone a git repository.
Parameters: Returns: New Repo object representing the cloned repository.
Return type:
-
await
delete_repo
(name)[source]¶ Delete a repository and its folders.
Parameters: name (str) – The name of the repository to delete. Raises: MissingGitRepo – If the repo does not exist.
-
await
Exceptions¶
-
exception
redbot.cogs.downloader.errors.
DownloaderException
[source]¶ Bases:
Exception
Base class for Downloader exceptions.
-
exception
redbot.cogs.downloader.errors.
GitException
[source]¶ Bases:
redbot.cogs.downloader.errors.DownloaderException
Generic class for git exceptions.
-
exception
redbot.cogs.downloader.errors.
InvalidRepoName
[source]¶ Bases:
redbot.cogs.downloader.errors.DownloaderException
Throw when a repo name is invalid. Check the message for a more detailed reason.
-
exception
redbot.cogs.downloader.errors.
ExistingGitRepo
[source]¶ Bases:
redbot.cogs.downloader.errors.DownloaderException
Thrown when trying to clone into a folder where a git repo already exists.
-
exception
redbot.cogs.downloader.errors.
MissingGitRepo
[source]¶ Bases:
redbot.cogs.downloader.errors.DownloaderException
Thrown when a git repo is expected to exist but does not.
-
exception
redbot.cogs.downloader.errors.
CloningError
[source]¶ Bases:
redbot.cogs.downloader.errors.GitException
Thrown when git clone returns a non zero exit code.
-
exception
redbot.cogs.downloader.errors.
CurrentHashError
[source]¶ Bases:
redbot.cogs.downloader.errors.GitException
Thrown when git returns a non zero exit code attempting to determine the current commit hash.
-
exception
redbot.cogs.downloader.errors.
HardResetError
[source]¶ Bases:
redbot.cogs.downloader.errors.GitException
Thrown when there is an issue trying to execute a hard reset (usually prior to a repo update).
-
exception
redbot.cogs.downloader.errors.
UpdateError
[source]¶ Bases:
redbot.cogs.downloader.errors.GitException
Thrown when git pull returns a non zero error code.
-
exception
redbot.cogs.downloader.errors.
GitDiffError
[source]¶ Bases:
redbot.cogs.downloader.errors.GitException
Thrown when a git diff fails.
-
exception
redbot.cogs.downloader.errors.
NoRemoteURL
[source]¶ Bases:
redbot.cogs.downloader.errors.GitException
Thrown when no remote URL exists for a repo.
-
exception
redbot.cogs.downloader.errors.
PipError
[source]¶ Bases:
redbot.cogs.downloader.errors.DownloaderException
Thrown when pip returns a non-zero return code.