如何使用“cabal-dev ghci”使用非沙箱、非全局(用户?)包?
我正在为我正在从事的项目尝试 cabal-dev
;该项目是一个库,cabal-dev
在构建它的沙盒版本方面做得很好 - 但我的部分工作流程遇到了问题......
我有一个脚本,scratch.hs
,我会将其(前 cabal-dev
)加载到 ghci
中进行尝试。当然,scratch.hs
的内容会随着时间的推移而变化,具体取决于我正在开发的功能。 scratch.hs
不是库代码库的一部分,它只是我在处理它时的个人暂存空间。
现在,为了获得加载了沙箱的 ghci
会话,我只需 cabal-dev ghci
,然后将 scratch.hs
加载到那。问题是,这(按照设计,并且明智地)排除了我的用户包数据库,因此,如果 scratch.hs
引用了不在我的库的 build-depends
(这并非不合理 - 毕竟它不是库的一部分),这些包不可见,因此我收到一个错误,例如:
scripts/scratch.hs:8:8:
Could not find module `Data.Aeson.Generic':
It is a member of the hidden package `aeson-0.3.2.11'.
Perhaps you need to add `aeson' to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
Failed, modules loaded: none.
在这种情况下, scratch.hs
想要导入Data.Aeson.Generic
但 aeson
不在我的库的 build-depends
中(非常正确),但是在我的用户包数据库中。
那么我该如何解决这个问题呢?我可以想象这些类别中的任何一个的答案,但也许有一些类别我错过了:
一种(选择性地)使用我的用户包数据库中的包与
cabal-dev创建的沙箱结合使用的方法< /代码>。 (也许滚动我自己的
cabal-dev ghci
样式脚本?)关于如何改进我的工作流程以便问题消失的建议。
我知道我可以全局安装该软件包,但我不愿意以这种方式污染我的全局软件包数据库(并且cabal-dev
明确阻止这样做)。
非常感谢所有的建议。
I'm trying out cabal-dev
for a project I'm working on; the project is a library, and cabal-dev
does a great job of building a sandboxed version of it - but I'm having trouble with part of my workflow...
I have a script, scratch.hs
, which (pre-cabal-dev
) I would load into ghci
for trying stuff out. The contents of scratch.hs
change over time depending on what feature I'm working on, of course. scratch.hs
isn't part of the library codebase, it's just my personal scratchspace while I'm working on it.
Now, in order to get a ghci
session with my sandbox loaded, I can just cabal-dev ghci
, and then load scratch.hs
into that. The problem is that this (by design, and sensibly) excludes my user package database, so if scratch.hs
references modules from packages which aren't in my library's build-depends
(which is not unreasonable - it's not part of the library after all), those packages aren't visible, and so I get an error such as:
scripts/scratch.hs:8:8:
Could not find module `Data.Aeson.Generic':
It is a member of the hidden package `aeson-0.3.2.11'.
Perhaps you need to add `aeson' to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
Failed, modules loaded: none.
where, in this case, scratch.hs
wants to import Data.Aeson.Generic
but aeson
is not in my library's build-depends
(quite properly), but is in my user package database.
So how can I work around this? I can imagine answers in either of these categories, but maybe there are categories I've missed:
A way to (selectively) use packages from my user package database in conjunction with the sandbox created by
cabal-dev
. (Perhaps rolling my owncabal-dev ghci
style script?)A suggestion on how to improve my workflow so the problem just goes away.
I know I could just install the package globally, but I'm reluctant to pollute my global package database in this manner (and cabal-dev
discourages this explicitly).
Many thanks for all advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为最简单的解决方案就是将您需要的东西安装到沙箱中。例如,如果您的交互式脚本需要 aeson:
那么
:set -package aeson
应该可以在ghci
中工作。如果这还不够,您需要从用户包数据库中使用很多依赖项,并且您不需要使用 cabal 文件为调用
设置的其他标志来调用
,然后您可以调用非沙盒ghci
>ghcghci
来访问沙盒中的包以及您的用户和全局包。例如(对于 GHC 7.0.3):(请注意
GHC_PACKAGE_PATH
末尾的冒号以及它与ghci
之间的空格。)I think the simplest solution is just to install the things that you need into the sandbox. For example, if you need aeson for your interactive script:
Then
:set -package aeson
should work inghci
.If that's inadequate, you have a lot of dependencies you want to use from your user package database, and you don't need
ghci
to be invoked with the other flags that your cabal file sets for invokingghc
, then you can invoke non-sandboxedghci
with access to the packages from the sandbox as well as your user and global packages. For example (for GHC 7.0.3):(Note both the colon at the end of the
GHC_PACKAGE_PATH
and the space between that andghci
.)