@@ -252,6 +252,7 @@ Nimble Options:
252252 -y, --accept Accept all interactive prompts.
253253 -n, --reject Reject all interactive prompts.
254254 -l, --localdeps Run in project local dependency mode.
255+ -g, --global Run in global dependency mode.
255256 -p, --package For which package in the dependency tree the
256257 command should be executed. If not provided by
257258 default it applies to the current directory
@@ -440,11 +441,49 @@ proc setPackageCache(options: var Options, baseDir: string) =
440441 if options.verbosity >= LowPriority :
441442 display (" Info:" , " Package cache path " & options.pkgCachePath, priority = LowPriority )
442443
444+ proc isSubdirOf * (subdir, baseDir: string ): bool =
445+ let
446+ normalizedSubdir = subdir.normalizedPath
447+ normalizedBaseDir = baseDir.normalizedPath & DirSep
448+
449+ when defined (windows):
450+ normalizedSubdir.toLower.startsWith (normalizedBaseDir.toLower)
451+ else :
452+ normalizedSubdir.startsWith (normalizedBaseDir)
453+
454+ proc findNimbleFile * (dir: string ; error: bool , options: Options , warn = true ): string =
455+ var hits = 0
456+ for kind, path in walkDir (dir):
457+ if kind in {pcFile, pcLinkToFile}:
458+ let ext = path.splitFile.ext
459+ case ext
460+ of " .babel" , " .nimble" :
461+ result = path
462+ inc hits
463+ else : discard
464+ if hits >= 2 :
465+ raise nimbleError (
466+ " Only one .nimble file should be present in " & dir)
467+ elif hits == 0 :
468+ if error:
469+ raise nimbleError (
470+ " Could not find a file with a .nimble extension inside the specified " &
471+ " directory: $1" % dir)
472+ else :
473+ if not dir.isSubdirOf (options.nimBinariesDir) and warn:
474+ displayWarning (& " No .nimble file found for { dir} " )
475+
443476proc setNimbleDir * (options: var Options ) =
444477 var
445478 nimbleDir = options.config.nimbleDir
446479 propagate = false
447480
481+ # if there is no .nimble file in the current directory, we default to global deps mode
482+ let thereIsNimbleFile = findNimbleFile (getCurrentDir (), error = false , options, warn = false ) != " "
483+ if not thereIsNimbleFile and options.action.typ != actionDevelop:
484+ options.localdeps = false
485+
486+
448487 if options.action.typ == actionDevelop:
449488 options.forceFullClone = true
450489
@@ -468,10 +507,7 @@ proc setNimbleDir*(options: var Options) =
468507 setPackageCache (options, nimbleDir)
469508 else :
470509 # ...followed by project local deps mode
471- if dirExists (nimbledeps) or (options.localdeps and not options.developLocaldeps):
472- if not options.showVersion:
473- display (" Warning:" , " Using project local deps mode" , Warning ,
474- priority = HighPriority )
510+ if dirExists (nimbledeps) or (options.localdeps and not options.developLocaldeps):
475511 nimbleDir = nimbledeps
476512 options.localdeps = true
477513 propagate = true
@@ -633,6 +669,7 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
633669 of " disablevalidation" : result .disableValidation = true
634670 of " nim" : result .nimBin = some makeNimBin (result , val)
635671 of " localdeps" , " l" : result .localdeps = true
672+ of " global" , " g" : result .localdeps = false
636673 of " nosslcheck" : result .disableSslCertCheck = true
637674 of " nolockfile" : result .disableLockFile = true
638675 of " tarballs" , " t" : result .enableTarballs = true
@@ -805,7 +842,8 @@ proc initOptions*(): Options =
805842 useSatSolver: true ,
806843 useDeclarativeParser: false ,
807844 legacy: false , # default to legacy code path for nimble < 1.0.0
808- satResult: SatResult ()
845+ satResult: SatResult (),
846+ localDeps: true
809847 )
810848
811849proc handleUnknownFlags (options: var Options ) =
@@ -964,16 +1002,6 @@ proc lockFile*(options: Options, dir: string): string =
9641002proc lockFileExists * (options: Options , dir: string ): bool =
9651003 return options.lockFile (dir).fileExists
9661004
967- proc isSubdirOf * (subdir, baseDir: string ): bool =
968- let
969- normalizedSubdir = subdir.normalizedPath
970- normalizedBaseDir = baseDir.normalizedPath & DirSep
971-
972- when defined (windows):
973- normalizedSubdir.toLower.startsWith (normalizedBaseDir.toLower)
974- else :
975- normalizedSubdir.startsWith (normalizedBaseDir)
976-
9771005proc isDevelopment * (pkg: PackageInfo , options: Options ): bool =
9781006 # ## Returns true if the package is a development package.
9791007 # ## A development package is a root package that is not installed.
0 commit comments