Types
UriParseError = object of Defect
- Source Edit
Consts
NIM_SCRIPT_API_TEMPLATE = "# Copyright (C) Dominik Picheta. All rights reserved.\n# BSD License. Look at license.txt for more info.\n\n## This module is implicitly imported in NimScript .nimble files.\n\nimport system except getCommand, setCommand, switch, `--`\nimport strformat, strutils, tables, sequtils\nexport tables\n\n\nvar\n packageName* = \"\" ## Set this to the package name. It\n ## is usually not required to do that, nims\' filename is\n ## the default.\n version*: string ## The package\'s version.\n author*: string ## The package\'s author.\n description*: string ## The package\'s description.\n license*: string ## The package\'s license.\n srcDir*: string ## The package\'s source directory.\n binDir*: string ## The package\'s binary directory.\n backend*: string ## The package\'s backend.\n\n skipDirs*, skipFiles*, skipExt*, installDirs*, installFiles*,\n installExt*, bin*, paths*, entryPoints*: seq[string] = @[] ## Nimble metadata.\n requiresData*: seq[string] = @[] ## The package\'s dependencies.\n taskRequiresData*: Table[string, seq[string]] ## Task dependencies\n foreignDeps*: seq[string] = @[] ## The foreign dependencies. Only\n ## exported for \'distros.nim\'.\n\n nimbleTasks*: seq[tuple[name, description: string]] = @[]\n beforeHooks*: seq[string] = @[]\n afterHooks*: seq[string] = @[]\n flags*: Table[string, seq[string]]\n namedBin*: Table[string, string]\n\n command* = \"e\"\n project* = \"\"\n success* = false\n retVal* = true\n nimblePathsEnv* = \"__NIMBLE_PATHS\"\n\nproc requires*(deps: varargs[string]) =\n ## Call this to set the list of requirements of your Nimble\n ## package.\n for d in deps: requiresData.add(d)\n\nproc taskRequires*(task: string, deps: varargs[string]) =\n ## Call this to set the list of requirements for a certain task\n if task notin taskRequiresData:\n taskRequiresData[task] = @[]\n for d in deps:\n taskRequiresData[task] &= d\n\nproc getParams(): tuple[scriptFile, projectFile, outFile, actionName: string,\n commandLineParams: seq[string]] =\n result = (scriptFile: \"\", projectFile: \"\", outFile: \"\", actionName: \"\", commandLineParams: @[])\n # Called by nimscriptwrapper.nim:execNimscript()\n # nim e --flags /full/path/to/file.nims /full/path/to/file.nimble /full/path/to/file.out action\n for i in 2 .. nimscript.paramCount():\n let\n param = nimscript.paramStr(i)\n if param[0] != \'-\':\n if result.scriptFile.len == 0:\n result.scriptFile = param\n elif result.projectFile.len == 0:\n result.projectFile = param\n elif result.outFile.len == 0:\n result.outFile = param\n elif result.actionName.len == 0:\n result.actionName = param.normalize\n else:\n result.commandLineParams.add param\n else:\n result.commandLineParams.add param\n\nlet #if we make this const nimsuggest would crash \n # Command line values are const so that thisDir() works at compile time\n (scriptFile, projectFile, outFile, actionName, commandLineParams*) = getParams()\n NimbleVersion* {.strdefine.} = \"\"\n NimbleMajor* {.intdefine.} = 0\n NimbleMinor* {.intdefine.} = 0\n NimblePatch* {.intdefine.} = 0\n\nproc getCommand*(): string =\n return command\n\nproc setCommand*(cmd: string, prj = \"\") =\n command = cmd\n if prj.len != 0:\n project = prj\n\nproc switch*(key: string, value=\"\") =\n if flags.hasKey(key):\n flags[key].add(value)\n else:\n flags[key] = @[value]\n\ntemplate `--`*(key, val: untyped) =\n switch(astToStr(key), strip astToStr(val))\n\ntemplate `--`*(key: untyped) =\n switch(astToStr(key), \"\")\n\ntemplate printIfLen(varName) =\n if varName.len != 0:\n result &= astToStr(varName) & \": \\\"\\\"\\\"\" & varName & \"\\\"\\\"\\\"\\n\"\n\ntemplate printSeqIfLen(name: string, varName: untyped) =\n if varName.len != 0:\n result &= name & \": \\\"\" & varName.join(\", \") & \"\\\"\\n\"\n\ntemplate printSeqIfLen(varName) =\n printSeqIfLen(astToStr(varName), varName)\n\nproc printPkgInfo(): string =\n if backend.len == 0:\n backend = \"c\"\n\n # Forward `namedBin` entries in `bin`\n for k, v in namedBin:\n let idx = bin.find(k)\n if idx == -1:\n bin.add k & \"=\" & v\n else:\n bin[idx] = k & \"=\" & v\n\n result = \"[Package]\\n\"\n if packageName.len != 0:\n result &= \"name: \\\"\" & packageName & \"\\\"\\n\"\n printIfLen version\n printIfLen author\n printIfLen description\n printIfLen license\n printIfLen srcDir\n printIfLen binDir\n printIfLen backend\n\n printSeqIfLen skipDirs\n printSeqIfLen skipFiles\n printSeqIfLen skipExt\n printSeqIfLen installDirs\n printSeqIfLen installFiles\n printSeqIfLen installExt\n printSeqIfLen paths\n printSeqIfLen entryPoints\n printSeqIfLen bin\n printSeqIfLen \"nimbleTasks\", nimbleTasks.unzip()[0]\n printSeqIfLen beforeHooks\n printSeqIfLen afterHooks\n\n if requiresData.len != 0 or taskRequiresData.len != 0:\n result &= \"\\n[Deps]\\n\"\n # Write package level dependencies\n if requiresData.len != 0:\n result &= &\"requires: \\\"{requiresData.join(\\\", \\\")}\\\"\\n\"\n # Write task level dependencies\n for task, requiresData in taskRequiresData.pairs:\n result &= &\"{task}Requires: \\\"{requiresData.join(\\\", \\\")}\\\"\\n\"\n\n\nproc onExit*() =\n if actionName.len == 0 or actionName == \"help\":\n var maxNameLen = 8\n for (name, _) in nimbleTasks:\n maxNameLen = max(maxNameLen, name.len)\n for (name, description) in nimbleTasks:\n echo alignLeft(name, maxNameLen + 2), description\n\n if \"printPkgInfo\".normalize == actionName:\n if outFile.len != 0:\n writeFile(outFile, printPkgInfo())\n else:\n var\n output = \"\"\n output &= \"\\\"success\\\": \" & $success & \", \"\n output &= \"\\\"command\\\": \\\"\" & command & \"\\\", \"\n if project.len != 0:\n output &= \"\\\"project\\\": \\\"\" & project & \"\\\", \"\n if flags.len != 0:\n output &= \"\\\"flags\\\": {\"\n for key, val in flags.pairs:\n output &= \"\\\"\" & key & \"\\\": [\"\n for v in val:\n let v = if v.len > 0 and v[0] == \'\"\': strutils.unescape(v)\n else: v\n output &= v.escape & \", \"\n output = output[0 .. ^3] & \"], \"\n output = output[0 .. ^3] & \"}, \"\n\n output &= \"\\\"retVal\\\": \" & $retVal\n\n if outFile.len != 0:\n writeFile(outFile, \"{\" & output & \"}\")\n\n# TODO: New release of Nim will move this `task` template under a\n# `when not defined(nimble)`. This will allow us to override it in the future.\ntemplate task*(name: untyped; description: string; body: untyped): untyped =\n ## Defines a task. Hidden tasks are supported via an empty description.\n ## Example:\n ##\n ## .. code-block:: nim\n ## task build, \"default build is via the C backend\":\n ## setCommand \"c\"\n proc `name Task`*() = body\n\n nimbleTasks.add (astToStr(name), description)\n\n if actionName.len == 0 or actionName == \"help\":\n success = true\n elif actionName == astToStr(name).normalize:\n success = true\n `name Task`()\n\ntemplate before*(action: untyped, body: untyped): untyped =\n ## Defines a block of code which is evaluated before ``action`` is executed.\n proc `action Before`*(): bool =\n result = true\n body\n\n beforeHooks.add astToStr(action)\n\n if (astToStr(action) & \"Before\").normalize == actionName:\n success = true\n retVal = `action Before`()\n\ntemplate after*(action: untyped, body: untyped): untyped =\n ## Defines a block of code which is evaluated after ``action`` is executed.\n proc `action After`*(): bool =\n result = true\n body\n\n afterHooks.add astToStr(action)\n\n if (astToStr(action) & \"After\").normalize == actionName:\n success = true\n retVal = `action After`()\n\nconst nimbleExe* {.strdefine.} = \"nimble\"\n\nproc getPkgDir*(): string =\n ## Returns the package directory containing the .nimble file currently\n ## being evaluated.\n result = projectFile.rsplit(seps={\'/\', \'\\\\\', \':\'}, maxsplit=1)[0]\n\nproc thisDir*(): string = getPkgDir()\n\nproc getPaths*(): seq[string] =\n ## Returns the paths to the dependencies\n return getEnv(nimblePathsEnv).split(\"|\")\n\nproc getPathsClause*(): string =\n ## Returns the paths to the dependencies as consumed by the nim compiler.\n return getPaths().mapIt(\"--path:\" & it).join(\" \")\n\ntemplate feature*(name: string, body: untyped): untyped =\n discard\n\ntemplate dev*(body: untyped): untyped =\n discard\n"
- Source Edit
Procs
proc addCallback(future: FutureBase; cb: proc () {.closure, ...gcsafe, raises: [].}) {. ...deprecated: "Replace with built-in chronos mechanism", raises: [], tags: [], forbids: [].}
-
Adds the callbacks proc to be called when the future completes.
If future has already completed then cb will be called immediately.
Source Edit proc addCallback[T](future: Future[T]; cb: proc (future: Future[T]) {.closure, ...gcsafe.}) {. ...deprecated.}
-
Adds the callbacks proc to be called when the future completes.
If future has already completed then cb will be called immediately.
Source Edit proc catchOrQuit(error: Exception) {....raises: [], tags: [WriteIOEffect], forbids: [].}
- Source Edit
proc createUTFMapping(line: string): FingerTable {....raises: [], tags: [], forbids: [].}
- Source Edit
proc ensureStorageDir(): string {....raises: [OSError, IOError], tags: [ ReadEnvEffect, ReadIOEffect, WriteDirEffect, ReadDirEffect], forbids: [].}
- Source Edit
proc getNextFreePort(): Port {....raises: [OSError, ValueError, Exception, LibraryError, SslError], tags: [ReadIOEffect, RootEffect], forbids: [].}
- Source Edit
proc getNimScriptAPITemplatePath(): string {....raises: [OSError, IOError], tags: [ ReadEnvEffect, WriteDirEffect, ReadDirEffect, ReadIOEffect, WriteIOEffect], forbids: [].}
- Source Edit
proc isRelTo(path, base: string): bool {....raises: [], tags: [RootEffect], forbids: [].}
-
isRelativeTo version that do not throws
Source Edit proc partial[A, B, C, D](fn: proc (a: A; b: B; c: C): D {....gcsafe, raises: [], nimcall.}; a: A): proc (b: B; c: C): D {....gcsafe, raises: [].}
- Source Edit
proc readAllOutput(stream: AsyncStreamReader): Future[string] {. ...stackTrace: false, raises: [], gcsafe, tags: [RootEffect], forbids: [].}
- Source Edit
proc readErrorOutputUntilExit(process: AsyncProcessRef; duration: Duration): Future[ tuple[output: string, code: int]] {....stackTrace: false, raises: [], gcsafe, tags: [RootEffect], forbids: [].}
- Source Edit
proc readOutputUntilExit(process: AsyncProcessRef; duration: Duration): Future[ tuple[output: string, error: string, code: int]] {....stackTrace: false, raises: [], gcsafe, tags: [RootEffect], forbids: [].}
- Source Edit
proc shutdownChildProcess(p: AsyncProcessRef): Future[void] {....stackTrace: false, raises: [], gcsafe, tags: [RootEffect], forbids: [].}
- Source Edit
proc traceAsyncErrors(fut: Future)
- Source Edit
proc tryRelativeTo(path, base: string): Option[string] {....raises: [], tags: [RootEffect], forbids: [].}
- Source Edit
proc withTimeout[T](fut: Future[T]; timeout: int = 500): Future[Option[T]] {. ...stackTrace: false, raises: [], gcsafe.}
- Source Edit
proc writeStackTrace(ex = getCurrentException()) {....raises: [], tags: [WriteIOEffect], forbids: [].}
- Source Edit