Skip to content

Commit

Permalink
Localdeps flag support (#852)
Browse files Browse the repository at this point in the history
  • Loading branch information
genotrance committed Sep 23, 2020
1 parent f4c818a commit 26167cd
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 31 deletions.
6 changes: 4 additions & 2 deletions changelog.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Nimble changelog

## 0.12.0 - TBD
## 0.12.0

This is a major release containing multiple improvements and bug fixes:

Expand All @@ -28,6 +28,8 @@ This is a major release containing multiple improvements and bug fixes:
exists within a project, Nimble will use it to store all package dependencies
instead of `~/.nimble/bin`. This enables isolation of a project and its
dependencies from other projects being developed.
- The `-l | --localdeps` flag can be used to setup a project in local dependency
mode.
- Nimble output can now be suppressed using `--silent`.
- Binaries compiled by Nimble can now be named differently than the source file
with the `namedBin` table instead of `bin`. In addition, binary names that clash
Expand All @@ -36,7 +38,7 @@ This is a major release containing multiple improvements and bug fixes:

----

Full changelog: https://github.com/nim-lang/nimble/compare/v0.11.4...master
Full changelog: https://github.com/nim-lang/nimble/compare/v0.11.4...v0.12.0

## 0.11.4 - 19/05/2020

Expand Down
2 changes: 1 addition & 1 deletion nimble.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.11.4"
version = "0.12.0"
author = "Dominik Picheta"
description = "Nim package manager."
license = "BSD"
Expand Down
10 changes: 9 additions & 1 deletion readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ language](https://nim-lang.org).
Interested in learning **how to create a package**? Skip directly to that section
[here](#creating-packages).

This documentation is for the latest commit of Nimble. Nim releases ship with a
specific version of Nimble and may not contain all the features and fixes described
here. `nimble -v` will display the version of Nimble in use and corresponding
documentation can be found [here](https://github.com/nim-lang/nimble/releases).

The Nimble change log can be found [here](https://github.com/nim-lang/nimble/blob/master/changelog.markdown).

## Contents

- [Requirements](#requirements)
Expand Down Expand Up @@ -911,7 +918,8 @@ work properly and you won't be able to run them.
If the ``nimbledeps`` directory exists next to the package ``.nimble`` file,
Nimble will use that directory as ``$nimbleDir`` and ``$HOME/.nimble`` will be
ignored. This allows for project local dependencies and isolation from other
projects.
projects. The `-l | --localdeps` flag can be used to setup a project in local
dependency mode.

Nimble also allows overriding ``$nimbleDir`` on the command line with the
``--nimbleDir`` flag or the ``NIMBLE_DIR`` environment variable if required.
Expand Down
26 changes: 20 additions & 6 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -933,8 +933,26 @@ proc developFromDir(dir: string, options: Options) =
# Overwrite the version to #head always.
pkgInfo.specialVersion = "#head"

# Dependencies need to be processed before the creation of the pkg dir.
discard processDeps(pkgInfo, options)
if options.developLocaldeps:
var optsCopy: Options
optsCopy.forcePrompts = options.forcePrompts
optsCopy.nimbleDir = dir / nimbledeps
createDir(optsCopy.getPkgsDir())
optsCopy.verbosity = options.verbosity
optsCopy.action = Action(typ: actionDevelop)
optsCopy.config = options.config
optsCopy.nimbleData = %{"reverseDeps": newJObject()}
optsCopy.pkgInfoCache = newTable[string, PackageInfo]()
optsCopy.noColor = options.noColor
optsCopy.disableValidation = options.disableValidation
optsCopy.forceFullClone = options.forceFullClone
optsCopy.startDir = dir
optsCopy.nim = options.nim
cd dir:
discard processDeps(pkgInfo, optsCopy)
else:
# Dependencies need to be processed before the creation of the pkg dir.
discard processDeps(pkgInfo, options)

# Don't link if project local deps mode and "developing" the top level package
if not (options.localdeps and options.isInstallingTopLevel(dir)):
Expand Down Expand Up @@ -1120,10 +1138,6 @@ proc doAction(options: var Options) =

setNimBin(options)
setNimbleDir(options)
if not dirExists(options.getNimbleDir()):
createDir(options.getNimbleDir())
if not dirExists(options.getPkgsDir):
createDir(options.getPkgsDir)

if options.action.typ in {actionTasks, actionRun, actionBuild, actionCompile}:
# Implicitly disable package validation for these commands.
Expand Down
2 changes: 1 addition & 1 deletion src/nimblepkg/common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ when not defined(nimscript):
return (error, hint)

const
nimbleVersion* = "0.11.4"
nimbleVersion* = "0.12.0"

when not declared(initHashSet):
import sets
Expand Down
37 changes: 27 additions & 10 deletions src/nimblepkg/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ from httpclient import Proxy, newProxy

import config, version, common, cli

const
nimbledeps* = "nimbledeps"

type
DumpMode* = enum kdumpIni, kdumpJson
Options* = object
Expand Down Expand Up @@ -36,6 +39,7 @@ type
# some commands, useful when processing deps
nim*: string # Nim compiler location
localdeps*: bool # True if project local deps mode
developLocaldeps*: bool # True if local deps + nimble develop pkg1 ...

ActionType* = enum
actionNil, actionRefresh, actionInit, actionDump, actionPublish,
Expand Down Expand Up @@ -130,6 +134,7 @@ Nimble Options:
-v, --version Print version information.
-y, --accept Accept all interactive prompts.
-n, --reject Reject all interactive prompts.
-l, --localdeps Run in project local dependency mode
--ver Query remote server for package version
information when searching or listing packages
--nimbleDir:dirname Set the Nimble directory.
Expand Down Expand Up @@ -251,10 +256,25 @@ proc promptList*(options: Options, question: string, args: openarray[string]): s
## options is selected.
return promptList(options.forcePrompts, question, args)

proc getNimbleDir*(options: Options): string =
return options.nimbleDir

proc getPkgsDir*(options: Options): string =
options.getNimbleDir() / "pkgs"

proc getBinDir*(options: Options): string =
options.getNimbleDir() / "bin"

proc setNimbleDir*(options: var Options) =
var
nimbleDir = options.config.nimbleDir
propagate = false

if (options.localdeps and options.action.typ == actionDevelop and
options.action.packages.len != 0):
# Localdeps + nimble develop pkg1 ...
options.developLocaldeps = true

if options.nimbleDir.len != 0:
# --nimbleDir:<dir> takes priority...
nimbleDir = options.nimbleDir
Expand All @@ -268,8 +288,7 @@ proc setNimbleDir*(options: var Options) =
nimbleDir = env
else:
# ...followed by project local deps mode
let nimbledeps = "nimbledeps"
if dirExists(nimbledeps):
if dirExists(nimbledeps) or (options.localdeps and not options.developLocaldeps):
display("Warning:", "Using project local deps mode", Warning,
priority = HighPriority)
nimbleDir = nimbledeps
Expand All @@ -286,14 +305,11 @@ proc setNimbleDir*(options: var Options) =
if options.nimbleDir notin path:
putEnv("PATH", options.nimbleDir / "bin" & PathSep & path)

proc getNimbleDir*(options: Options): string =
return options.nimbleDir

proc getPkgsDir*(options: Options): string =
options.getNimbleDir() / "pkgs"

proc getBinDir*(options: Options): string =
options.getNimbleDir() / "bin"
if not options.developLocaldeps:
# Create nimbleDir/pkgs if it doesn't exist - will create nimbleDir as well
let pkgsDir = options.getPkgsDir()
if not dirExists(pkgsDir):
createDir(pkgsDir)

proc parseCommand*(key: string, result: var Options) =
result.action = Action(typ: parseActionType(key))
Expand Down Expand Up @@ -407,6 +423,7 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
of "nocolor": result.noColor = true
of "disablevalidation": result.disableValidation = true
of "nim": result.nim = val
of "localdeps", "l": result.localdeps = true
else: isGlobalFlag = false

var wasFlagHandled = true
Expand Down
36 changes: 26 additions & 10 deletions tests/tester.nim
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ suite "multi":
check output.contains("beta installed successfully")

test "can develop package from git subdir":
removeDir("nimble-test/multi")
removeDir("multi")
let args = ["develop", "https://github.com/nimble-test/multi?subdir=beta"]
check execNimbleYes(args).exitCode == QuitSuccess

Expand Down Expand Up @@ -725,6 +725,31 @@ suite "nimble run":
"""Testing `nimble run`: @["\"", "\'", "\t", "arg with spaces"]"""
)

suite "project local deps mode":
test "nimbledeps exists":
cd "localdeps":
removeDir("nimbledeps")
createDir("nimbledeps")
let (output, exitCode) = execCmdEx(nimblePath & " install -y")
check exitCode == QuitSuccess
check output.contains("project local deps mode")
check output.contains("Succeeded")

test "--localdeps flag":
cd "localdeps":
removeDir("nimbledeps")
let (output, exitCode) = execCmdEx(nimblePath & " install -y -l")
check exitCode == QuitSuccess
check output.contains("project local deps mode")
check output.contains("Succeeded")

test "localdeps develop":
removeDir("packagea")
let (_, exitCode) = execCmdEx(nimblePath & " develop https://github.com/nimble-test/packagea --localdeps -y")
check exitCode == QuitSuccess
check dirExists("packagea" / "nimbledeps")
check not dirExists("nimbledeps")

suite "misc tests":
test "depsOnly + flag order test":
var (output, exitCode) = execNimbleYes(
Expand Down Expand Up @@ -821,15 +846,6 @@ suite "misc tests":

check execNimble("list", "-i").exitCode == QuitSuccess

test "project local deps mode":
cd "localdeps":
removeDir("nimbledeps")
createDir("nimbledeps")
var (output, exitCode) = execCmdEx(nimblePath & " install -y")
check exitCode == QuitSuccess
check output.contains("project local deps mode")
check output.contains("Succeeded")

suite "issues":
test "issue 801":
cd "issue801":
Expand Down

0 comments on commit 26167cd

Please sign in to comment.