From d2eac93c0f65c204640bc292e0a487b0504af3c7 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 5 Feb 2025 11:06:18 +0100 Subject: [PATCH] applies formatting --- .github/workflows/main.yml | 12 ++++++++++++ README.md | 1 + codexcrawler.nim | 15 ++++++++++----- codexcrawler.nimble | 22 ++++++++++++++-------- codexcrawler/config.nim | 25 +++++++++++-------------- codexcrawler/main.nim | 3 +-- codexcrawler/version.nim | 4 ++-- tests/test.nimble | 12 ++++++------ 8 files changed, 57 insertions(+), 37 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3653389..6d393ce 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,6 +3,18 @@ name: CI on: [push, pull_request] jobs: + linting: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Check `nph` formatting + uses: arnetheduck/nph-action@v1 + with: + version: 0.6.1 + options: "./" + fail: true + suggest: true + test: runs-on: ${{ matrix.os }} strategy: diff --git a/README.md b/README.md index 57a023c..91927f3 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Metrics are published from a scrape target. # Usage ```sh +nimble format nimble build nimble test nimble run diff --git a/codexcrawler.nim b/codexcrawler.nim index 9c3ad81..6432a9c 100644 --- a/codexcrawler.nim +++ b/codexcrawler.nim @@ -3,14 +3,15 @@ import pkg/chronos import ./codexcrawler/main import ./codexcrawler/config +import ./codexcrawler/metrics when defined(posix): import system/ansi_c type ApplicationStatus {.pure.} = enum - Stopped, - Stopping, + Stopped + Stopping Running Application = ref object @@ -20,8 +21,11 @@ proc run(app: Application) = let config = parseConfig() info "Loaded configuration", config - app.status = ApplicationStatus.Running + setupMetrics(config.metricsAddress, config.metricsPort) + info "Metrics endpoint initialized" + info "Starting application" + app.status = ApplicationStatus.Running waitFor startApplication() while app.status == ApplicationStatus.Running: @@ -30,7 +34,7 @@ proc run(app: Application) = except Exception as exc: error "Unhandled exception", msg = exc.msg quit QuitFailure - notice "Done" + notice "Application closed" when isMainModule: let app = Application() @@ -46,7 +50,8 @@ when isMainModule: # workaround for https://github.com/nim-lang/Nim/issues/4057 try: setupForeignThreadGc() - except Exception as exc: raiseAssert exc.msg + except Exception as exc: + raiseAssert exc.msg notice "Shutting down after having received SIGINT" onStopSignal() diff --git a/codexcrawler.nimble b/codexcrawler.nimble index 7fa17af..008e299 100644 --- a/codexcrawler.nimble +++ b/codexcrawler.nimble @@ -1,15 +1,16 @@ # Package -version = "0.0.1" -author = "Codex core contributors" -description = "Crawler for Codex networks" -license = "MIT" -skipDirs = @["tests"] -bin = @["codexcrawler"] +version = "0.0.1" +author = "Codex core contributors" +description = "Crawler for Codex networks" +license = "MIT" +skipDirs = @["tests"] +bin = @["codexcrawler"] # Dependencies requires "secp256k1#2acbbdcc0e63002a013fff49f015708522875832" # >= 0.5.2 & < 0.6.0 -requires "protobuf_serialization#5a31137a82c2b6a989c9ed979bb636c7a49f570e" # >= 0.2.0 & < 0.3.0 +requires "protobuf_serialization#5a31137a82c2b6a989c9ed979bb636c7a49f570e" + # >= 0.2.0 & < 0.3.0 requires "nimcrypto >= 0.5.4" requires "bearssl == 0.2.5" requires "chronicles >= 0.10.2 & < 0.11.0" @@ -20,8 +21,13 @@ requires "stew >= 0.2.0" requires "stint#3236fa68394f1e3a06e2bc34218aacdd2d675923" requires "https://github.com/codex-storage/nim-datastore >= 0.1.0 & < 0.2.0" requires "questionable >= 0.10.15 & < 0.11.0" -requires "https://github.com/codex-storage/nim-codex-dht#4bd3a39e0030f8ee269ef217344b6b59ec2be6dc" # 7 Jan 2024 - Support for Nim 2.0.14 +requires "https://github.com/codex-storage/nim-codex-dht#4bd3a39e0030f8ee269ef217344b6b59ec2be6dc" + # 7 Jan 2024 - Support for Nim 2.0.14 requires "docopt >= 0.7.1 & < 1.0.0" +requires "nph >= 0.6.1 & < 1.0.0" + +task format, "Formatting...": + exec "nph ./" task test, "Run tests": exec "nimble install -d -y" diff --git a/codexcrawler/config.nim b/codexcrawler/config.nim index d144290..5506407 100644 --- a/codexcrawler/config.nim +++ b/codexcrawler/config.nim @@ -1,7 +1,8 @@ import std/net import ./version -let doc = """ +let doc = + """ Codex Network Crawler. Generates network metrics. Usage: @@ -18,21 +19,17 @@ Options: import strutils import docopt -type - CrawlerConfig* = ref object - logLevel*: string - metricsAddress*: IpAddress - metricsPort*: Port - dataDir*: string - discPort*: Port +type CrawlerConfig* = ref object + logLevel*: string + metricsAddress*: IpAddress + metricsPort*: Port + dataDir*: string + discPort*: Port proc `$`*(config: CrawlerConfig): string = - "CrawlerConfig:" & - " logLevel=" & config.logLevel & - " metricsAddress=" & $config.metricsAddress & - " metricsPort=" & $config.metricsPort & - " dataDir=" & config.dataDir & - " discPort=" & $config.discPort + "CrawlerConfig:" & " logLevel=" & config.logLevel & " metricsAddress=" & + $config.metricsAddress & " metricsPort=" & $config.metricsPort & " dataDir=" & + config.dataDir & " discPort=" & $config.discPort proc parseConfig*(): CrawlerConfig = let args = docopt(doc, version = crawlerFullVersion) diff --git a/codexcrawler/main.nim b/codexcrawler/main.nim index 89460db..e3e8748 100644 --- a/codexcrawler/main.nim +++ b/codexcrawler/main.nim @@ -11,8 +11,7 @@ proc startApplication*() {.async.} = await sleepAsync(1000) asyncSpawn aaa() - + await sleepAsync(1000) notice "b" - diff --git a/codexcrawler/version.nim b/codexcrawler/version.nim index da2c320..d3d7d2d 100644 --- a/codexcrawler/version.nim +++ b/codexcrawler/version.nim @@ -20,5 +20,5 @@ const nimBanner* = getNimBanner() crawlerFullVersion* = - "CodexNetworkCrawler version: " & crawlerVersion & "\p" & "CodexNetworkCrawler revision: " & crawlerRevision & "\p" & - nimBanner + "CodexNetworkCrawler version: " & crawlerVersion & "\p" & + "CodexNetworkCrawler revision: " & crawlerRevision & "\p" & nimBanner diff --git a/tests/test.nimble b/tests/test.nimble index b47abb1..f7596d1 100644 --- a/tests/test.nimble +++ b/tests/test.nimble @@ -1,13 +1,13 @@ # Package -version = "0.0.1" -author = "Codex core contributors" -description = "Tests for crawler for Codex networks" -license = "MIT" -installFiles = @["build.nims"] +version = "0.0.1" +author = "Codex core contributors" +description = "Tests for crawler for Codex networks" +license = "MIT" +installFiles = @["build.nims"] # Dependencies -requires "asynctest >= 0.5.2 & < 0.6.0" +requires "asynctest >= 0.5.2 & < 0.6.0" requires "unittest2 <= 0.3.0" task test, "Run tests":