But there is the Options type everywhere that everything needs, and I don’t know how I would make one of these for nimble without the cmd line. A small example would be very helpful!
It would be great if anyone could help!
I was born for this moment! I literally ran into your issue roughly a week ago when I wanted to use nimble search as well as parse a nimble file using the nimble package.
It would of course be nicer if nimble could provide public procs that didn't require you to pass in options but instead whatever from options is actually needed.
I've started adopting the approach to write myself a "generateDummyOptions" proc per nimble command I want to use.
Here what I use to parse a nimble file:
import std/[strutils, sequtils, osproc, sugar, strformat]
import std/options as opt
import nimblepkg/[options, packageparser, packageinfotypes, version]
proc generateDummyOptions(): Options =
result = initOptions()
result.setNimBin()
result.setNimbleDir()
proc parseNimbleFile*(nimblePath: string): PackageInfo =
let options = generateDummyOptions()
result = getPkgInfoFromFile(nimblePath.NimbleFile, options)
echo parseNimbleFile("/home/philipp/dev/playground/playground.nimble").repr
I haven't done calls to nimble's CLI-api that refresh the package-list/install packages, that might however work by instantiating options as needed.
Thanks a lot! I have figured out this:
import nimblepkg/[options, packageinfo, download]
import std/tables
from nimble import removePackage, installFromDir, getDownloadInfo
proc generateDummyOptions(): Options =
result = initOptions()
result.setNimBin()
result.setNimbleDir()
proc refresh*() =
let options = generateDummyOptions()
for name, list in options.config.packageLists:
fetchList(list, options)
proc basicInstall*(name: string): PackageDependenciesInfo =
let options = generateDummyOptions()
let (meth, url, metadata) = getDownloadInfo(name, options, true)
let subdir = metadata.getOrDefault("subdir")
let (downloadDir, downloadVersion, vcsRevision) =
downloadPkg(url, pv.ver, meth, subdir, options,
downloadPath = "", vcsRevision = notSetSha1Hash)
result = installFromDir(downloadDir, pv.ver, options, url,
first, fromLockFile, vcsRevision)
But I am having trouble as nimble functions are private. Is there any way to get private procs from a module?