Renamed myVersion to version and version to specialVersion.

This commit is contained in:
Dominik Picheta 2016-12-27 13:27:08 +00:00
commit 432c91b938
5 changed files with 43 additions and 35 deletions

View file

@ -15,16 +15,16 @@ when not defined(nimscript):
PackageInfo* = object
myPath*: string ## The path of this .nimble file
## The version specified in the .nimble file.Assuming info is non-minimal,
## it will always be a non-special version such as '0.1.4'
myVersion*: string
isNimScript*: bool ## Determines if this pkg info was read from a nims file
isMinimal*: bool
isInstalled*: bool ## Determines if the pkg this info belongs to is installed
postHooks*: HashSet[string] ## Useful to know so that Nimble doesn't execHook unnecessarily
preHooks*: HashSet[string]
name*: string
version*: string ## Either `myVersion` or a special version such as #head.
## The version specified in the .nimble file.Assuming info is non-minimal,
## it will always be a non-special version such as '0.1.4'
version*: string
specialVersion*: string ## Either `myVersion` or a special version such as #head.
author*: string
description*: string
license*: string

View file

@ -22,7 +22,7 @@ type
proc initPackageInfo*(path: string): PackageInfo =
result.myPath = path
result.myVersion = ""
result.specialVersion = ""
result.preHooks.init()
result.postHooks.init()
# reasonable default:
@ -195,11 +195,19 @@ proc getInstalledPkgsMin*(libsDir: string, options: Options):
var pkg = initPackageInfo(nimbleFile)
pkg.name = name
pkg.version = version
pkg.specialVersion = version
pkg.isMinimal = true
pkg.isInstalled = true
result.add((pkg, meta))
proc findPkg*(pkglist: seq[tuple[pkginfo: PackageInfo, meta: MetaData]],
proc withinRange*(pkgInfo: PackageInfo, verRange: VersionRange): bool =
## Determines whether the specified package's version is within the
## specified range. The check works with ordinary versions as well as
## special ones.
return withinRange(newVersion(pkgInfo.version), verRange) or
withinRange(newVersion(pkgInfo.specialVersion), verRange)
proc findPkg*(pkglist: seq[tuple[pkgInfo: PackageInfo, meta: MetaData]],
dep: PkgTuple,
r: var PackageInfo): bool =
## Searches ``pkglist`` for a package of which version is within the range
@ -211,22 +219,23 @@ proc findPkg*(pkglist: seq[tuple[pkginfo: PackageInfo, meta: MetaData]],
for pkg in pkglist:
if cmpIgnoreStyle(pkg.pkginfo.name, dep.name) != 0 and
cmpIgnoreStyle(pkg.meta.url, dep.name) != 0: continue
if withinRange(newVersion(pkg.pkginfo.myVersion), dep.ver) or
withinRange(newVersion(pkg.pkginfo.version), dep.ver):
if not result or newVersion(r.version) < newVersion(pkg.pkginfo.myVersion):
if withinRange(pkg.pkgInfo, dep.ver):
let isNewer = (not r.version.isNil) and
newVersion(r.version) < newVersion(pkg.pkginfo.version)
if not result or isNewer:
r = pkg.pkginfo
result = true
proc findAllPkgs*(pkglist: seq[tuple[pkginfo: PackageInfo, meta: MetaData]],
proc findAllPkgs*(pkglist: seq[tuple[pkgInfo: PackageInfo, meta: MetaData]],
dep: PkgTuple): seq[PackageInfo] =
## Searches ``pkglist`` for packages of which version is within the range
## of ``dep.ver``. This is similar to ``findPkg`` but returns multiple
## packages if multiple are found.
result = @[]
for pkg in pkglist:
if cmpIgnoreStyle(pkg.pkginfo.name, dep.name) != 0 and
if cmpIgnoreStyle(pkg.pkgInfo.name, dep.name) != 0 and
cmpIgnoreStyle(pkg.meta.url, dep.name) != 0: continue
if withinRange(newVersion(pkg.pkginfo.version), dep.ver):
if withinRange(pkg.pkgInfo, dep.ver):
result.add pkg.pkginfo
proc getRealDir*(pkgInfo: PackageInfo): string =

View file

@ -273,6 +273,7 @@ proc readPackageInfo(nf: NimbleFile, options: Options,
if onlyMinimalInfo:
result.name = minimalInfo.name
result.version = minimalInfo.version
result.specialVersion = result.version
result.isNimScript = true
result.isMinimal = true
else:
@ -287,21 +288,18 @@ proc readPackageInfo(nf: NimbleFile, options: Options,
" " & getCurrentExceptionMsg() & "."
raise newException(NimbleError, msg)
# Validate version ahead of time, we will be potentially overwriting it soon.
result.myVersion = result.version
validateVersion(result.version)
# The package directory name may include a "special" version
# (example #head). If so, it is given higher priority and therefore
# overwrites the .nimble file's version.
let version = parseVersionRange(minimalInfo.version)
if version.kind == verSpecial:
result.version = minimalInfo.version
result.specialVersion = minimalInfo.version
if not result.isMinimal:
options.pkgInfoCache[nf] = result
# Validate the rest of the package info last.
validateVersion(result.version)
validatePackageInfo(result, options)
proc getPkgInfoFromFile*(file: NimbleFile, options: Options): PackageInfo =