Skip to content

Instantly share code, notes, and snippets.

@pietroppeter
Last active April 7, 2021 16:10
Show Gist options
  • Save pietroppeter/8e21066aa6d2515e5f5514e2c4c2135d to your computer and use it in GitHub Desktop.
Save pietroppeter/8e21066aa6d2515e5f5514e2c4c2135d to your computer and use it in GitHub Desktop.
Nim file to count Nimble packages
# git clone https://github.com/nim-lang/packages.git
# then compile and run this file in the git repo
import os, parsecsv, json, strutils
proc runCommand(command: string) =
let errorCode = os.execShellCmd(command)
if errorCode != 0:
echo "error running command: " & command
quit(1)
else:
echo "succesfully run command: " & command
proc countPackages(): int =
try:
let packages = "packages.json".readFile.parseJson
if packages.kind != JArray: return -1
for package in packages:
if package.kind != JObject: return -1
if "alias" in package:
continue
inc result
except JsonParsingError, IOError:
return -1
const
commitHistoryFilename = "packages_commit_history.csv"
runCommand("git log --date=iso --pretty=\"%H,%cd\" > " & commitHistoryFilename)
var stats = @["commit,timestamp,error,count"]
var p: CsvParser
p.open(commitHistoryFilename)
var i = 0
while p.readRow():
inc i
let
commit = p.row[0]
timestamp = p.row[1]
echo i, timestamp
runCommand("git checkout " & commit)
let
count = countPackages()
if count < 0:
echo "error while processing json at commit: " & commit
stats.add(commit & "," & timestamp & ",1," & $count)
else:
stats.add(commit & "," & timestamp & ",0," & $count)
"package_count.csv".writeFile(stats.join("\n"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment