Open timotheecour opened 3 years ago
This is a bit similar to my import $var / file
ideas (which didn't make it into Nim) but has the downside that it's command-line only. I would like to see {.path ...}
as pragmas, maybe with the restriction that only the main Nim file can use it. In general I want to get away both from Nim's config system and also from command-line only features.
has the downside that it's command-line only
I also want {.path.}
, it simplifies some patterns. Note that {.path: "compiler:/pathto/compiler".}
can be supported in addition to --path:prefix:path
(and would call same logic) with the semantics that for a relative path, it resolves as usual to currentSourcePath. But that can be done later.
Note that nimble shells out to nim so {.path.}
wouldn't be sufficient.
This is a bit similar to my import $var / file ideas
it subsumes it, if you allow a special token @
(or $
) in import paths:
--path:@var:pathto/var
import @var # for a package
import @var/sub # for a module
and could simplify/generalize existing hard-coded logic for interpolated paths eg import "$lib/../tools/nimweb"
But the main point of the RFC is it works without modification to existing source files, eg import compiler/foo
can be re-targetted via --path:compiler:path
maybe with the restriction that only the main Nim file can use
I don't think that's needed, this would restrict legitimate use case.
--path:cligen@1:pathto/cligen-1.0 --path:cligen@1.2:pathto/cligen-1.2
import cligen@1/foo
import cligen@1.2/foo
listFullPaths:off
, instead of current algo which uses a mix of absolute or relative paths depending on number of ..
, we can now show:
/pathto/compiler/foo.nim
=> compiler/foo.nim
when uses passes --path:compiler:/pathto/compiler
which gives good context as to which package error messages came from--path:std/linenoise:pkg/noise/linenoisecompat
this RFC improves on
--path:path
as follows:src
in nimble packages, without any of the downsides of scope pollution mentioned in https://github.com/nim-lang/RFCs/issues/267#issuecomment-716074374 such as this:proposal
--path:path
is extended to support this new syntax:--path:prefix:path
, which updates a key-value tableprefixes: Table[string,string]
mapping prefix to path.when
import path
is parsed, we now resolve the module as follows:notes (consequences of above rules)
note that
--path:prefix:path
operates as a key-value table, unlike--path:path
, which guarantees that only 1 dir is searched for for a given prefix and avoids inconsistencies. eg:nim r --path:compiler:/pathto/Nim1/compiler --path:compiler:/pathto/Nim2/compiler main
note that you can override a child prefix, which is an important feature (eg for debugging or customization) eg:
nim r --path:compiler:/pathto/Nim1/compiler --path:compiler/ast:/pathto/Nim1/compiler/ast_modif.nim main
It works for packages too:
nim r --path:compiler:/pathto/Nim1/compiler --path:compiler/plugins:/pathto/Nim_temp/compiler/plugins main
benefits
src
in nimble packages can now be omitted without any downside of scope pollutiontests/compiler/nim.cfg
can now containand avoids scope pollution (ie bringing everything in
$nim/
in import scope (egimport tools/deps
) even though we were just interested incompiler/*
)--path:prefix:path
where path isn't found (this would not make as much sense with--path:path
syntax)links
patchFile
is somewhat similar in spirit but different; eg it's an API for nimscript, not a cmdline flag, and doesn't allow overriding a (sub) package. in fact, it seems like--path:prefix:path
subsumespatchFile
somewhat related: offers an alternative for https://github.com/nim-lang/Nim/pull/8636 and https://github.com/nim-lang/Nim/pull/8637
https://github.com/disruptek/dist/discussions/5#discussioncomment-288196