我可以将自定义包 link 放入 stack.yaml 吗?

Can I put a custom package link to stack.yaml?

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

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

Stackage LTS 似乎不包含这个包。

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

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
    2. 下载 pretty-tree-0.1.0.0.tar.gz
    3. 解压到我的项目文件夹。
    4. pretty-tree-0.1.0.0 添加到 stack.yaml
    packages:
    - .
    - pretty-tree-0.1.0.0
    

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

    我可以将这个 link https://hackage.haskell.org/package/pretty-tree-0.1.0.0/pretty-tree-0.1.0.0.tar.gz 直接添加到 stack.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\snapshots184208\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\snapshots184208\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 版本的内部组件。您不需要知道 Pantry 是什么或它是如何工作的就可以使用 Stack,但如果您有兴趣,可以参考 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: 部分。)