Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to install from nimble file #1022

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,13 @@ proc processLockedDependencies(pkgInfo: PackageInfo, options: Options):
else:
raise nimbleError("Unsatisfied dependency: " & pkgInfo.basicInfo.name)

proc getDownloadInfo*(pv: PkgTuple, options: Options,
doPrompt: bool, ignorePackageCache = false): (DownloadMethod, string,
Table[string, string]) =
proc getDownloadInfo*(
pv: PkgTuple,
options: Options,
doPrompt: bool,
ignorePackageCache = false
): (DownloadMethod, string, Table[string, string]) =
## download info
if pv.name.isURL:
let (url, metadata) = getUrlData(pv.name)
return (checkUrlType(url), url, metadata)
Expand Down Expand Up @@ -664,6 +668,11 @@ proc install(packages: seq[PkgTuple], options: Options,
"\nThey will be ignored and installed as normal packages.")
result = installFromDir(currentDir, newVRAny(), options, "", first,
fromLockFile)
elif options.action.isNimbleFile:
let pv = packages[0]
let pkgInfo = getPkgInfoFromFile(pv.name, options, forValidation=true)
result = installFromDir(pkgInfo.myPath.parentDir(), pv.ver, options, "",
first, fromLockFile)
else:
# Install each package.
for pv in packages:
Expand Down
3 changes: 3 additions & 0 deletions src/nimblepkg/download.nim
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ proc getUrlData*(url: string): (string, Table[string, string]) =
proc isURL*(name: string): bool =
name.startsWith(peg" @'://' ")

proc isNimble*(name: string): bool =
name.startsWith(peg" @'://' ")

proc cloneSpecificRevision(downloadMethod: DownloadMethod,
url, downloadDir: string,
vcsRevision: Sha1Hash) =
Expand Down
4 changes: 4 additions & 0 deletions src/nimblepkg/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type
devActions*: seq[DevelopAction]
path*: string
noRebuild*: bool
isNimbleFile*: bool
withDependencies*: bool
## Whether to put in develop mode also the dependencies of the packages
## listed in the develop command.
Expand Down Expand Up @@ -109,6 +110,7 @@ Commands:
[-d, --depsOnly] Install only dependencies.
[-p, --passNim] Forward specified flag to compiler.
[--noRebuild] Don't rebuild binaries if they're up-to-date.
[--nimble-file] Use nimble file instead of pkgname.
develop [pkgname, ...] Clones a list of packages for development.
Adds them to a develop file if specified or
to `nimble.develop` if not specified and
Expand Down Expand Up @@ -528,6 +530,8 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
case f
of "depsonly", "d":
result.depsOnly = true
of "nimble-file":
result.action.isNimbleFile = true
of "norebuild":
result.action.noRebuild = true
of "passnim", "p":
Expand Down
10 changes: 10 additions & 0 deletions tests/tuninstall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ from nimblepkg/common import cd
from nimblepkg/version import newVersion

suite "uninstall":
test "can install deps from nimble file":
let srcDirTest = "develop/srcdirtest/srcdirtest.nimble"
cleanDir(installDir)
check execNimbleYes("install", "--onlyDeps", "--nimble-file", srcDirTest).exitCode == QuitSuccess

test "can install from nimble file":
let srcDirTest = "develop/srcdirtest/srcdirtest.nimble"
cleanDir(installDir)
check execNimbleYes("install", "--nimble-file", srcDirTest).exitCode == QuitSuccess

test "cannot install packagebin2 in --offline mode":
cleanDir(installDir)
let args = ["--offline", "install", pkgBin2Url]
Expand Down