Skip to content

Commit b51b57f

Browse files
authored
Add the feature to update renv.lock provided as an input (#18)
1 parent 373c61a commit b51b57f

File tree

16 files changed

+794
-575
lines changed

16 files changed

+794
-575
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ help: ## Show this help menu
2525

2626
devdeps: ## Install development dependencies
2727
@printf "Executing target: [$@] 🎯\n"
28-
@which -a golangci-lint > /dev/null || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH) v1.55.0
28+
@which -a golangci-lint > /dev/null || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH) v1.55.2
2929
@which -a typex > /dev/null || go install github.com/dtgorski/typex@latest
3030
@which -a goreleaser > /dev/null || go install github.com/goreleaser/goreleaser@latest
3131
@which -a gocover-cobertura > /dev/null || go install github.com/boumenot/gocover-cobertura@latest
@@ -60,7 +60,7 @@ format: ## Format source code
6060

6161
lint: devdeps spell ## Lint source code
6262
@printf "Executing target: [$@] 🎯\n"
63-
@golangci-lint run --fast -c .golangci.yml
63+
@golangci-lint run -c .golangci.yml
6464

6565
test: clean tidy devdeps spell ## Run unit tests and generate reports
6666
@printf "Executing target: [$@] 🎯\n"

README.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ following command to view its capabilities:
3232
locksmith --help
3333
```
3434

35-
Example usage with multiple flags:
36-
37-
```bash
38-
locksmith --logLevel debug --exampleParameter 'exampleValue'
39-
```
40-
4135
Real-life example with multiple input packages and repositories.
4236
Please see below for [an example](#configuration-file) how to set package and repository lists more
4337
easily in a configuration file.
@@ -46,7 +40,7 @@ easily in a configuration file.
4640
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,https://gitlab.example.com/api/v4/projects/123456/repository/files/DESCRIPTION/raw?ref=main,https://gitlab.example.com/api/v4/projects/234567/repository/files/directory%2Fsubdirectory%2FDESCRIPTION/raw?ref=main --inputRepositoryList BioC=https://bioconductor.org/packages/release/bioc,CRAN=https://cran.rstudio.com
4741
```
4842

49-
In order to download the packages from non-public GitHub or GitLab repositories, please set the environment
43+
In order to download the input `DESCRIPTION` files from GitHub or GitLab repositories, please set the environment
5044
variables containing the Personal Access Tokens.
5145

5246
* For GitHub, set the `LOCKSMITH_GITHUBTOKEN` environment variable.
@@ -88,6 +82,8 @@ as opposed to `inputPackageList` and `inputRepositoryList` CLI flags/YAML keys.
8882
Additionally, `inputPackageList`/`inputRepositoryList` CLI flags take precendence over
8983
`inputPackages`/`inputRepositories` YAML keys.
9084

85+
Please note that package repository URLs should be provided without the trailing `/`.
86+
9187
## Environment variables
9288

9389
`locksmith` reads environment variables with `LOCKSMITH_` prefix and tries to match them with CLI
@@ -98,9 +94,11 @@ The order of precedence is:
9894

9995
CLI flag → environment variable → configuration file → default value.
10096

97+
To check the available names of environment variables, please run `locksmith --help`.
98+
10199
## Binary dependencies
102100

103-
For `locksmith` in order to generate an `renv.lock` with binary R packages,
101+
If `locksmith` should generate an `renv.lock` with binary R packages,
104102
it is necessary to provide URLs to binary repositories via `inputRepositories`/`inputRepositoryList`.
105103

106104
Examples illustrating the expected format of URLs to repositories with binary packages:
@@ -120,7 +118,7 @@ Examples illustrating the expected format of URLs to repositories with binary pa
120118

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

123-
In all cases the URL points to a directory where the `PACKAGES` file is located.
121+
In all cases the URL points to a directory where the `PACKAGES` file is located, without the trailing `/`.
124122

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

@@ -152,6 +150,26 @@ Simply list the types of dependencies which should not cause the `renv.lock` gen
152150
locksmith --allowIncompleteRenvLock 'Imports,Depends,Suggests,LinkingTo'
153151
```
154152

153+
## Updating existing `renv.lock`
154+
155+
`locksmith` has the capability to update an existing lockfile with the newest available package versions.
156+
157+
To ensure that the `input.renv.lock` has all the packages in the newest versions from the respective repositories (git, CRAN-like or BioConductor-like), and to save such updated file to `output.renv.lock`, you can run:
158+
159+
```bash
160+
locksmith --inputRenvLock input.renv.lock --outputRenvLock output.renv.lock
161+
```
162+
163+
For git packages, a reference to the latest commit on the default branch will be saved.
164+
165+
For packages which, according to the input lockfile, should be downloaded from CRAN-like or BioConductor-like repositories, a reference to the latest available package version in the respective repository will be saved.
166+
167+
The packages can be updated selectively by using the `--updatePackages` flag.
168+
169+
Please note that `renv` might have saved the information in the input lockfile that the package should be downloaded from `CRAN`, `RSPM` or BioConductor repository, but at the same time the definition of that repository in the `renv.lock` header (in the `Repositories` section) might be missing. For such packages `locksmith` will try to check what is the newest available package version at [CRAN](https://cloud.r-project.org).
170+
171+
Please also note that `locksmith` will not verify whether the dependencies of some packages have changed - this means that the set of package names present in the lockfile will stay the same.
172+
155173
## Development
156174

157175
This project is built with the [Go programming language](https://go.dev/).

cmd/construct.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func ConstructOutputPackageList(packages []PackageDescription, packagesFiles map
3535
outputPackageList = append(outputPackageList, PackageDescription{
3636
p.Package, p.Version, p.Source, "", []Dependency{},
3737
p.RemoteType, p.RemoteHost, p.RemoteUsername, p.RemoteRepo, p.RemoteSubdir,
38-
p.RemoteRef, p.RemoteSha,
38+
p.RemoteRef, p.RemoteSha, []string{},
3939
})
4040
}
4141
for _, p := range packages {
@@ -120,7 +120,7 @@ func ResolveDependenciesRecursively(outputList *[]PackageDescription, name strin
120120
// during the processing of output package list into renv.lock file.
121121
*outputList = append(*outputList, PackageDescription{
122122
p.Package, p.Version, "Repository", r, []Dependency{},
123-
"", "", "", "", "", "", "",
123+
"", "", "", "", "", "", "", []string{},
124124
})
125125
for _, d := range p.Dependencies {
126126
if d.DependencyType == "Depends" || d.DependencyType == "Imports" ||

0 commit comments

Comments
 (0)