Skip to content

Commit

Permalink
collectAllVersion now collects requirements from releases discovered …
Browse files Browse the repository at this point in the history
…through tags. minimal from git also restore the current package even if it isnt released
  • Loading branch information
jmgomez committed Nov 20, 2024
1 parent 89a2d6d commit 63f07b3
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 18 deletions.
41 changes: 24 additions & 17 deletions src/nimblepkg/nimblesat.nim
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,11 @@ proc getSolvedPackages*(pkgVersionTable: Table[string, PackageVersions], output:
for dep, q in items graph.reqs[ver.req].deps:
if dep notin graph.packageToDependency:
#debug print. show all packacges in the graph
output.add &"Dependency {dep} not found in the graph \n"
for k, v in pkgVersionTable:
output.add &"Package {k} \n"
for v in v.versions:
output.add &"\t \t Version {v.version} requires: {v.requires} \n"
output.add &"Dependency {dep} not found in the graph \n"
return newSeq[SolvedPackage]()

let form = toFormular(graph)
Expand Down Expand Up @@ -447,7 +447,9 @@ proc getAllNimReleases(options: Options): seq[PackageMinimalInfo] =
proc getPackageMinimalVersionsFromRepo*(repoDir, pkgName: string, 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}"
gitFetchTags(repoDir, downloadMethod)
gitFetchTags(repoDir, downloadMethod)
#First package must be the current one
result.add getPkgInfo(repoDir, options).getMinimalInfo(options)
let tags = getTagsList(repoDir, downloadMethod).getVersionList()
var checkedTags = 0
for (ver, tag) in tags.pairs:
Expand All @@ -461,17 +463,19 @@ proc getPackageMinimalVersionsFromRepo*(repoDir, pkgName: string, downloadMethod
let nimbleFile = findNimbleFile(repoDir, true, options)
let pkgInfo = getPkgInfoFromFile(nimbleFile, options, useCache=false)
let minimalInfo = pkgInfo.getMinimalInfo(options)
result.add minimalInfo
result.addUnique minimalInfo
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)

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 == verSpecial:
return @[downloadPkInfoForPv(pv, options).getMinimalInfo(options)]
let (downloadRes, downloadMeth) = downloadPkgFromUrl(pv, options)
getPackageMinimalVersionsFromRepo(downloadRes.dir, pv.name, downloadMeth, options)
result = @[downloadPkInfoForPv(pv, options).getMinimalInfo(options)]
else:
let (downloadRes, downloadMeth) = downloadPkgFromUrl(pv, options)
result = getPackageMinimalVersionsFromRepo(downloadRes.dir, pv.name, downloadMeth, options)
# echo "Downloading minimal package for ", pv.name, " ", $pv.ver, result

proc fillPackageTableFromPreferred*(packages: var Table[string, PackageVersions], preferredPackages: seq[PackageMinimalInfo]) =
for pkg in preferredPackages:
Expand All @@ -484,20 +488,17 @@ proc fillPackageTableFromPreferred*(packages: var Table[string, PackageVersions]
proc getInstalledMinimalPackages*(options: Options): seq[PackageMinimalInfo] =
getInstalledPkgsMin(options.getPkgsDir(), options).mapIt(it.getMinimalInfo(options))

proc collectAllVersions*(versions: var Table[string, PackageVersions], package: PackageMinimalInfo, options: Options, getMinimalPackage: GetPackageMinimal, preferredPackages: seq[PackageMinimalInfo] = newSeq[PackageMinimalInfo]()) =
### Collects all the versions of a package and its dependencies and stores them in the versions table
### A getMinimalPackage function is passed to get the package

proc collectAllVersions*(versions: var Table[string, PackageVersions], package: PackageMinimalInfo, options: Options, getMinimalPackage: GetPackageMinimal, preferredPackages: seq[PackageMinimalInfo] = newSeq[PackageMinimalInfo]()) =
proc getMinimalFromPreferred(pv: PkgTuple): seq[PackageMinimalInfo] =
#Before proceding to download we check if the package is in the preferred packages
for pp in preferredPackages:
if pp.name == pv.name and pp.version.withinRange(pv.ver):
return @[pp]
# echo "Getting minimal from getMinimalPackage for ", pv.name, " ", $pv.ver
getMinimalPackage(pv, options)

for pv in package.requires:
# echo "Collecting versions for ", pv.name, " and Version: ", $pv.ver, " via ", package.name
var pv = pv
if not hasVersion(versions, pv): # Not found, meaning this package-version needs to be explored
proc processRequirements(versions: var Table[string, PackageVersions], pv: PkgTuple) =
if not hasVersion(versions, pv):
var pkgMins = getMinimalFromPreferred(pv)
for pkgMin in pkgMins.mitems:
if pv.ver.kind == verSpecial:
Expand All @@ -506,8 +507,14 @@ proc collectAllVersions*(versions: var Table[string, PackageVersions], package:
versions[pv.name] = PackageVersions(pkgName: pv.name, versions: @[pkgMin])
else:
versions[pv.name].versions.addUnique pkgMin
#TODO Note for when implementing "enumerate all versions": do not enter in the loop until we have collected all the versions
collectAllVersions(versions, pkgMin, options, getMinimalPackage, preferredPackages)

# Process requirements from both the package and GetMinimalPackage results
for req in pkgMin.requires:
# echo "Processing requirement: ", req.name, " ", $req.ver
processRequirements(versions, req)

for pv in package.requires:
processRequirements(versions, pv)

proc topologicalSort*(solvedPkgs: seq[SolvedPackage]): seq[SolvedPackage] =
var inDegree = initTable[string, int]()
Expand Down
2 changes: 1 addition & 1 deletion src/nimblepkg/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ proc initOptions*(): Options =
noColor: not isatty(stdout),
startDir: getCurrentDir(),
nimBinariesDir: getHomeDir() / ".nimble" / "nimbinaries",
maxTaggedVersions: 0 #TODO increase once we have a cache
maxTaggedVersions: 2 #TODO increase once we have a cache
)

proc handleUnknownFlags(options: var Options) =
Expand Down
13 changes: 13 additions & 0 deletions tests/oldnimble/oldnimble.nimble
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Package

version = "0.1.0"
author = "jmgomez"
description = "A new awesome nimble package"
license = "MIT"
srcDir = "src"


# Dependencies

requires "nim >= 2.0.11"
requires "nimble <= 0.16.2" #We know this nimble version has additional requirements (new nimble use submodules)
7 changes: 7 additions & 0 deletions tests/oldnimble/src/oldnimble.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This is just an example to get you started. A typical library package
# exports the main API in this file. Note that you cannot rename this file
# but you can remove it if you wish.

proc add*(x, y: int): int =
## Adds two numbers together.
return x + y
12 changes: 12 additions & 0 deletions tests/oldnimble/src/oldnimble/submodule.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This is just an example to get you started. Users of your library will
# import this file by writing ``import oldnimble/submodule``. Feel free to rename or
# remove this file altogether. You may create additional modules alongside
# this file as required.

type
Submodule* = object
name*: string

proc initSubmodule*(): Submodule =
## Initialises a new ``Submodule`` object.
Submodule(name: "Anonymous")
12 changes: 12 additions & 0 deletions tests/oldnimble/tests/test1.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This is just an example to get you started. You may wish to put all of your
# tests into a single file, or separate them into multiple `test1`, `test2`
# etc. files (better names are recommended, just make sure the name starts with
# the letter 't').
#
# To run these tests, simply execute `nimble test`.

import unittest

import oldnimble
test "can add":
check add(5, 5) == 10
7 changes: 7 additions & 0 deletions tests/wronglytaggednim/src/wronglytaggednim.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This is just an example to get you started. A typical library package
# exports the main API in this file. Note that you cannot rename this file
# but you can remove it if you wish.

proc add*(x, y: int): int =
## Adds two numbers together.
return x + y
12 changes: 12 additions & 0 deletions tests/wronglytaggednim/src/wronglytaggednim/submodule.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This is just an example to get you started. Users of your library will
# import this file by writing ``import wronglytaggednim/submodule``. Feel free to rename or
# remove this file altogether. You may create additional modules alongside
# this file as required.

type
Submodule* = object
name*: string

proc initSubmodule*(): Submodule =
## Initialises a new ``Submodule`` object.
Submodule(name: "Anonymous")
12 changes: 12 additions & 0 deletions tests/wronglytaggednim/tests/test1.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This is just an example to get you started. You may wish to put all of your
# tests into a single file, or separate them into multiple `test1`, `test2`
# etc. files (better names are recommended, just make sure the name starts with
# the letter 't').
#
# To run these tests, simply execute `nimble test`.

import unittest

import wronglytaggednim
test "can add":
check add(5, 5) == 10
12 changes: 12 additions & 0 deletions tests/wronglytaggednim/wronglytaggednim.nimble
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Package

version = "0.1.0"
author = "jmgomez"
description = "A new awesome nimble package"
license = "MIT"
srcDir = "src"


# Dependencies

requires "nim >= 0.18.0", "random >= 0.5.6", "nimfp <= 0.4.5"

0 comments on commit 63f07b3

Please sign in to comment.