Skip to content

Commit

Permalink
MaximumTaggedVersions is now an option. Fixes a Nim CI issue (#1293)
Browse files Browse the repository at this point in the history
* Fixes nim CI

* maximumTaggedVersions is now an option

* cleanup

* simplifies folder restoring

* Fixes compilation
  • Loading branch information
jmgomez authored Nov 29, 2024
1 parent 813f736 commit 74f0872
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
19 changes: 12 additions & 7 deletions src/nimblepkg/nimblesat.nim
Original file line number Diff line number Diff line change
Expand Up @@ -482,18 +482,18 @@ proc saveTaggedVersions*(repoDir: string, taggedVersions: TaggedPackageVersions)
except CatchableError as e:
displayWarning(&"Error saving tagged versions: {e.msg}", HighPriority)

proc getPackageMinimalVersionsFromRepo*(repoDir, pkgName: string, downloadMethod: DownloadMethod, options: Options): seq[PackageMinimalInfo] =
proc getPackageMinimalVersionsFromRepo*(repoDir: string, name: string, version: Version, downloadMethod: DownloadMethod, options: Options): seq[PackageMinimalInfo] =
#This is expensive. We need to cache it. Potentially it could be also run in parallel
# echo &"Discovering version for {pkgName}"
let taggedVersions = getTaggedVersions(repoDir, options)
if taggedVersions.isSome:
return taggedVersions.get.versions
gitFetchTags(repoDir, downloadMethod)
gitFetchTags(repoDir, downloadMethod)
#First package must be the current one
try:
result.add getPkgInfo(repoDir, options).getMinimalInfo(options)
except CatchableError as e:
displayWarning(&"Error getting package info for {pkgName}: {e.msg}", HighPriority)
displayWarning(&"Error getting package info for {name}: {e.msg}", HighPriority)
let tags = getTagsList(repoDir, downloadMethod).getVersionList()
var checkedTags = 0
for (ver, tag) in tags.pairs:
Expand All @@ -506,20 +506,25 @@ proc getPackageMinimalVersionsFromRepo*(repoDir, pkgName: string, downloadMethod
doCheckout(downloadMethod, repoDir, tag)
let nimbleFile = findNimbleFile(repoDir, true, options)
let pkgInfo = getPkgInfoFromFile(nimbleFile, options, useCache=false)
let minimalInfo = pkgInfo.getMinimalInfo(options)
result.addUnique minimalInfo
result.addUnique pkgInfo.getMinimalInfo(options)
except CatchableError as e:
displayWarning(&"Error reading tag {tag}: for package {pkgName}. This may not be relevant as it could be an old version of the package. \n {e.msg}", HighPriority)
displayWarning(&"Error reading tag {tag}: for package {name}. This may not be relevant as it could be an old version of the package. \n {e.msg}", HighPriority)

#make sure we let this folder as it was
for (ver, tag) in tags.pairs:
if ver == version:
doCheckout(downloadMethod, repoDir, tag)

saveTaggedVersions(repoDir, TaggedPackageVersions(maxTaggedVersions: options.maxTaggedVersions, versions: result))

proc downloadMinimalPackage*(pv: PkgTuple, options: Options): seq[PackageMinimalInfo] =
if pv.name == "": return newSeq[PackageMinimalInfo]()
if pv.isNim and not options.disableNimBinaries: return getAllNimReleases(options)
if pv.ver.kind in [verSpecial, verEq]: #if special or equal, we dont retrieve more versions as we only need one.
result = @[downloadPkInfoForPv(pv, options).getMinimalInfo(options)]
else:
let (downloadRes, downloadMeth) = downloadPkgFromUrl(pv, options)
result = getPackageMinimalVersionsFromRepo(downloadRes.dir, pv.name, downloadMeth, options)
result = getPackageMinimalVersionsFromRepo(downloadRes.dir, pv.name, downloadRes.version, downloadMeth, options)
# echo "Downloading minimal package for ", pv.name, " ", $pv.ver, result

proc fillPackageTableFromPreferred*(packages: var Table[string, PackageVersions], preferredPackages: seq[PackageMinimalInfo]) =
Expand Down
9 changes: 7 additions & 2 deletions src/nimblepkg/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ Nimble Options:
--solver:sat|legacy Use the SAT solver (default) or the legacy for dependency resolution.
--requires Add extra packages to the dependency resolution. Uses the same syntax as the Nimble file. Example: nimble install --requires "pkg1; pkg2 >= 1.2"
--disableNimBinaries Disable the use of nim precompiled binaries. Note in some platforms precompiled binaries are not available but the flag can still be used to avoid compile the Nim version once and reuse it.
--maximumTaggedVersions Maximum number of tags to check for a package when discovering versions for the SAT solver. 0 means all.
For more information read the GitHub readme:
https://github.com/nim-lang/nimble#readme
"""
Expand Down Expand Up @@ -640,6 +640,11 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
result.extraRequires = val.split(";").mapIt(it.strip.parseRequires())
of "disablenimbinaries":
result.disableNimBinaries = true
of "maximumtaggedversions":
try:
result.maxTaggedVersions = parseUInt(val).int
except ValueError:
raise nimbleError(&"{val} is not a valid value")
else: isGlobalFlag = false

var wasFlagHandled = true
Expand Down Expand Up @@ -749,7 +754,7 @@ proc initOptions*(): Options =
noColor: not isatty(stdout),
startDir: getCurrentDir(),
nimBinariesDir: getHomeDir() / ".nimble" / "nimbinaries",
maxTaggedVersions: 2 #TODO increase once we have a cache
maxTaggedVersions: 2
)

proc handleUnknownFlags(options: var Options) =
Expand Down
15 changes: 9 additions & 6 deletions tests/tsat.nim
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,10 @@ suite "SAT solver":
"https://nim-lang.org/nimble/packages.json"
])
let pv = parseRequires("nimfp >= 0.3.4")
let repoDir = pv.downloadPkgFromUrl(options)[0].dir #This is just to setup the test. We need a git dir to work on
let downloadRes = pv.downloadPkgFromUrl(options)[0] #This is just to setup the test. We need a git dir to work on
let repoDir = downloadRes.dir
let downloadMethod = DownloadMethod git
let packageVersions = getPackageMinimalVersionsFromRepo(repoDir, pv[0], downloadMethod, options)
let packageVersions = getPackageMinimalVersionsFromRepo(repoDir, pv[0], downloadRes.version, downloadMethod, options)

#we know these versions are available
let availableVersions = @["0.3.4", "0.3.5", "0.3.6", "0.4.5", "0.4.4"].mapIt(newVersion(it))
Expand All @@ -317,15 +318,17 @@ suite "SAT solver":
removeDir(dir.path)

let pvPrev = parseRequires("nimfp >= 0.3.4")
let repoDirPrev = pvPrev.downloadPkgFromUrl(options)[0].dir
discard getPackageMinimalVersionsFromRepo(repoDirPrev, pvPrev[0], DownloadMethod.git, options)
let downloadResPrev = pvPrev.downloadPkgFromUrl(options)[0]
let repoDirPrev = downloadResPrev.dir
discard getPackageMinimalVersionsFromRepo(repoDirPrev, pvPrev[0], downloadResPrev.version, DownloadMethod.git, options)
check fileExists(repoDirPrev / TaggedVersionsFileName)

let pv = parseRequires("nimfp >= 0.4.4")
let repoDir = pv.downloadPkgFromUrl(options)[0].dir
let downloadRes = pv.downloadPkgFromUrl(options)[0]
let repoDir = downloadRes.dir
check not fileExists(repoDir / TaggedVersionsFileName)

let packageVersions = getPackageMinimalVersionsFromRepo(repoDir, pv[0], DownloadMethod.git, options)
let packageVersions = getPackageMinimalVersionsFromRepo(repoDir, pv[0], downloadRes.version, DownloadMethod.git, options)
#we know these versions are available
let availableVersions = @["0.4.5", "0.4.4"].mapIt(newVersion(it))
for version in availableVersions:
Expand Down

0 comments on commit 74f0872

Please sign in to comment.