diff --git a/src/nimble.nim b/src/nimble.nim index be143affe..48cb70ced 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -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 "" diff --git a/src/nimblepkg/packageparser.nim b/src/nimblepkg/packageparser.nim index 96e0731f7..0ac6172c2 100644 --- a/src/nimblepkg/packageparser.nim +++ b/src/nimblepkg/packageparser.nim @@ -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, @@ -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. ## diff --git a/tests/pathWithDevelop/nimble.develop b/tests/pathWithDevelop/nimble.develop new file mode 100644 index 000000000..6fb33142e --- /dev/null +++ b/tests/pathWithDevelop/nimble.develop @@ -0,0 +1,7 @@ +{ + "version": 1, + "includes": [], + "dependencies": [ + "../deps" + ] +} \ No newline at end of file diff --git a/tests/pathWithDevelop/pathWithDevelop.nimble b/tests/pathWithDevelop/pathWithDevelop.nimble new file mode 100644 index 000000000..05490c3c0 --- /dev/null +++ b/tests/pathWithDevelop/pathWithDevelop.nimble @@ -0,0 +1,6 @@ +version = "0.1.0" +author = "Ivan Yonchovski" +description = "Nim package manager." +license = "BSD" + +requires "deps" diff --git a/tests/tpathcommand.nim b/tests/tpathcommand.nim index 02c2bf4df..f7dec707f 100644 --- a/tests/tpathcommand.nim +++ b/tests/tpathcommand.nim @@ -22,3 +22,17 @@ suite "path command": check exitCode == QuitSuccess check execNimble("path", "srcdirtest@1.0").exitCode == QuitSuccess check execNimble("path", "srcdirtest@2.0").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"))