Skip to content

Commit

Permalink
0.0.14: support $nimbleDir on nim-1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
disruptek committed Nov 28, 2019
1 parent c8bcfc7 commit 997a931
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 18 deletions.
2 changes: 1 addition & 1 deletion nimph.nimble
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "0.0.13"
version = "0.0.14"
author = "disruptek"
description = "nim package handler from the future"
license = "MIT"
Expand Down
52 changes: 37 additions & 15 deletions src/nimph/config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ iterator packagePaths*(config: ConfigRef; exists = true): string =
continue
yield path

proc suggestNimbleDir*(config: ConfigRef; repo: string;
local = ""; global = ""): string =
proc suggestNimbleDir*(config: ConfigRef; local = ""; global = ""): string =
## come up with a useful nimbleDir based upon what we find in the
## current configuration, the location of the project, and the provided
## suggestions for local or global package directories
Expand All @@ -295,13 +294,13 @@ proc suggestNimbleDir*(config: ConfigRef; repo: string;
if local != "":
assert local.endsWith(DirSep)
{.warning: "look for a nimble packages file here?".}
for search in config.likelySearch(repo, libsToo = false):
for search in config.likelySearch(libsToo = false):
if search.startsWith(local):
result = local
break either

# otherwise, try to pick a global .nimble directory based upon lazy paths
for search in config.likelyLazy(repo):
for search in config.likelyLazy:
{.warning: "maybe we should look for some nimble debris?".}
if search.endsWith(PkgDir & DirSep):
result = search.parentDir # ie. the parent of pkgs
Expand All @@ -311,18 +310,41 @@ proc suggestNimbleDir*(config: ConfigRef; repo: string;

# otherwise, try to make one up using the suggestion
if global == "":
raise newException(IOError, "unable to guess global {dotNimble} directory")
raise newException(IOError, "can't guess global {dotNimble} directory")
assert global.endsWith(DirSep)
result = global
break either

iterator pathSubsFor(config: ConfigRef; sub: string; conf: string): string =
## a convenience to work around the compiler's broken pathSubs
if sub.toLowerAscii in ["nimbledir", "nimblepath"]:
when NimMajor <= 1 and NimMinor < 1:
# we have to pick the first lazy path because that's what Nimble does
block found:
for search in config.likelyLazy:
if search.endsWith(PkgDir & DirSep):
yield search.parentDir / ""
else:
yield search
break found
raise newException(ValueError, "unable to compute $" & sub)
else:
for path in config.nimbleSubs(&"${sub}"):
yield path / ""
else:
yield config.pathSubs(&"${sub}", conf) / ""

iterator pathSubstitutions(config: ConfigRef; path: string;
conf: string; write: bool): string =
## compute the possible path substitions, including the original path
const
readSubs = @["nimcache", "config", "nimbledir", "nimblepath",
"projectdir", "projectpath", "lib", "nim", "home"]
writeSubs = @["nimcache", "config", "projectdir", "lib", "nim", "home"]
writeSubs =
when writeNimbleDirPaths:
readSubs
else:
@["nimcache", "config", "projectdir", "lib", "nim", "home"]
var
matchedPath = false
when defined(debug):
Expand All @@ -334,15 +356,15 @@ iterator pathSubstitutions(config: ConfigRef; path: string;
substitutions = if write: writeSubs else: readSubs

for sub in substitutions.items:
let attempt = config.pathSubs(&"${sub}", conf) / ""
# ignore any empty substitutions
if attempt == "/":
continue
# note if any substitution matches the path
if path == attempt:
matchedPath = true
if path.startsWith(attempt):
yield path.replace(attempt, &"${sub}" / "")
for attempt in config.pathSubsFor(sub, conf):
# ignore any empty substitutions
if attempt == "/":
continue
# note if any substitution matches the path
if path == attempt:
matchedPath = true
if path.startsWith(attempt):
yield path.replace(attempt, &"${sub}" / "")
# if a substitution matches the path, don't yield it at the end
if not matchedPath:
yield path
Expand Down
3 changes: 1 addition & 2 deletions src/nimph/project.nim
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ proc nimbleDir*(project: Project): string =
# otherwise, if we have configuration data, we should use it to determine
# what the user might be using as a package directory -- local or elsewise
elif project.cfg != nil:
result = project.cfg.suggestNimbleDir(project.repo,
local = project.localDeps,
result = project.cfg.suggestNimbleDir(local = project.localDeps,
global = globaldeps)

# otherwise, we'll just presume some configuration-free defaults
Expand Down
1 change: 1 addition & 0 deletions src/nimph/spec.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const
emptyRelease* {.strdefine.} = "#head"
defaultRemote* {.strdefine.} = "origin"
excludeMissingPaths* {.booldefine.} = false
writeNimbleDirPaths* {.booldefine.} = false
hubTime* = initTimeFormat "yyyy-MM-dd\'T\'HH:mm:ss\'Z\'"
shortDate* = initTimeFormat "yyyy-MM-dd"

Expand Down

0 comments on commit 997a931

Please sign in to comment.