Skip to content
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
50 changes: 29 additions & 21 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1130,27 +1130,35 @@ proc listPaths(options: Options) =
if options.action.packages.len == 0:
raise nimbleError("A package name needs to be specified")

var errors = 0
let pkgs = getInstalledPkgsMin(options.getPkgsDir(), options)
for name, version in options.action.packages.items:
var installed: seq[VersionAndPath] = @[]
# There may be several, list all available ones and sort by version.
for pkg in pkgs:
if name == pkg.basicInfo.name and withinRange(pkg.basicInfo.version, version):
installed.add((pkg.basicInfo.version, pkg.getRealDir))

if installed.len > 0:
sort(installed, cmp[VersionAndPath], Descending)
# The output for this command is used by tools so we do not use display().
for pkg in installed:
echo pkg.path
else:
display("Warning:", "Package '$1' is not installed" % name, Warning,
MediumPriority)
errors += 1
if errors > 0:
raise nimbleError(
"At least one of the specified packages was not found")
let pkgInfo = maybeGetPkgInfo(getCurrentDir(), options)
if pkgInfo.isSome:
let searchNames = options.action.packages.mapIt(it.name).toHashSet
for dep in pkgInfo.get.processAllDependencies(options):
if dep.basicInfo.name in searchNames:
for path in dep.expandPaths(options):
echo path
else:
var errors = 0
let pkgs = getInstalledPkgsMin(options.getPkgsDir(), options)
for name, version in options.action.packages.items:
var installed: seq[VersionAndPath] = @[]
# There may be several, list all available ones and sort by version.
for pkg in pkgs:
if name == pkg.basicInfo.name and withinRange(pkg.basicInfo.version, version):
installed.add((pkg.basicInfo.version, pkg.getRealDir))

if installed.len > 0:
sort(installed, cmp[VersionAndPath], Descending)
# The output for this command is used by tools so we do not use display().
for pkg in installed:
echo pkg.path
else:
display("Warning:", "Package '$1' is not installed" % name, Warning,
MediumPriority)
errors += 1
if errors > 0:
raise nimbleError(
"At least one of the specified packages was not found")

proc join(x: seq[PkgTuple]; y: string): string =
if x.len == 0: return ""
Expand Down
8 changes: 7 additions & 1 deletion src/nimblepkg/packageparser.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (C) Dominik Picheta. All rights reserved.
# BSD License. Look at license.txt for more info.
import parsecfg, sets, streams, strutils, os, tables, sugar, strformat
import std/[parsecfg, sets, streams, strutils, os, tables, sugar, strformat, options]
from sequtils import apply, map, toSeq

import common, version, tools, nimscriptwrapper, options, cli, sha1hashes,
Expand Down Expand Up @@ -389,6 +389,12 @@ proc getPkgInfo*(dir: string, options: Options, forValidation = false):
let nimbleFile = findNimbleFile(dir, true, options)
result = getPkgInfoFromFile(nimbleFile, options, forValidation)

proc maybeGetPkgInfo*(dir: string, options: Options): Option[PackageInfo] =
try:
return some(getPkgInfo(dir, options))
except NimbleError:
return none(PackageInfo)

proc getInstalledPkgs*(libsDir: string, options: Options): seq[PackageInfo] =
## Gets a list of installed packages.
##
Expand Down
7 changes: 7 additions & 0 deletions tests/pathWithDevelop/nimble.develop
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"version": 1,
"includes": [],
"dependencies": [
"../deps"
]
}
6 changes: 6 additions & 0 deletions tests/pathWithDevelop/pathWithDevelop.nimble
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version = "0.1.0"
author = "Ivan Yonchovski"
description = "Nim package manager."
license = "BSD"

requires "deps"
14 changes: 14 additions & 0 deletions tests/tpathcommand.nim
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,17 @@ suite "path command":
check exitCode == QuitSuccess
check execNimble("path", "[email protected]").exitCode == QuitSuccess
check execNimble("path", "[email protected]").exitCode != QuitSuccess

test "Use current nimble package to determine path when possible":
cd "deps":
check execNimbleYes("install").exitCode == QuitSuccess
let (output, exitCode) = execNimble("path", "timezones")
check(exitCode == QuitSuccess)
check output.strip() == getPackageDir(pkgsDir, "timezones-0.5.4")

test "Respect develop overrides for nimble packages":
cd "pathWithDevelop":
let (output, exitCode) = execNimble("path", "deps")
check(exitCode == QuitSuccess)
checkpoint "Nimble path output was: " & output
check output.startsWith(expandFilename("../deps"))
Loading