Skip to content

Commit ad17ab1

Browse files
committed
Remove the parallel package downloads
The parallel package downloads are removed, because the `asynctools` library for asynchronous processes, that is used is not production-ready. It has several hard-to-find bugs causing а crashing of Nimble. First, they must be fixed before using it. Related to #127
1 parent 95ce15b commit ad17ab1

File tree

9 files changed

+99
-1650
lines changed

9 files changed

+99
-1650
lines changed

changelog.markdown

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55

66
## 0.14.0
77

8-
This is a major release containing two big features:
8+
This is a major release containing four new features:
99

1010
- A new dependencies development mode.
1111
- Support for lock files.
1212
- Download tarballs when downloading packages from GitHub.
13-
- Parallel downloads of the locked dependencies.
14-
- Setup command.
13+
- A setup command.
1514

1615
## 0.13.0
1716

src/nimble.nim

Lines changed: 19 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import system except TResult
55

66
import os, tables, strtabs, json, algorithm, sets, uri, sugar, sequtils, osproc,
7-
strformat, asyncdispatch
7+
strformat
88

99
import std/options as std_opt
1010

@@ -485,14 +485,7 @@ type
485485
url: string
486486
version: VersionRange
487487
downloadDir: string
488-
vcsRevision: Sha1HashRef
489-
490-
DownloadQueue = ref seq[tuple[name: string, dep: LockFileDep]]
491-
## A queue of dependencies from the lock file which to be downloaded.
492-
493-
DownloadResults = ref seq[DownloadInfo]
494-
## A list of `DownloadInfo` objects used for installing the downloaded
495-
## dependencies.
488+
vcsRevision: Sha1Hash
496489

497490
proc developWithDependencies(options: Options): bool =
498491
## Determines whether the current executed action is a develop sub-command
@@ -521,8 +514,8 @@ proc raiseCannotCloneInExistingDirException(downloadDir: string) =
521514
raise nimbleError(msg, hint)
522515

523516
proc downloadDependency(name: string, dep: LockFileDep, options: Options):
524-
Future[DownloadInfo] {.async.} =
525-
## Asynchronously downloads a dependency from the lock file.
517+
DownloadInfo =
518+
## Downloads a dependency from the lock file.
526519

527520
if not options.developWithDependencies:
528521
let depDirName = getDependencyDir(name, dep, options)
@@ -546,12 +539,12 @@ proc downloadDependency(name: string, dep: LockFileDep, options: Options):
546539
url: url,
547540
version: version,
548541
downloadDir: downloadPath,
549-
vcsRevision: dep.vcsRevision.newClone)
542+
vcsRevision: dep.vcsRevision)
550543
return
551544
else:
552545
raiseCannotCloneInExistingDirException(downloadPath)
553546

554-
let (downloadDir, _, vcsRevision) = await downloadPkg(
547+
let (downloadDir, _, vcsRevision) = downloadPkg(
555548
url, version, dep.downloadMethod, subdir, options, downloadPath,
556549
dep.vcsRevision)
557550

@@ -578,7 +571,7 @@ proc installDependency(pkgInfo: PackageInfo, downloadInfo: DownloadInfo,
578571
downloadInfo.url,
579572
first = false,
580573
fromLockFile = true,
581-
downloadInfo.vcsRevision[])
574+
downloadInfo.vcsRevision)
582575

583576
downloadInfo.downloadDir.removeDir
584577

