Documentation
¶
Overview ¶
Package cmd implements the core functionality of locksmith - the renv.lock generator.
Index ¶
- func CheckIfBasePackage(name string) bool
- func CheckIfSkipDependency(indentation string, packageName string, dependencyName string, ...) bool
- func CheckIfVersionSufficient(availableVersionValue string, versionOperator string, ...) bool
- func CleanDescriptionOrPackagesEntry(description string, isDescription bool) string
- func DownloadPackagesFiles(repositoryList []string, ...) map[string]string
- func DownloadTextFile(url string, parameters map[string]string) (int, int64, string)
- func Execute()
- func GetGitHubSha(remoteUsername string, remoteRepo string, remoteRef string, ...) string
- func GetGitLabProjectAndSha(projectURL string, remoteRef string, token map[string]string, ...) (string, string, string)
- func GetRepositoryKeyByValue(repositoryURL string, repositoryMap map[string]string) string
- func ParseInput() ([]string, []string, map[string]string, []string)
- func ParsePackagesFiles(repositoryPackageFiles map[string]string) map[string]PackagesFile
- func ProcessDependencyFields(packageMap map[string]string, packageDependencies *[]Dependency)
- func ProcessDescription(description DescriptionFile, allPackages *[]PackageDescription)
- func ProcessDescriptionURL(descriptionURL string, ...) (map[string]string, string, string, string, string, string, string, string, ...)
- func ResolveDependenciesRecursively(outputList *[]PackageDescription, name string, versionOperator string, ...)
- type Dependency
- type DescriptionFile
- type GitHubObject
- type GitHubTagOrBranchResponse
- type GitLabAPIResponse
- type GitLabCommit
- type GitLabTagOrBranchResponse
- type PackageDescription
- type PackagesFile
- type RenvLock
- type RenvLockContents
- type RenvLockRepository
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckIfBasePackage ¶
CheckIfBasePackage checks whether the package should be treated as a base R package (included in every R installation) or if it should be treated as a dependency to be downloaded from a package repository.
func CheckIfSkipDependency ¶
func CheckIfSkipDependency(indentation string, packageName string, dependencyName string, versionOperator string, versionValue string, outputList *[]PackageDescription) bool
CheckIfSkipDependency checks if processing of the package (dependency) should be skipped. Dependency should be skipped if it is a base R package, or has already been added to output package list (later used to generate the renv.lock).
func CheckIfVersionSufficient ¶
func CheckIfVersionSufficient(availableVersionValue string, versionOperator string, requiredVersionValue string) bool
CheckIfVersionSufficient checks if availableVersionValue fulfills the requirement expressed by versionOperator ('>=' or '>') and requiredVersionValue.
func CleanDescriptionOrPackagesEntry ¶
CleanDescriptionOrPackagesEntry processes a multiline string representing information about one package from PACKAGES file (if isDescription is false), or the whole contents of DESCRIPTION file (if isDescription is true). Removes newlines occurring within filtered fields (which are predominantly fields containing lists of package dependencies). Also removes fields which are not required for further processing.
func DownloadPackagesFiles ¶
func DownloadPackagesFiles(repositoryList []string, downloadFileFunction func(string, map[string]string) (int, int64, string)) map[string]string
DownloadPackagesFiles downloads PACKAGES files from repository URLs specified in the repositoryList. Returns a map from repository URL to the string with the contents of PACKAGES file for that repository.
func DownloadTextFile ¶
DownloadTextFile returns HTTP status code for downloaded file, number of bytes in downloaded content, and the downloaded content itself as a string.
func GetGitHubSha ¶
func GetGitHubSha(remoteUsername string, remoteRepo string, remoteRef string, token map[string]string, downloadFileFunction func(string, map[string]string) (int, int64, string)) string
GetGitHubSha retrieves SHA of the remoteRef from the remoteUsername/remoteRepo GitHub repository.
func GetGitLabProjectAndSha ¶
func GetGitLabProjectAndSha(projectURL string, remoteRef string, token map[string]string, downloadFileFunction func(string, map[string]string) (int, int64, string)) (string, string, string)
GetGitLabProjectAndSha retrieves information about GitLab repository (project path, repository name and commit SHA) from projectURL GitLab API endpoint.
func GetRepositoryKeyByValue ¶
GetRepositoryKeyByValue searches for repository URL in repositoryMap and returns the name (alias) of that repository which will then be used in output renv.lock file.
func ParseInput ¶
ParseInput parses CLI input parameters, and returns: list of package DESCRIPTION URLs, list of package repository URLs (in descending priority order), a map from package repository alias (name) to the package repository URL, and a list of allowed types of missing dependencies.
func ParsePackagesFiles ¶
func ParsePackagesFiles(repositoryPackageFiles map[string]string) map[string]PackagesFile
ParsePackagesFiles iterates through package repository PACKAGES files.
func ProcessDependencyFields ¶
func ProcessDependencyFields(packageMap map[string]string, packageDependencies *[]Dependency)
ProcessDependencyFields processes a map containing a YAML-like object representing dependencies of a package. Returns a list of Dependency structures corresponding to dependency name, and version constraints.
func ProcessDescription ¶
func ProcessDescription(description DescriptionFile, allPackages *[]PackageDescription)
ProcessDescription reads a string containing DESCRIPTION file and returns a structure with those fields/properties that are required for further processing.
func ProcessDescriptionURL ¶
func ProcessDescriptionURL(descriptionURL string, downloadFileFunction func(string, map[string]string) (int, int64, string), ) (map[string]string, string, string, string, string, string, string, string, string)
ProcessDescriptionURL gets information about the git repository in which the package is stored based on the provided descriptionURL to the package DESCRIPTION file.
func ResolveDependenciesRecursively ¶
func ResolveDependenciesRecursively(outputList *[]PackageDescription, name string, versionOperator string, versionValue string, dependencyType string, allowedMissingDependencyTypes []string, repositoryList []string, packagesFiles map[string]PackagesFile, recursionLevel int, fatalErrors *string, nonFatalErrors *string)
ResolveDependenciesRecursively checks dependencies of the package, and their required versions. Checks if the required version is already included in the output package list (later used to generate the renv.lock), or if the dependency should be downloaded from a package repository. Repeats the process recursively for all dependencies not yet processed.
Types ¶
type Dependency ¶
type DescriptionFile ¶
type DescriptionFile struct {
// Contents stores the DESCRIPTION file.
Contents string `json:"contents"`
// PackageSource can be either 'GitHub' or 'GitLab'.
PackageSource string `json:"source"`
// RemoteType can be either 'github' or 'gitlab'.
RemoteType string `json:"remoteType"`
// RemoteHost can be 'api.github.com' or the URL of GitLab instance,
// for example: 'https://gitlab.example.com'.
RemoteHost string `json:"remoteHost"`
// RemoteUsername represents the organization or the owner in case of a GitHub
// repository, or the path to the repository in the project tree in case of
// a GitLab repository.
RemoteUsername string `json:"remoteUsername"`
// RemoteRepo contains the name of git repository.
RemoteRepo string `json:"remoteRepo"`
// RemoteSubdir is an optional field storing the path to the package inside
// the git repository in case the package is not located in the root of the
// git repository.
RemoteSubdir string `json:"remoteSubdir"`
// RemoteRef is tag or branch name representing the verion of the provided
// package DESCRIPTION file. If RemoteRef matches `v\d+(\.\d+)*` regex,
// it is treated as a git tag, otherwise it is treated as a git branch.
RemoteRef string `json:"remoteRef"`
// RemoteSha is the commit SHA for the RemoteRef.
RemoteSha string `json:"remoteSha"`
}
DescriptionFile represents the input package DESCRIPTION file together with related information about the git repository where the package is stored. This structure represents data about input git packages before it is parsed into a PackageDescription struct.
func DownloadDescriptionFiles ¶
func DownloadDescriptionFiles(packageDescriptionList []string, downloadFileFunction func(string, map[string]string) (int, int64, string)) []DescriptionFile
DownloadDescriptionFiles downloads DESCRIPTION files from packageDescriptionList. It returns a list of structures representing: the contents of DESCRIPTION file for the packages and various information about git repositories storing the packages.
type GitHubObject ¶
type GitHubObject struct {
Sha string `json:"sha"`
}
type GitHubTagOrBranchResponse ¶
type GitHubTagOrBranchResponse struct {
Object GitHubObject `json:"object"`
}
type GitLabAPIResponse ¶
type GitLabAPIResponse struct {
PathWithNamespace string `json:"path_with_namespace"`
}
type GitLabCommit ¶
type GitLabCommit struct {
ID string `json:"id"`
}
type GitLabTagOrBranchResponse ¶
type GitLabTagOrBranchResponse struct {
Commit GitLabCommit `json:"commit"`
}
type PackageDescription ¶
type PackageDescription struct {
// Package stores the package name.
Package string `json:"Package"`
// Version stores the package version.
Version string `json:"Version"`
// Source can be one of: 'GitHub', 'GitLab' (for packages from git repositories)
// or 'Repository' (for packages from package repositories).
Source string `json:"Source"`
// Repository stores the URL or the name (depending on the stage of processing)
// of the package repository, in case Source is 'Repository'.
Repository string `json:"Repository,omitempty"`
// Dependencies contains the list of package dependencies.
Dependencies []Dependency `json:"Requirements,omitempty"`
// When processing packages stored in package repositories, the fields below are empty.
// These fields are documented in the DescriptionFile struct.
RemoteType string `json:"RemoteType,omitempty"`
RemoteHost string `json:"RemoteHost,omitempty"`
RemoteUsername string `json:"RemoteUsername,omitempty"`
RemoteRepo string `json:"RemoteRepo,omitempty"`
RemoteSubdir string `json:"RemoteSubdir,omitempty"`
RemoteRef string `json:"RemoteRef,omitempty"`
RemoteSha string `json:"RemoteSha,omitempty"`
}
PackageDescrition represents an R package.
func ConstructOutputPackageList ¶
func ConstructOutputPackageList(packages []PackageDescription, packagesFiles map[string]PackagesFile, repositoryList []string, allowedMissingDependencyTypes []string) []PackageDescription
ConstructOutputPackageList generates a list of all packages and their dependencies which should be included in the output renv.lock file, based on the list of package descriptions, and information contained in the PACKAGES files.
func ParseDescriptionFileList ¶
func ParseDescriptionFileList(inputDescriptionFiles []DescriptionFile) []PackageDescription
ParseDescriptionFileList iterates through package DESCRIPTION files.
type PackagesFile ¶
type PackagesFile struct {
Packages []PackageDescription `json:"packages"`
}
func ProcessPackagesFile ¶
func ProcessPackagesFile(content string) PackagesFile
ProcessPackagesFile reads a string containing PACKAGES file, and returns a structure with those fields/properties that are required for further processing.
type RenvLock ¶
type RenvLock struct {
R RenvLockContents `json:"R"`
Packages map[string]PackageDescription `json:"Packages"`
}
func GenerateRenvLock ¶
func GenerateRenvLock(packageList []PackageDescription, repositoryMap map[string]string) RenvLock
GenerateRenvLock generates renv.lock file structure which can be then saved as a JSON file. It uses a list of package data created by ConstructOutputPackageList, and the map of package repositories containing the packages.
type RenvLockContents ¶
type RenvLockContents struct {
Repositories []RenvLockRepository `json:"Repositories"`
}