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

Generate renv.lock #3

Merged
merged 21 commits into from
Oct 24, 2023
Merged
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ coverage.html
coverage.xml
junit-report.xml
test-results.txt
renv.lock
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ help: ## Show this help menu

devdeps: ## Install development dependencies
@printf "Executing target: [$@] 🎯\n"
@which -a golangci-lint > /dev/null || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH) v1.51.2
@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
@which -a typex > /dev/null || go install github.com/dtgorski/typex@latest
@which -a goreleaser > /dev/null || go install github.com/goreleaser/goreleaser@latest
@which -a gocover-cobertura > /dev/null || go install github.com/boumenot/gocover-cobertura@latest
Expand Down
53 changes: 28 additions & 25 deletions cmd/construct.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,23 @@ import (
)

func constructOutputPackageList(packages []PackageDescription, packagesFiles map[string]PackagesFile,
repositoryList []string) []OutputPackage {
var outputPackageList []OutputPackage
repositoryList []string) []PackageDescription {
var outputPackageList []PackageDescription
// Add all input packages to output list, as the packages should be downloaded from git repositories.
for _, p := range packages {
outputPackageList = append(outputPackageList, OutputPackage{
p.Package, p.Version, p.Repository,
outputPackageList = append(outputPackageList, PackageDescription{
p.Package, p.Version, p.Source, "", []Dependency{},
p.RemoteType, p.RemoteHost, p.RemoteUsername, p.RemoteRepo, p.RemoteSubdir,
p.RemoteRef, p.RemoteSha,
})
}
for _, p := range packages {
for _, d := range p.Dependencies {
skipDependency := false
if d.DependencyType == "Depends" || d.DependencyType == "Imports" ||
d.DependencyType == "Suggests" {
if checkIfBasePackage(d.DependencyName) {
log.Debug("Skipping package ", d.DependencyName, " as it is a base R package.")
skipDependency = true
}
if checkIfPackageOnOutputList(d.DependencyName, outputPackageList) {
log.Debug("Package ", d.DependencyName, " is already present on the output list.")
d.DependencyType == "Suggests" || d.DependencyType == "LinkingTo" {
if checkIfSkipDependency("", p.Package, d.DependencyName,
d.VersionOperator, d.VersionValue, &outputPackageList) {
skipDependency = true
}
if !skipDependency {
Expand All @@ -55,7 +53,7 @@ func constructOutputPackageList(packages []PackageDescription, packagesFiles map
return outputPackageList
}

func resolveDependenciesRecursively(outputList *[]OutputPackage, name string, versionOperator string,
func resolveDependenciesRecursively(outputList *[]PackageDescription, name string, versionOperator string,
versionValue string, repositoryList []string, packagesFiles map[string]PackagesFile, recursionLevel int) {
var indentation string
for i := 0; i < recursionLevel; i++ {
Expand All @@ -82,11 +80,13 @@ func resolveDependenciesRecursively(outputList *[]OutputPackage, name string, ve
// Add package to the output list.
// Repository is saved as an URL, and will be changed into an alias
// during the processing of output package list into renv.lock file.
*outputList = append(*outputList, OutputPackage{
p.Package, p.Version, r,
*outputList = append(*outputList, PackageDescription{
p.Package, p.Version, "Repository", r, []Dependency{},
"", "", "", "", "", "", "",
})
for _, d := range p.Dependencies {
if d.DependencyType == "Depends" || d.DependencyType == "Imports" {
if d.DependencyType == "Depends" || d.DependencyType == "Imports" ||
d.DependencyType == "LinkingTo" {
if !checkIfSkipDependency(indentation, p.Package, d.DependencyName,
d.VersionOperator, d.VersionValue, outputList) {
log.Info(indentation, p.Package, " → ", d.DependencyName)
Expand Down Expand Up @@ -121,17 +121,8 @@ func checkIfBasePackage(name string) bool {
return stringInSlice(name, basePackages)
}

func checkIfPackageOnOutputList(name string, outputList []OutputPackage) bool {
for _, o := range outputList {
if name == o.Package {
return true
}
}
return false
}

func checkIfSkipDependency(indentation string, packageName string, dependencyName string,
versionOperator string, versionValue string, outputList *[]OutputPackage) bool {
versionOperator string, versionValue string, outputList *[]PackageDescription) bool {
if checkIfBasePackage(dependencyName) {
log.Debug(indentation, "Skipping package ", dependencyName, " as it is a base R package.")
return true
Expand All @@ -143,6 +134,17 @@ func checkIfSkipDependency(indentation string, packageName string, dependencyNam
if dependencyName == (*outputList)[i].Package {
// Dependency found on the output list.
if checkIfVersionSufficient((*outputList)[i].Version, versionOperator, versionValue) {
var requirementMessage string
if versionOperator != "" && versionValue != "" {
requirementMessage = " according to the requirement " + versionOperator + " " + versionValue
} else {
requirementMessage = " since no required version has been specified."
}
log.Debug(
indentation, "Output list already contains dependency ", dependencyName, " version ",
(*outputList)[i].Version, " which is sufficient for ", packageName,
requirementMessage,
)
return true
}
log.Warn(
Expand All @@ -157,6 +159,7 @@ func checkIfSkipDependency(indentation string, packageName string, dependencyNam
// When generating the output renv.lock, these empty entries will be filtered out.
(*outputList)[i].Package = ""
(*outputList)[i].Version = ""
(*outputList)[i].Source = ""
(*outputList)[i].Repository = ""
return false
}
Expand Down
Loading
Loading