Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for binary dependencies #9

Merged
merged 10 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Real-life example with multiple input packages and repositories.
Please see below for [an example](#configuration-file) how to set package and repository lists more easily in a configuration file.

```bash
locksmith --inputPackageList https://raw.githubusercontent.com/insightsengineering/formatters/main/DESCRIPTION,https://raw.githubusercontent.com/insightsengineering/rtables/main/DESCRIPTION,https://raw.githubusercontent.com/insightsengineering/scda/main/DESCRIPTION,https://raw.githubusercontent.com/insightsengineering/scda.2022/main/DESCRIPTION,https://raw.githubusercontent.com/insightsengineering/nestcolor/main/DESCRIPTION,https://raw.githubusercontent.com/insightsengineering/tern/main/DESCRIPTION,https://raw.githubusercontent.com/insightsengineering/rlistings/main/DESCRIPTION --inputRepositoryList BioC=https://bioconductor.org/packages/release/bioc,CRAN=https://cran.rstudio.com/
locksmith --inputPackageList https://raw.githubusercontent.com/insightsengineering/formatters/main/DESCRIPTION,https://raw.githubusercontent.com/insightsengineering/rtables/main/DESCRIPTION,https://raw.githubusercontent.com/insightsengineering/scda/main/DESCRIPTION,https://raw.githubusercontent.com/insightsengineering/scda.2022/main/DESCRIPTION,https://raw.githubusercontent.com/insightsengineering/nestcolor/main/DESCRIPTION,https://raw.githubusercontent.com/insightsengineering/tern/main/DESCRIPTION,https://raw.githubusercontent.com/insightsengineering/rlistings/main/DESCRIPTION --inputRepositoryList BioC=https://bioconductor.org/packages/release/bioc,CRAN=https://cran.rstudio.com
```

In order to download the packages from GitHub or GitLab repositories, please set the environment variables containing the Personal Access Tokens.
Expand Down Expand Up @@ -63,15 +63,56 @@ inputPackages:
- https://raw.githubusercontent.com/insightsengineering/scda/main/DESCRIPTION
- https://raw.githubusercontent.com/insightsengineering/scda.2022/main/DESCRIPTION
inputRepositories:
- Bioconductor.BioCsoft=https://bioconductor.org/packages/release/bioc/
- CRAN=https://cran.rstudio.com/
- Bioconductor.BioCsoft=https://bioconductor.org/packages/release/bioc
- CRAN=https://cran.rstudio.com
```

The example above shows an alternative way of providing input packages, and input repositories,
as opposed to `inputPackageList` and `inputRepositoryList` CLI flags/YAML keys.

Additionally, `inputPackageList`/`inputRepositoryList` CLI flags take precendence over `inputPackages`/`inputRepositories` YAML keys.

## Binary dependencies

For `locksmith` in order to generate an `renv.lock` with binary R packages, it is necessary to provide URLs to binary repositories in `inputRepositories`/`inputRepositoryList`.

Examples illustrating the expected format of URLs to repositories with binary packages:

* Linux:
* `https://packagemanager.posit.co/cran/__linux__/<distribution-name>/latest`
* Windows:
* `https://cloud.r-project.org/bin/windows/contrib/<r-version>`
* `https://www.bioconductor.org/packages/release/bioc/bin/windows/contrib/<r-version>`
* `https://packagemanager.posit.co/cran/latest/bin/windows/contrib/<r-version>`
* macOS:
* `https://cloud.r-project.org/bin/macosx/contrib/<r-version>`
* `https://www.bioconductor.org/packages/release/bioc/bin/macosx/big-sur-arm64/contrib/<r-version>`
* `https://www.bioconductor.org/packages/release/bioc/bin/macosx/big-sur-x86_64/contrib/<r-version>`
* `https://packagemanager.posit.co/cran/latest/bin/macosx/big-sur-x86_64/contrib/<r-version>`
* `https://packagemanager.posit.co/cran/latest/bin/macosx/big-sur-arm64/contrib/<r-version>`

where `<r-version>` is e.g. `4.2`, `4.3` etc.

In all cases the URL points to a directory where the `PACKAGES` file is located.

As a result, the configuration file could look like this:

* for macOS:

```yaml
inputRepositories:
- CRAN-macOS=https://cloud.r-project.org/bin/macosx/contrib/4.2
- Bioc-macOS=https://www.bioconductor.org/packages/release/bioc/bin/macosx/big-sur-x86_64/contrib/4.3
```

* for Windows:

```yaml
inputRepositories:
- CRAN-Windows=https://cloud.r-project.org/bin/windows/contrib/4.2
- Bioc-Windows=https://www.bioconductor.org/packages/release/bioc/bin/windows/contrib/4.3
```

## Environment variables

`locksmith` reads environment variables with `LOCKSMITH_` prefix and tries to match them with CLI flags.
Expand Down
13 changes: 11 additions & 2 deletions cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,20 @@ func DownloadPackagesFiles(repositoryList []string,
downloadFileFunction func(string, map[string]string) (int, int64, string)) map[string]string {
inputPackagesFiles := make(map[string]string)
for _, repository := range repositoryList {
statusCode, _, packagesFileContent := downloadFileFunction(repository+"/src/contrib/PACKAGES", map[string]string{})
var packagesFileURL string
if strings.Contains(repository, "/bin/windows/") || strings.Contains(repository, "/bin/macosx") {
// If we're dealing with a repository with binary Windows or macOS packages,
// we're expecting it to be in a specific format documented in the README.
packagesFileURL = repository + "/PACKAGES"
} else {
packagesFileURL = repository + "/src/contrib/PACKAGES"
}
log.Debug("Downloading ", packagesFileURL)
statusCode, _, packagesFileContent := downloadFileFunction(packagesFileURL, map[string]string{})
if statusCode == 200 {
inputPackagesFiles[repository] = packagesFileContent
} else {
log.Warn("An error occurred while downloading ", repository+"/src/contrib/PACKAGES")
log.Warn("An error occurred while downloading ", packagesFileURL)
}
}
return inputPackagesFiles
Expand Down
3 changes: 2 additions & 1 deletion cmd/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func ParseDescriptionFileList(inputDescriptionFiles []DescriptionFile) []Package
func ParsePackagesFiles(repositoryPackageFiles map[string]string) map[string]PackagesFile {
packagesFilesMap := make(map[string]PackagesFile)
for repository, packagesFile := range repositoryPackageFiles {
log.Debug("Parsing PACKAGES file for ", repository)
packagesFilesMap[repository] = ProcessPackagesFile(packagesFile)
}
return packagesFilesMap
Expand All @@ -45,7 +46,7 @@ func ParsePackagesFiles(repositoryPackageFiles map[string]string) map[string]Pac
// with those fields/properties that are required for further processing.
func ProcessPackagesFile(content string) PackagesFile {
var allPackages PackagesFile
for _, lineGroup := range strings.Split(content, "\n\n") {
for _, lineGroup := range strings.Split(strings.ReplaceAll(content, "\r\n", "\n"), "\n\n") {
if lineGroup == "" {
continue
}
Expand Down
Loading