haskell - 我可以将自定义包链接放入 stack.yaml 吗?

标签 haskell haskell-stack hackage stackage

为了打印漂亮的垂直树,我搜索了google,找到了一个包pretty-tree .

我想导入这个包,但问题是:

Stackage LTS 似乎不包含此软件包。

所以当我添加pretty-tree时至package.yamlstack build ,提示

In the dependencies for quick-sort-0.1.0.0:
    pretty-tree needed, but the stack configuration has no specified version  (latest matching version is 0.1.0.0)
needed since quick-sort is a build target.

Some different approaches to resolving this:

  * Recommended action: try adding the following to your extra-deps in E:\work-category-theory\quick-sort\stack.yaml:

- pretty-tree-0.1.0.0@sha256:49b0e17008f9d30328db2bcc2958f3a7b78d154d2335c2dbaa2073e237b524ae,668

我将此修订添加到 stack.yaml :

extra-deps:
  - pretty-tree-0.1.0.0@sha256:49b0e17008f9d30328db2bcc2958f3a7b78d154d2335c2dbaa2073e237b524ae,668

这个问题解决了,我可以成功编译。

问题是:

  1. 什么是pretty-tree-0.1.0.0@sha256:49b0e17008f9d30328db2bcc2958f3a7b78d154d2335c2dbaa2073e237b524ae, 688 ,来自哪里?

    堆栈文档说的是

    extra-deps

    This field allows you to specify extra dependencies on top of what is defined in your snapshot (specified in the resolver field mentioned above). These dependencies may either come from a local file path or a Pantry package location.

    For the local file path case, the same relative path rules as apply to packages apply.

    Pantry package locations allow you to include dependencies from three different kinds of sources:

    Hackage

    Archives (tarballs or zip files, either local or over HTTP(S))

    Git or Mercurial repositories

    但我不知道Pantry是什么...

  2. 还有另一种方法可以解决此问题。 那就是

    1. https://hackage.haskell.org/package/pretty-tree下载pretty-tree-0.1.0.0.tar.gz
    2. 将其解压缩到我的项目文件夹中。
    3. 添加pretty-tree-0.1.0.0stack.yaml
    packages:
    - .
    - pretty-tree-0.1.0.0
    

    上面这个方法也可以解决问题,但是我的问题是:

    我可以添加这个链接https://hackage.haskell.org/package/pretty-tree-0.1.0.0/pretty-tree-0.1.0.0.tar.gzstack.yaml直接地?比如下面这样:

    extra-deps: 
      - url: https://hackage.haskell.org/package/pretty-tree-0.1.0.0/pretty-tree-0.1.0.0.tar.gz
    

    我试了一下,堆栈提示错误:

E:\work-category-theory\quick-sort>stack build
Stack has not been tested with GHC versions above 8.6, and using 8.8.3, this may fail
Stack has not been tested with Cabal versions above 2.4, but version 3.0.1.0 was found, this may fail
boxes               > using precompiled package
contravariant       > using precompiled package
distributive        > using precompiled package
th-abstraction      > using precompiled package
transformers-compat > using precompiled package
unordered-containers> using precompiled package
pretty-tree         > configure
pretty-tree         > Configuring pretty-tree-0.1.0.0...
pretty-tree         > build
pretty-tree         > Preprocessing library for pretty-tree-0.1.0.0..
pretty-tree         > Building library for pretty-tree-0.1.0.0..
pretty-tree         > [1 of 1] Compiling Data.Tree.Pretty
pretty-tree         > copy/register
pretty-tree         > Installing library in C:\sr\snapshots\34184208\lib\x86_64-windows-ghc-8.8.3\pretty-tree-0.1.0.0-KT
aQApPwVahHd2AQwQQQSA
pretty-tree         > Registering library for pretty-tree-0.1.0.0..
Received ExitFailure 1 when running
Raw command: "C:\\Users\\Chansey\\AppData\\Local\\Programs\\stack\\x86_64-windows\\ghc-8.8.3\\bin\\ghc-pkg.exe" --user -
-no-user-package-db --package-db "C:\\sr\\snapshots\\34184208\\pkgdb" describe --simple-output distributive --expand-pkg
root
Standard error:

