Updated source to eliminate stuff deprecated by nim 0.10.2
This commit is contained in:
parent
1efd705731
commit
383e0f2a4c
7 changed files with 56 additions and 45 deletions
|
|
@ -7,7 +7,8 @@ import httpclient, parseopt, os, strutils, osproc, pegs, tables, parseutils,
|
|||
from sequtils import toSeq
|
||||
|
||||
import nimblepkg/packageinfo, nimblepkg/version, nimblepkg/tools,
|
||||
nimblepkg/download, nimblepkg/config, nimblepkg/compat
|
||||
nimblepkg/download, nimblepkg/config, nimblepkg/compat,
|
||||
nimblepkg/nimbletypes
|
||||
|
||||
when not defined(windows):
|
||||
from posix import getpid
|
||||
|
|
@ -18,7 +19,7 @@ type
|
|||
queryVersions: bool
|
||||
action: TAction
|
||||
config: TConfig
|
||||
nimbleData: PJsonNode ## Nimbledata.json
|
||||
nimbleData: JsonNode ## Nimbledata.json
|
||||
|
||||
TActionType = enum
|
||||
ActionNil, ActionUpdate, ActionInit, ActionInstall, ActionSearch,
|
||||
|
|
@ -137,6 +138,8 @@ proc parseCmdLine(): TOptions =
|
|||
result.action.typ = ActionInstall
|
||||
of "path":
|
||||
result.action.typ = ActionPath
|
||||
else:
|
||||
discard
|
||||
result.action.packages = @[]
|
||||
of "build":
|
||||
result.action.typ = ActionBuild
|
||||
|
|
@ -177,6 +180,8 @@ proc parseCmdLine(): TOptions =
|
|||
result.action.projName = key
|
||||
of ActionList, ActionBuild:
|
||||
writeHelp()
|
||||
else:
|
||||
discard
|
||||
of cmdLongOption, cmdShortOption:
|
||||
case key
|
||||
of "help", "h": writeHelp()
|
||||
|
|
@ -184,6 +189,7 @@ proc parseCmdLine(): TOptions =
|
|||
of "accept", "y": result.forcePrompts = ForcePromptYes
|
||||
of "reject", "n": result.forcePrompts = ForcePromptNo
|
||||
of "ver": result.queryVersions = true
|
||||
else: discard
|
||||
of cmdEnd: assert(false) # cannot happen
|
||||
if result.action.typ == ActionNil:
|
||||
writeHelp()
|
||||
|
|
@ -266,7 +272,7 @@ proc copyWithExt(origDir, currentDir, dest: string,
|
|||
result.add copyFileD(path, changeRoot(origDir, dest, path))
|
||||
|
||||
proc copyFilesRec(origDir, currentDir, dest: string,
|
||||
options: TOptions, pkgInfo: TPackageInfo): TSet[string] =
|
||||
options: TOptions, pkgInfo: TPackageInfo): HashSet[string] =
|
||||
## Copies all the required files, skips files specified in the .nimble file
|
||||
## (TPackageInfo).
|
||||
## Returns a list of filepaths to files which have been installed.
|
||||
|
|
@ -323,7 +329,7 @@ proc saveNimbleData(options: TOptions) =
|
|||
|
||||
proc addRevDep(options: TOptions, dep: tuple[name, version: string],
|
||||
pkg: TPackageInfo) =
|
||||
let depNameVer = dep.name & '-' & dep.version
|
||||
# let depNameVer = dep.name & '-' & dep.version
|
||||
if not options.nimbleData["reverseDeps"].hasKey(dep.name):
|
||||
options.nimbleData["reverseDeps"][dep.name] = newJObject()
|
||||
if not options.nimbleData["reverseDeps"][dep.name].hasKey(dep.version):
|
||||
|
|
@ -336,7 +342,7 @@ proc addRevDep(options: TOptions, dep: tuple[name, version: string],
|
|||
proc removeRevDep(options: TOptions, pkg: TPackageInfo) =
|
||||
## Removes ``pkg`` from the reverse dependencies of every package.
|
||||
proc remove(options: TOptions, pkg: TPackageInfo, depTup: TPkgTuple,
|
||||
thisDep: PJsonNode) =
|
||||
thisDep: JsonNode) =
|
||||
for ver, val in thisDep:
|
||||
if ver.newVersion in depTup.ver:
|
||||
var newVal = newJArray()
|
||||
|
|
@ -403,7 +409,7 @@ proc processDeps(pkginfo: TPackageInfo, options: TOptions): seq[string] =
|
|||
|
||||
# Check if two packages of the same name (but different version) are listed
|
||||
# in the path.
|
||||
var pkgsInPath: PStringTable = newStringTable(modeCaseSensitive)
|
||||
var pkgsInPath: StringTableRef = newStringTable(modeCaseSensitive)
|
||||
for p in result:
|
||||
let (name, version) = getNameVersion(p)
|
||||
if pkgsInPath.hasKey(name) and pkgsInPath[name] != version:
|
||||
|
|
@ -430,7 +436,7 @@ proc buildFromDir(pkgInfo: TPackageInfo, paths: seq[string]) =
|
|||
doCmd(getNimBin() & " $# -d:release --noBabelPath $# \"$#\"" %
|
||||
[pkgInfo.backend, args, realDir / bin.changeFileExt("nim")])
|
||||
|
||||
proc saveNimbleMeta(pkgDestDir, url: string, filesInstalled: TSet[string]) =
|
||||
proc saveNimbleMeta(pkgDestDir, url: string, filesInstalled: HashSet[string]) =
|
||||
var nimblemeta = %{"url": %url}
|
||||
nimblemeta["files"] = newJArray()
|
||||
for file in filesInstalled:
|
||||
|
|
@ -442,7 +448,7 @@ proc removePkgDir(dir: string, options: TOptions) =
|
|||
try:
|
||||
var nimblemeta = parseFile(dir / "nimblemeta.json")
|
||||
if not nimblemeta.hasKey("files"):
|
||||
raise newException(EJsonParsingError,
|
||||
raise newException(JsonParsingError,
|
||||
"Meta data does not contain required info.")
|
||||
for file in nimblemeta["files"]:
|
||||
removeFile(dir / file.str)
|
||||
|
|
@ -455,7 +461,7 @@ proc removePkgDir(dir: string, options: TOptions) =
|
|||
else:
|
||||
echo("WARNING: Cannot completely remove " & dir &
|
||||
". Files not installed by nimble are present.")
|
||||
except EOS, EJsonParsingError:
|
||||
except OSError, JsonParsingError:
|
||||
echo("Error: Unable to read nimblemeta.json: ", getCurrentExceptionMsg())
|
||||
if not options.prompt("Would you like to COMPLETELY remove ALL files " &
|
||||
"in " & dir & "?"):
|
||||
|
|
@ -500,7 +506,7 @@ proc installFromDir(dir: string, latest: bool, options: TOptions,
|
|||
removeFile(binDir / bin)
|
||||
|
||||
## Will contain a list of files which have been installed.
|
||||
var filesInstalled: TSet[string]
|
||||
var filesInstalled: HashSet[string]
|
||||
|
||||
createDir(pkgDestDir)
|
||||
if pkgInfo.bin.len > 0:
|
||||
|
|
@ -710,7 +716,7 @@ proc init(options: TOptions) =
|
|||
echo("Initializing new Nimble project!")
|
||||
var
|
||||
pkgName, fName: string = ""
|
||||
outFile: TFile
|
||||
outFile: File
|
||||
|
||||
if (options.action.projName != ""):
|
||||
pkgName = options.action.projName
|
||||
|
|
@ -743,7 +749,7 @@ proc init(options: TOptions) =
|
|||
|
||||
else:
|
||||
raise newException(ENimble, "Unable to open file " & fName &
|
||||
" for writing: " & osErrorMsg())
|
||||
" for writing: " & osErrorMsg(osLastError()))
|
||||
|
||||
proc uninstall(options: TOptions) =
|
||||
var pkgsToDelete: seq[TPackageInfo] = @[]
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# BSD License. Look at license.txt for more info.
|
||||
import parsecfg, streams, strutils, os
|
||||
|
||||
import tools, version
|
||||
import tools, version, nimbletypes
|
||||
|
||||
type
|
||||
TConfig* = object
|
||||
|
|
@ -32,7 +32,7 @@ proc parseConfig*(): TConfig =
|
|||
|
||||
if f != nil:
|
||||
echo("Reading from config file at ", confFile)
|
||||
var p: TCfgParser
|
||||
var p: CfgParser
|
||||
open(p, f, confFile)
|
||||
while true:
|
||||
var e = next(p)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
import parseutils, os, osproc, strutils, tables, pegs
|
||||
|
||||
import packageinfo, version, tools
|
||||
import packageinfo, version, tools, nimbletypes
|
||||
|
||||
type
|
||||
TDownloadMethod* {.pure.} = enum
|
||||
|
|
@ -98,7 +98,7 @@ proc getTagsListRemote*(url: string, meth: TDownloadMethod): seq[string] =
|
|||
of TDownloadMethod.Git:
|
||||
var (output, exitCode) = doCmdEx("git ls-remote --tags " & url)
|
||||
if exitCode != QuitSuccess:
|
||||
raise newException(EOS, "Unable to query remote tags for " & url &
|
||||
raise newException(OSError, "Unable to query remote tags for " & url &
|
||||
". Git returned: " & output)
|
||||
for i in output.splitLines():
|
||||
if i == "": continue
|
||||
|
|
@ -108,9 +108,9 @@ proc getTagsListRemote*(url: string, meth: TDownloadMethod): seq[string] =
|
|||
|
||||
of TDownloadMethod.Hg:
|
||||
# http://stackoverflow.com/questions/2039150/show-tags-for-remote-hg-repository
|
||||
raise newException(EInvalidValue, "Hg doesn't support remote tag querying.")
|
||||
raise newException(ValueError, "Hg doesn't support remote tag querying.")
|
||||
|
||||
proc getVersionList*(tags: seq[string]): TTable[TVersion, string] =
|
||||
proc getVersionList*(tags: seq[string]): Table[TVersion, string] =
|
||||
# Returns: TTable of version -> git tag name
|
||||
result = initTable[TVersion, string]()
|
||||
for tag in tags:
|
||||
|
|
@ -225,7 +225,7 @@ proc echoPackageVersions*(pkg: TPackage) =
|
|||
echo(" versions: " & vstr)
|
||||
else:
|
||||
echo(" versions: (No versions tagged in the remote repository)")
|
||||
except EOS:
|
||||
except OSError:
|
||||
echo(getCurrentExceptionMsg())
|
||||
of TDownloadMethod.Hg:
|
||||
echo(" versions: (Remote tag retrieval not supported by " & pkg.downloadMethod & ")")
|
||||
|
|
|
|||
7
src/nimblepkg/nimbletypes.nim
Normal file
7
src/nimblepkg/nimbletypes.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# BSD License. Look at license.txt for more info.
|
||||
#
|
||||
# Various miscellaneous common types reside here, to avoid problems with
|
||||
# recursive imports
|
||||
|
||||
type
|
||||
ENimble* = object of Exception
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
# Copyright (C) Dominik Picheta. All rights reserved.
|
||||
# BSD License. Look at license.txt for more info.
|
||||
import parsecfg, json, streams, strutils, parseutils, os
|
||||
import version, tools
|
||||
import version, tools, nimbletypes
|
||||
type
|
||||
## Tuple containing package name and version range.
|
||||
TPkgTuple* = tuple[name: string, ver: PVersionRange]
|
||||
|
|
@ -120,7 +120,7 @@ proc readPackageInfo*(path: string): TPackageInfo =
|
|||
result.mypath = path
|
||||
var fs = newFileStream(path, fmRead)
|
||||
if fs != nil:
|
||||
var p: TCfgParser
|
||||
var p: CfgParser
|
||||
open(p, fs, path)
|
||||
var currentSection = ""
|
||||
while true:
|
||||
|
|
@ -159,6 +159,7 @@ proc readPackageInfo*(path: string): TPackageInfo =
|
|||
result.backend = ev.value.toLower()
|
||||
case result.backend.normalize
|
||||
of "javascript": result.backend = "js"
|
||||
else: discard
|
||||
else:
|
||||
raise newException(ENimble, "Invalid field: " & ev.key)
|
||||
of "deps", "dependencies":
|
||||
|
|
@ -174,23 +175,23 @@ proc readPackageInfo*(path: string): TPackageInfo =
|
|||
raise newException(ENimble, "Error parsing .nimble file: " & ev.msg)
|
||||
close(p)
|
||||
else:
|
||||
raise newException(EInvalidValue, "Cannot open package info: " & path)
|
||||
raise newException(ValueError, "Cannot open package info: " & path)
|
||||
validatePackageInfo(result, path)
|
||||
|
||||
proc optionalField(obj: PJsonNode, name: string, default = ""): string =
|
||||
proc optionalField(obj: JsonNode, name: string, default = ""): string =
|
||||
## Queries ``obj`` for the optional ``name`` string.
|
||||
##
|
||||
## Returns the value of ``name`` if it is a valid string, or aborts execution
|
||||
## if the field exists but is not of string type. If ``name`` is not present,
|
||||
## returns ``default``.
|
||||
if existsKey(obj, name):
|
||||
if hasKey(obj, name):
|
||||
if obj[name].kind == JString:
|
||||
return obj[name].str
|
||||
else:
|
||||
raise newException(ENimble, "Corrupted packages.json file. " & name & " field is of unexpected type.")
|
||||
else: return default
|
||||
|
||||
proc requiredField(obj: PJsonNode, name: string): string =
|
||||
proc requiredField(obj: JsonNode, name: string): string =
|
||||
## Queries ``obj`` for the required ``name`` string.
|
||||
##
|
||||
## Aborts execution if the field does not exist or is of invalid json type.
|
||||
|
|
@ -199,7 +200,7 @@ proc requiredField(obj: PJsonNode, name: string): string =
|
|||
raise newException(ENimble,
|
||||
"Package in packages.json file does not contain a " & name & " field.")
|
||||
|
||||
proc fromJson(obj: PJSonNode): TPackage =
|
||||
proc fromJson(obj: JSonNode): TPackage =
|
||||
## Constructs a TPackage object from a JSON node.
|
||||
##
|
||||
## Aborts execution if the JSON node doesn't contain the required fields.
|
||||
|
|
|
|||
|
|
@ -2,11 +2,8 @@
|
|||
# BSD License. Look at license.txt for more info.
|
||||
#
|
||||
# Various miscellaneous utility functions reside here.
|
||||
import osproc, pegs, strutils, os, parseurl, sets, json
|
||||
import version, packageinfo
|
||||
|
||||
type
|
||||
ENimble* = object of EBase
|
||||
import osproc, pegs, strutils, os, uri, sets, json
|
||||
import version, packageinfo, nimbletypes
|
||||
|
||||
proc doCmd*(cmd: string) =
|
||||
let bin = cmd.split(' ')[0]
|
||||
|
|
@ -61,7 +58,7 @@ proc changeRoot*(origRoot, newRoot, path: string): string =
|
|||
if path.startsWith(origRoot):
|
||||
return newRoot / path[origRoot.len .. -1]
|
||||
else:
|
||||
raise newException(EInvalidValue,
|
||||
raise newException(ValueError,
|
||||
"Cannot change root of path: Path does not begin with original root.")
|
||||
|
||||
proc copyFileD*(fro, to: string): string =
|
||||
|
|
@ -78,37 +75,37 @@ proc copyDirD*(fro, to: string): seq[string] =
|
|||
createDir(changeRoot(fro, to, path.splitFile.dir))
|
||||
result.add copyFileD(path, changeRoot(fro, to, path))
|
||||
|
||||
proc getDownloadDirName*(url: string, verRange: PVersionRange): string =
|
||||
## Creates a directory name based on the specified ``url``
|
||||
proc getDownloadDirName*(uri: string, verRange: PVersionRange): string =
|
||||
## Creates a directory name based on the specified ``uri`` (url)
|
||||
result = ""
|
||||
let purl = parseUrl(url)
|
||||
for i in purl.hostname:
|
||||
let puri = parseUri(uri)
|
||||
for i in puri.hostname:
|
||||
case i
|
||||
of strutils.Letters, strutils.Digits:
|
||||
result.add i
|
||||
else: nil
|
||||
else: discard
|
||||
result.add "_"
|
||||
for i in purl.path:
|
||||
for i in puri.path:
|
||||
case i
|
||||
of strutils.Letters, strutils.Digits:
|
||||
result.add i
|
||||
else: nil
|
||||
else: discard
|
||||
|
||||
let verSimple = getSimpleString(verRange)
|
||||
if verSimple != "":
|
||||
result.add "_"
|
||||
result.add verSimple
|
||||
|
||||
proc incl*(s: var TSet[string], v: seq[string] | TSet[string]) =
|
||||
proc incl*(s: var HashSet[string], v: seq[string] | HashSet[string]) =
|
||||
for i in v:
|
||||
s.incl i
|
||||
|
||||
proc contains*(j: PJsonNode, elem: PJsonNode): bool =
|
||||
proc contains*(j: JsonNode, elem: JsonNode): bool =
|
||||
for i in j:
|
||||
if i == elem:
|
||||
return true
|
||||
|
||||
proc contains*(j: PJsonNode, elem: tuple[key: string, val: PJsonNode]): bool =
|
||||
proc contains*(j: JsonNode, elem: tuple[key: string, val: JsonNode]): bool =
|
||||
for key, val in pairs(j):
|
||||
if key == elem.key and val == elem.val:
|
||||
return true
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ type
|
|||
of verAny:
|
||||
nil
|
||||
|
||||
EParseVersion* = object of EInvalidValue
|
||||
EParseVersion* = object of ValueError
|
||||
|
||||
proc newVersion*(ver: string): TVersion = return TVersion(ver)
|
||||
proc newSpecial*(spe: string): TSpecial = return TSpecial(spe)
|
||||
|
|
@ -55,7 +55,7 @@ proc `<`*(ver: TVersion, ver2: TVersion): bool =
|
|||
if sVerI < sVerI2:
|
||||
return true
|
||||
elif sVerI == sVerI2:
|
||||
nil
|
||||
discard
|
||||
else:
|
||||
return false
|
||||
|
||||
|
|
@ -229,7 +229,7 @@ proc newVREq*(ver: string): PVersionRange =
|
|||
result.kind = verEq
|
||||
result.ver = newVersion(ver)
|
||||
|
||||
proc findLatest*(verRange: PVersionRange, versions: TTable[TVersion, string]): tuple[ver: TVersion, tag: string] =
|
||||
proc findLatest*(verRange: PVersionRange, versions: Table[TVersion, string]): tuple[ver: TVersion, tag: string] =
|
||||
result = (newVersion(""), "")
|
||||
for ver, tag in versions:
|
||||
if not withinRange(ver, verRange): continue
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue