From 9c9e566a0b63ecc3b588233047272fd889a218da Mon Sep 17 00:00:00 2001 From: Pietro Peterlongo Date: Wed, 1 Feb 2023 09:51:40 +0100 Subject: [PATCH 1/4] Adding devel to CI I am adding both stable (that will become 2.x soon) and devel (which is candidate for 2.x). Also update versions of cache and setup-nim-action --- .github/workflows/test.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fcf52092..0d4fb7d9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,11 +7,18 @@ on: jobs: tests: runs-on: ubuntu-latest + strategy: + matrix: + nim: + - '1.6.x' + - 'stable' + - 'devel' + name: Nim ${{ matrix.nim }} steps: - - uses: actions/checkout@v2 - - uses: jiro4989/setup-nim-action@v1.3.15 + - uses: actions/checkout@v3 + - uses: jiro4989/setup-nim-action@v1.4.3 with: - nim-version: '1.6.x' + nim-version: ${{ matrix.nim }} - run: nimble -y install - run: nimble docsdeps - run: nimble test From 57458cace9dacdb5129d5bfec137ddc259918f26 Mon Sep 17 00:00:00 2001 From: Pietro Peterlongo Date: Wed, 1 Feb 2023 10:07:27 +0100 Subject: [PATCH 2/4] disable fail-fast for test CI see https://stackoverflow.com/a/65647509/4178189 --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0d4fb7d9..d80f86c2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,6 +13,7 @@ jobs: - '1.6.x' - 'stable' - 'devel' + fail-fast: false name: Nim ${{ matrix.nim }} steps: - uses: actions/checkout@v3 From a2bf928efdb41993baf032495ed78413fcc624be Mon Sep 17 00:00:00 2001 From: Pietro Peterlongo Date: Thu, 9 Feb 2023 11:23:26 +0100 Subject: [PATCH 3/4] Change toml lib + fix macro bug on devel (#173) (#174) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix orc macro bug * replace toml_serialization with parsetoml * clean up * use jsony for deserialzation as it can handle missing fields Co-authored-by: Hugo Granström <5092565+HugoGranstrom@users.noreply.github.com> --- nimib.nimble | 3 ++- src/nimib/config.nim | 62 +++++++++++++++++++++++++++++++++++++++++-- src/nimib/sources.nim | 5 +++- 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/nimib.nimble b/nimib.nimble index f7d2ab5f..72f4fa44 100644 --- a/nimib.nimble +++ b/nimib.nimble @@ -12,7 +12,8 @@ requires "nim >= 1.4.0" requires "tempfile >= 0.1.6" requires "markdown >= 0.8.1" requires "mustache >= 0.2.1" -requires "toml_serialization >= 0.2.0" +requires "parsetoml >= 0.7.0" +requires "jsony >= 1.1.5" task docsdeps, "install dependendencies required for doc building": exec "nimble -y install ggplotnim@0.5.3 numericalnim@0.6.1 nimoji nimpy karax@1.2.2" diff --git a/src/nimib/config.nim b/src/nimib/config.nim index 10272969..1734c5bc 100644 --- a/src/nimib/config.nim +++ b/src/nimib/config.nim @@ -1,4 +1,4 @@ -import types, os, toml_serialization +import types, parsetoml, jsony, std / [json, os, math, sequtils] proc hasCfg*(doc: var NbDoc): bool = doc.cfgDir.string != "" @@ -13,6 +13,64 @@ proc optOverride*(doc: var NbDoc) = if doc.options.homeDir != "": doc.cfg.homeDir = doc.options.homeDir + +proc customToJson*(table: parsetoml.TomlTableRef): JsonNode + +proc customToJson*(value: parsetoml.TomlValueRef): JsonNode = + case value.kind: + of TomlValueKind.Int: + %* value.intVal + of TomlValueKind.Float: + if classify(value.floatVal) == fcNan: + if value.forcedSign != Pos: + %* value.floatVal + else: + %* value.floatVal + else: + %* value.floatVal + of TomlValueKind.Bool: + %* $value.boolVal + of TomlValueKind.Datetime: + if value.dateTimeVal.shift == false: + %* value.dateTimeVal + else: + %* value.dateTimeVal + of TomlValueKind.Date: + %* value.dateVal + of TomlValueKind.Time: + %* value.timeVal + of TomlValueKind.String: + %* value.stringVal + of TomlValueKind.Array: + if value.arrayVal.len == 0: + when defined(newtestsuite): + %[] + else: + %* [] + elif value.arrayVal[0].kind == TomlValueKind.Table: + %value.arrayVal.map(customToJson) + else: + when defined(newtestsuite): + %*value.arrayVal.map(customToJson) + else: + %* value.arrayVal.map(customToJson) + of TomlValueKind.Table: + value.tableVal.customToJson() + of TomlValueKind.None: + %*{"type": "ERROR"} + +proc customToJson*(table: parsetoml.TomlTableRef): JsonNode = + result = newJObject() + for key, value in pairs(table): + result[key] = value.customToJson + + +proc loadTomlSection*[T](content, section: string, _: typedesc[T]): T = + let toml = parsetoml.parseString(content) + result = T() + if section in toml: + result = ($toml[section].customToJson()).fromJson(T) + proc loadNimibCfg*(cfgName: string): tuple[found: bool, dir: AbsoluteDir, raw: string, nb: NbConfig] = for dir in parentDirs(getCurrentDir()): if fileExists(dir / cfgName): @@ -22,7 +80,7 @@ proc loadNimibCfg*(cfgName: string): tuple[found: bool, dir: AbsoluteDir, raw: s break if result.found: result.raw = readFile(result.dir.string / cfgName) - result.nb = Toml.decode(result.raw, NbConfig, "nimib") + result.nb = loadTomlSection(result.raw, "nimib", NbConfig) proc loadCfg*(doc: var NbDoc) = if not doc.options.skipCfg: diff --git a/src/nimib/sources.nim b/src/nimib/sources.nim index 81799e15..55ca7d43 100644 --- a/src/nimib/sources.nim +++ b/src/nimib/sources.nim @@ -151,6 +151,9 @@ macro getCodeAsInSource*(source: string, command: static string, body: untyped): let endPos = finishPos(body) let endFilename = endPos.filename.newLit + let endPosLit = endPos.newLit + let startPosLit = startPos.newLit + result = quote do: if `filename` notin nb.sourceFiles: nb.sourceFiles[`filename`] = readFile(`filename`) @@ -160,4 +163,4 @@ macro getCodeAsInSource*(source: string, command: static string, body: untyped): If you want to mix code from different files in nbCode, use -d:nimibCodeFromAst instead. If you are not mixing code from different files, please open an issue on nimib's Github with a minimal reproducible example.""" - getCodeBlock(nb.sourceFiles[`filename`], `command`, `startPos`, `endPos`) \ No newline at end of file + getCodeBlock(nb.sourceFiles[`filename`], `command`, `startPosLit`, `endPosLit`) \ No newline at end of file From a3461674bd6d6fb1bfb74d4674a4aafd4e228ce6 Mon Sep 17 00:00:00 2001 From: Pietro Peterlongo Date: Thu, 9 Feb 2023 11:33:38 +0100 Subject: [PATCH 4/4] bump to 0.3.6 --- nimib.nimble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nimib.nimble b/nimib.nimble index 72f4fa44..71159546 100644 --- a/nimib.nimble +++ b/nimib.nimble @@ -1,6 +1,6 @@ # Package -version = "0.3.5" +version = "0.3.6" author = "Pietro Peterlongo & Hugo Granström" description = "nimib 🐳 - nim 👑 driven ⛵ publishing ✍" license = "MIT"