ghc-pkg.exe: C:\sr\snapshots\34184208\pkgdb\th-abstraction-0.3.2.0-D5zRQZUNFcq6kU1WHIrSvs.conf: getModificationTime:Crea
teFile "\\\\?\\C:\\sr\\snapshots\\34184208\\pkgdb\\th-abstraction-0.3.2.0-D5zRQZUNFcq6kU1WHIrSvs.conf": does not exist (
The system cannot find the file specified.)

Progress 7/15

抱歉,由于我对 Haskell 生态系统不太熟悉,这个问题可能很愚蠢。

谢谢。


编辑:

我发现如果我第一次使用

extra-deps:
  - pretty-tree-0.1.0.0@sha256:49b0e17008f9d30328db2bcc2958f3a7b78d154d2335c2dbaa2073e237b524ae,668

然后回滚到

  extra-deps: 
    - url: https://hackage.haskell.org/package/pretty-tree-0.1.0.0/pretty-tree-0.1.0.0.tar.gz

错误消失了,但我不知道为什么......

最佳答案

  1. What is pretty-tree-0.1.0.0@sha256:49b0e17008f9d30328db2bcc2958f3a7b78d154d2335c2dbaa2073e237b524ae, 688, where is from?

您包含的这一长串文本是软件包版本的描述。 pretty-tree 是软件包名称,0.1.0.0 是您正在使用的版本,49b0e17008f9d30328db2bcc2958f3a7b78d154d2335c2dbaa2073e237b524ae 是软件包 Cabal 文件的 SHA256 哈希值,688 是 Cabal 文件的大小。 (来源: https://docs.haskellstack.org/en/stable/pantry/ )实际上,您只需要包含 pretty-tree-0.1.0.0 位即可;其余的不是必需的,但如果您确实包含它,Stack 会将其用于验证目的,通过检查它每次总是下载相同的包来确保您的构建是可重现的。

But I don't know what Pantry is...

Pantry 只是 Stack 用于指定 Stack 版本的内部组件。使用 Stack 不需要知道 Pantry 是什么或者它是如何工作的,但是如果你有兴趣,可以引用 https://docs.haskellstack.org/en/stable/pantry/了解更多信息。

There is another way to fix this problem … Download pretty-tree-0.1.0.0.tar.gz

我不知道你为什么要这样做:这几乎就是 Stack 安装软件包的方式,但如果你手动执行,你就有更大的机会把它搞砸。

Can I add this link https://hackage.haskell.org/package/pretty-tree-0.1.0.0/pretty-tree-0.1.0.0.tar.gz to stack.yaml directly?

再说一遍,我并不完全理解您想要这样做的原因,因为当您指定 pretty-tree-0.1.0.0 时,Stack 无论如何都会从这个位置下载包。但令人惊讶的是,事实证明,如果你真的愿意的话,你实际上可以做到这一点!使用documentation for extra-deps ,看来您可以执行以下操作:

extra-deps:
- url: https://hackage.haskell.org/package/pretty-tree-0.1.0.0/pretty-tree-0.1.0.0.tar.gz

(未经测试,但这应该可行。如果不行,您可能需要根据链接文档添加 subdirs: 部分。)

关于haskell - 我可以将自定义包链接放入 stack.yaml 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61341717/

相关文章:

haskell - 简单 Haskell Monad - 随机数

haskell - Parsec:预测解析

haskell - 多包项目中的测试输出未显示为 `stack test`

haskell - SDL_image 无法安装

haskell - 离线安装和运行 haskell 包

haskell - 更新堆栈中的全局 GHC/i 快照

haskell - HackageDB 的用户名?

haskell - 使用测试创建完整的 Haskell 堆栈

haskell - 非维护者上传到 Hackage

haskell - 如何读取haskell字符串