Skip to content

Commit d564b2f

Browse files
authored
Expand forge aliases when requirement is parsed (#1385)
* Add test case * Expand forge aliases when they are parsed (That way the name is always either a URL or a package) Means we aren't having to expand it all over the place * Forge install test wasn't actually getting ran * Remove other usages of forge expansion Not needed anymore * Forge parser was also missing * Revert to old check if a package is valid * Don't expand when downloading Make the test look like other tests * Fix up the test Since it doesn't exist locally I can't use the vcs check function. I don't need it all anyways so easier to copy a minimal version once than to add another random flag parameter * Remove `os` import causing test failure * Fix Forge install test not working on windows Issue was it was checking the binary exists without adding the binary extension
1 parent d4aa18b commit d564b2f

File tree

7 files changed

+43
-41
lines changed

7 files changed

+43
-41
lines changed

src/nimble.nim

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import nimblepkg/packageinfotypes, nimblepkg/packageinfo, nimblepkg/version,
1818
nimblepkg/nimscriptwrapper, nimblepkg/developfile, nimblepkg/paths,
1919
nimblepkg/nimbledatafile, nimblepkg/packagemetadatafile,
2020
nimblepkg/displaymessages, nimblepkg/sha1hashes, nimblepkg/syncfile,
21-
nimblepkg/deps, nimblepkg/nimblesat, nimblepkg/forge_aliases, nimblepkg/nimenv,
21+
nimblepkg/deps, nimblepkg/nimblesat, nimblepkg/nimenv,
2222
nimblepkg/downloadnim, nimblepkg/declarativeparser
2323

2424
const
@@ -877,13 +877,7 @@ proc install(packages: seq[PkgTuple], options: Options,
877877
else:
878878
# Install each package.
879879
for pv in packages:
880-
let isAlias = isForgeAlias(pv.name)
881-
882-
let (meth, url, metadata) =
883-
if not isAlias:
884-
getDownloadInfo(pv, options, doPrompt) #TODO dont download if its nim
885-
else:
886-
(git, newForge(pv.name).expand(), initTable[string, string]())
880+
let (meth, url, metadata) = getDownloadInfo(pv, options, doPrompt) #TODO dont download if its nim
887881

888882
let subdir = metadata.getOrDefault("subdir")
889883
var downloadPath = ""
@@ -896,15 +890,9 @@ proc install(packages: seq[PkgTuple], options: Options,
896890
let (downloadDir, downloadVersion, vcsRevision) =
897891
if nimInstalled.isSome():
898892
(nimInstalled.get().dir, nimInstalled.get().ver, notSetSha1Hash)
899-
elif not isAlias:
893+
else:
900894
downloadPkg(url, pv.ver, meth, subdir, options,
901895
downloadPath = downloadPath, vcsRevision = notSetSha1Hash)
902-
else:
903-
downloadPkg(
904-
newForge(pv.name).expand(),
905-
pv.ver, meth, subdir, options,
906-
downloadPath = downloadPath, vcsRevision = notSetSha1Hash
907-
)
908896
try:
909897
var opt = options
910898
if pv.name.isNim:
@@ -970,26 +958,22 @@ proc addPackages(packages: seq[PkgTuple], options: var Options) =
970958
exists = false
971959
version: string
972960

973-
let
974-
isValidUrl = isURL(apkg.name)
975-
isValidAlias = isForgeAlias(apkg.name)
961+
let isValidUrl = isURL(apkg.name)
976962

977-
if not isValidAlias:
978-
for pkg in pkgList:
979-
if pkg.name == apkg.name:
980-
exists = true
981-
version = case apkg.ver.kind
982-
of verAny:
983-
""
984-
else:
985-
$apkg.ver
986-
break
963+
for pkg in pkgList:
964+
if pkg.name == apkg.name:
965+
exists = true
966+
version = case apkg.ver.kind
967+
of verAny:
968+
""
969+
else:
970+
$apkg.ver
971+
break
987972

988-
if not exists and
989-
not isValidUrl:
990-
raise nimbleError(
991-
"No such package \"$1\" was found in the package list." % [apkg.name]
992-
)
973+
if not exists and not isValidUrl:
974+
raise nimbleError(
975+
"No such package \"$1\" was found in the package list." % [apkg.name]
976+
)
993977

994978
var doAppend = true
995979
for dep in deps:

src/nimblepkg/download.nim

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# BSD License. Look at license.txt for more info.
33

44
import parseutils, os, osproc, strutils, tables, uri, strformat,
5-
httpclient, json, sequtils, forge_aliases, urls
5+
httpclient, json, sequtils, urls
66

77
from algorithm import SortOrder, sorted
88

@@ -620,9 +620,6 @@ proc getDownloadInfo*(
620620
result = (checkUrlType(url), url, metadata)
621621
# echo "getDownloadInfo:isURL: ", $result
622622
return
623-
elif pv.name.isForgeAlias:
624-
let url = newForge(pv.name).expand()
625-
return (checkUrlType(url), url, default(Table[string, string]))
626623
else:
627624
# If package is not found give the user a chance to refresh
628625
# package.json

src/nimblepkg/version.nim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
## Module for handling versions and version ranges such as ``>= 1.0 & <= 1.5``
55
import json, sets
6-
import common, strutils, tables, hashes, parseutils
6+
import common, strutils, tables, hashes, parseutils, forge_aliases
77
import std/[strscans]
88
type
99
Version* = object
@@ -304,6 +304,10 @@ proc parseRequires*(req: string): PkgTuple =
304304
raise nimbleError(
305305
"Unable to parse dependency version range: " & getCurrentExceptionMsg())
306306

307+
# Expand forge aliases here
308+
if result.name.isForgeAlias:
309+
result.name = newForge(result.name).expand()
310+
307311
proc `$`*(verRange: VersionRange): string =
308312
case verRange.kind
309313
of verLater:
@@ -473,4 +477,4 @@ when isMainModule:
473477
check toVersionRange(newVersion("#head")).kind == verSpecial
474478
check toVersionRange(newVersion("0.2.0")).kind == verEq
475479

476-
proc hash*(pv: PkgTuple): Hash = hash($pv)
480+
proc hash*(pv: PkgTuple): Hash = hash($pv)

tests/tester.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import tsat
3232
import tniminstall
3333
import trequireflag
3434
import tdeclarativeparser
35+
import tforgeinstall
36+
import tforgeparser
3537
# nonim tests are very slow and (often) break the CI.
3638

3739
# import tnonim

tests/tforgeinstall.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ test "can install packages via a forge alias":
99
cd "forgealias001":
1010
let (_, exitCode) = execNimbleYes(["build"])
1111
check exitCode == QuitSuccess
12-
check fileExists("forgealias001")
12+
check fileExists("forgealias001".addFileExt(ExeExt))

tests/tforgeparser.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# BSD License. Look at license.txt for more info.
33

44
{.used.}
5-
import std/[unittest, os]
5+
import std/unittest
66
import nimblepkg/forge_aliases
77

88
let

tests/tlockfile.nim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,3 +694,18 @@ requires "nim >= 1.5.1"
694694

695695
let exitCode = execNimbleYes("lock", "--developFile=" & "other-name.develop").exitCode
696696
check exitCode == QuitSuccess
697+
test "Forge alias is generated inside lockfile":
698+
cleanup()
699+
700+
withPkgListFile:
701+
cd "forgealias001":
702+
removeFile defaultLockFileName
703+
704+
let (_, exitCode) = execNimbleYes("lock")
705+
check exitCode == QuitSuccess
706+
707+
# Check the dependency appears in the lock file, and its expanded
708+
check defaultLockFileName.fileExists
709+
let json = defaultLockFileName.readFile.parseJson
710+
check json{$lfjkPackages, "librng", "url"}.str == "https://github.com/xTrayambak/librng"
711+

0 commit comments

Comments
 (0)