如何使用“cabal-dev ghci”使用非沙箱、非全局(用户?)包?

发布于 2024-12-04 21:29:15 字数 1389 浏览 0 评论 0原文

我正在为我正在从事的项目尝试 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.Genericaeson 不在我的库的 build-depends 中(非常正确),但在我的用户包数据库中。

那么我该如何解决这个问题呢?我可以想象这些类别中的任何一个的答案,但也许有一些类别我错过了:

  1. 一种(选择性地)使用我的用户包数据库中的包与cabal-dev创建的沙箱结合使用的方法< /代码>。 (也许滚动我自己的cabal-dev ghci样式脚本?)

  2. 关于如何改进我的工作流程以便问题消失的建议。

我知道我可以全局安装该软件包,但我不愿意以这种方式污染我的全局软件包数据库(并且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:

  1. A way to (selectively) use packages from my user package database in conjunction with the sandbox created by cabal-dev. (Perhaps rolling my own cabal-dev ghci style script?)

  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我恋#小黄人 2024-12-11 21:29:15

我认为最简单的解决方案就是将您需要的东西安装到沙箱中。例如,如果您的交互式脚本需要 aeson:

~/myproject$ cabal-dev install aeson
~/myproject$ cabal-dev ghci

那么 :set -package aeson 应该可以在 ghci 中工作。

如果这还不够,您需要从用户包数据库中使用很多依赖项,并且您不需要使用 cabal 文件为调用 设置的其他标志来调用 ghci >ghc,然后您可以调用非沙盒 ghci 来访问沙盒中的包以及您的用户和全局包。例如(对于 GHC 7.0.3):(

~/myproject$ GHC_PACKAGE_PATH=./cabal-dev/packages-7.0.3: ghci

请注意 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:

~/myproject$ cabal-dev install aeson
~/myproject$ cabal-dev ghci

Then :set -package aeson should work in ghci.

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 invoking ghc, then you can invoke non-sandboxed ghci with access to the packages from the sandbox as well as your user and global packages. For example (for GHC 7.0.3):

~/myproject$ GHC_PACKAGE_PATH=./cabal-dev/packages-7.0.3: ghci

(Note both the colon at the end of the GHC_PACKAGE_PATH and the space between that and ghci.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文