Skip to content

Commit

Permalink
Enhance develop --with-dependencies
Browse files Browse the repository at this point in the history
Make `develop --with-dependencies` to skip already existing directories
when cloning the repositories. This is useful when a second
`develop --with-dependencies` is executed for another package and some
of the dependencies are the same as in the first run. In that case, we
don't want the entire command to fail because some package directories
already exist.

Related to nim-lang#127
  • Loading branch information
bobeff authored and CyberTailor committed Dec 12, 2021
1 parent dab1989 commit 7c74e4a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,19 @@ proc downloadDependency(name: string, dep: LockFileDep, options: Options):
getDevelopDownloadDir(url, subdir, options) else: ""

if dirExists(downloadPath):
raiseCannotCloneInExistingDirException(downloadPath)
if options.developWithDependencies:
displayWarning(skipDownloadingInAlreadyExistingDirectoryMsg(
downloadPath, name))
result = DownloadInfo(
name: name,
dependency: dep,
url: url,
version: version,
downloadDir: downloadPath,
vcsRevision: dep.vcsRevision.newClone)
return
else:
raiseCannotCloneInExistingDirException(downloadPath)

let (downloadDir, _, vcsRevision) = await downloadPkg(
url, version, dep.downloadMethod, subdir, options, downloadPath,
Expand Down Expand Up @@ -1213,7 +1225,16 @@ proc installDevelopPackage(pkgTup: PkgTuple, options: var Options):
let downloadDir = getDevelopDownloadDir(url, subdir, options)

if dirExists(downloadDir):
raiseCannotCloneInExistingDirException(downloadDir)
if options.developWithDependencies:
displayWarning(skipDownloadingInAlreadyExistingDirectoryMsg(
downloadDir, pkgTup.name))
let pkgInfo = getPkgInfo(downloadDir, options)
developFromDir(pkgInfo, options)
options.action.devActions.add(
(datAdd, pkgInfo.getNimbleFileDir.normalizedPath))
return pkgInfo
else:
raiseCannotCloneInExistingDirException(downloadDir)

# Download the HEAD and make sure the full history is downloaded.
let ver =
Expand Down
4 changes: 4 additions & 0 deletions src/nimblepkg/displaymessages.nim
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,7 @@ proc pkgAlreadyExistsInTheCacheMsg*(pkgInfo: PackageInfo): string =
pkgInfo.basicInfo.name,
$pkgInfo.basicInfo.version,
$pkgInfo.basicInfo.checksum)

proc skipDownloadingInAlreadyExistingDirectoryMsg*(dir, name: string): string =
&"The download directory \"{dir}\" already exists.\n" &
&"Skipping the download of \"{name}\"."

0 comments on commit 7c74e4a

Please sign in to comment.