@@ -590,31 +583,6 @@ proc installDependency(pkgInfo: PackageInfo, downloadInfo: DownloadInfo,
590583

591584
return newlyInstalledPkgInfo
592585

593-
proc startDownloadWorker(queue: DownloadQueue, options: Options,
594-
downloadResults: DownloadResults) {.async.} =
595-
## Starts a new download worker.
596-
while queue[].len > 0:
597-
let download = queue[].pop
598-
let index = queue[].len
599-
downloadResults[index] = await downloadDependency(
600-
download.name, download.dep, options)
601-
602-
proc lockedDepsDownload(dependenciesToDownload: DownloadQueue,
603-
options: Options): DownloadResults =
604-
## By given queue with dependencies to download performs the downloads and
605-
## returns the result objects.
606-
607-
result.new
608-
result[].setLen(dependenciesToDownload[].len)
609-
610-
var downloadWorkers: seq[Future[void]]
611-
let workersCount = min(
612-
options.maxParallelDownloads, dependenciesToDownload[].len)
613-
for i in 0 ..< workersCount:
614-
downloadWorkers.add startDownloadWorker(
615-
dependenciesToDownload, options, result)
616-
waitFor all(downloadWorkers)
617-
618586
proc processLockedDependencies(pkgInfo: PackageInfo, options: Options):
619587
HashSet[PackageInfo] =
620588
# Returns a hash set with `PackageInfo` of all packages from the lock file of
@@ -625,20 +593,14 @@ proc processLockedDependencies(pkgInfo: PackageInfo, options: Options):
625593

626594
let developModeDeps = getDevelopDependencies(pkgInfo, options)
627595

628-
var dependenciesToDownload: DownloadQueue
629-
dependenciesToDownload.new
630-
631596
for name, dep in pkgInfo.lockedDeps:
632597
if developModeDeps.hasKey(name):
633598
result.incl developModeDeps[name][]
634599
elif isInstalled(name, dep, options):
635600
result.incl getDependency(name, dep, options)
636601
else:
637-
dependenciesToDownload[].add (name, dep)
638-
639-
let downloadResults = lockedDepsDownload(dependenciesToDownload, options)
640-
for downloadResult in downloadResults[]:
641-
result.incl installDependency(pkgInfo, downloadResult, options)
602+
let downloadResult = downloadDependency(name, dep, options)
603+
result.incl installDependency(pkgInfo, downloadResult, options)
642604

643605
proc getDownloadInfo*(pv: PkgTuple, options: Options,
644606
doPrompt: bool): (DownloadMethod, string,
@@ -687,11 +649,11 @@ proc install(packages: seq[PkgTuple], options: Options,
687649
let (meth, url, metadata) = getDownloadInfo(pv, options, doPrompt)
688650
let subdir = metadata.getOrDefault("subdir")
689651
let (downloadDir, downloadVersion, vcsRevision) =
690-
waitFor downloadPkg(url, pv.ver, meth, subdir, options,
691-
downloadPath = "", vcsRevision = notSetSha1Hash)
652+
downloadPkg(url, pv.ver, meth, subdir, options,
653+
downloadPath = "", vcsRevision = notSetSha1Hash)
692654
try:
693655
result = installFromDir(downloadDir, pv.ver, options, url,
694-
first, fromLockFile, vcsRevision[])
656+
first, fromLockFile, vcsRevision)
695657
except BuildFailed as error:
696658
# The package failed to build.
697659
# Check if we tried building a tagged version of the package.
@@ -1243,8 +1205,8 @@ proc installDevelopPackage(pkgTup: PkgTuple, options: var Options):
12431205
else:
12441206
pkgTup.ver
12451207

1246-
discard waitFor downloadPkg(url, ver, meth, subdir, options, downloadDir,
1247-
vcsRevision = notSetSha1Hash)
1208+
discard downloadPkg(url, ver, meth, subdir, options, downloadDir,
1209+
vcsRevision = notSetSha1Hash)
12481210

12491211
let pkgDir = downloadDir / subdir
12501212
var pkgInfo = getPkgInfo(pkgDir, options)
@@ -1258,18 +1220,12 @@ proc developLockedDependencies(pkgInfo: PackageInfo,
12581220
alreadyDownloaded: var HashSet[string], options: var Options) =
12591221
## Downloads for develop the dependencies from the lock file.
12601222

1261-
var dependenciesToDownload: DownloadQueue
1262-
dependenciesToDownload.new
1263-
12641223
for name, dep in pkgInfo.lockedDeps:
12651224
if dep.url.removeTrailingGitString notin alreadyDownloaded:
1266-
dependenciesToDownload[].add (name, dep)
1267-
1268-
let downloadResults = lockedDepsDownload(dependenciesToDownload, options)
1269-
for downloadResult in downloadResults[]:
1270-
alreadyDownloaded.incl downloadResult.url.removeTrailingGitString
1271-
options.action.devActions.add(
1272-
(datAdd, downloadResult.downloadDir.normalizedPath))
1225+
let downloadResult = downloadDependency(name, dep, options)
1226+
alreadyDownloaded.incl downloadResult.url.removeTrailingGitString
1227+
options.action.devActions.add(
1228+
(datAdd, downloadResult.downloadDir.normalizedPath))
12731229

12741230
proc check(alreadyDownloaded: HashSet[string], dep: PkgTuple,
12751231
options: Options): bool =
@@ -1965,6 +1921,7 @@ when isMainModule:
19651921
except CatchableError as error:
19661922
exitCode = QuitFailure
19671923
displayTip()
1924+
echo error.getStackTrace()
19681925
displayError(error)
19691926
finally:
19701927
try:

0 commit comments

Comments
 (0)