2

In order to print pretty vertical tree, I searched google and found a package pretty-tree.

I want to import this package, but the problem is:

It seems that the Stackage LTS does not include this package.

So when I add pretty-tree to package.yaml and stack build, it prompt that

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

I add this revision to stack.yaml:

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

This problem solved and I can complied successfully.

The question is :

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

    Stack document says that

    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

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

  2. There is another way to fix this problem. That is

    1. Download pretty-tree-0.1.0.0.tar.gz from https://hackage.haskell.org/package/pretty-tree
    2. unzip it to my project folder.
    3. Add pretty-tree-0.1.0.0 to stack.yaml
    packages:
    - .
    - pretty-tree-0.1.0.0
    

    This method above can also solve the problem, but my question is:

    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? Such as following:

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

    I try it, stack prompt a error:

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

Sorry, since I am not very familiar with Haskell ecosystem, this question maybe silly.

Thanks.


Edited:

I found that if I first use

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

and then rollback to

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

The error disappeared, but I don't know why...

chansey
  • 1,266
  • 9
  • 20
  • Why would you want to? Adding `pretty-tree-0.1.0.0` is the perfect way to do this. – Erich Apr 21 '20 at 11:51
  • @Erich Because I am not familiar with Haskell ecosystem, I want to know the best practice. – chansey Apr 21 '20 at 11:53
  • Okay, then I tell you that adding `pretty-tree-0.1.0.0` is the best practice. – Erich Apr 21 '20 at 11:54
  • @Erich I dont think that is best practice. The reason is if I have 2 projects both use pretty-tree, I need unzip and copy-paste twice. – chansey Apr 21 '20 at 12:00
  • You don't have to download pretty-tree yourself. Just add `pretty-tree-0.1.0.0` and stack automatically downloads everything. – Erich Apr 21 '20 at 12:04
  • @Erich As I mentioned in the question, I added `pretty-tree` to `package.yaml` and `stack build`. Then the stack prompt a error `pretty-tree needed, but the stack configuration has no specified version`. It seems that Stackage LTS does not include this package. What do you mean by "add pretty-tree-0.1.0.0"? Just add `pretty-tree-0.1.0.0` to `extra-deps` in `stack.yaml` without full URI? – chansey Apr 21 '20 at 12:11
  • 2
    Yes, this is the best way to do it IMHO. – Erich Apr 21 '20 at 12:16
  • @Erich I delete all files in `C:\sr` (this folder may be `.stack` in linux), clean `.stack-work` in my project, add `pretty-tree-0.1.0.0` to `extra-deps` in `stack.yaml` without full URI, and then rebuild it. It complied successfully now. Thanks! Perhaps stack download packages from Hackage by combining "URI" ++ "package-name" ++ "version" automatically. – chansey Apr 21 '20 at 12:52
  • @Erich The remaining question is What is Pantry? Could you explain it if you have time? – chansey Apr 21 '20 at 12:52
  • 2
    @chansey It’s an internal component of Stack used to specify package versions. See [the documentation](https://docs.haskellstack.org/en/stable/pantry/) for more details. – bradrn Apr 21 '20 at 12:54
  • @bradrn OK, Now I understand that when I add name/version combination `pretty-tree-0.1.0.0` to `extra-deps` in `stack.yaml`, the `pretty-tree-0.1.0.0` exactly Hackage location! Thanks. (I used to misunderstand that we need refer to the URL of Hackage, e.g. https://hackage.haskell.org/package/pretty-tree-0.1.0.0/pretty-tree-0.1.0.0.tar.gz) Now it's clear. – chansey Apr 21 '20 at 13:03
  • @chansey That’s correct. – bradrn Apr 21 '20 at 13:08

1 Answers1

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

This long string of text you’ve included is a description of a package version. pretty-tree is the package name, 0.1.0.0 is the version you’re using, 49b0e17008f9d30328db2bcc2958f3a7b78d154d2335c2dbaa2073e237b524ae is a SHA256 hash of the package’s Cabal file, and 688 is the size of the Cabal file. (Source: https://docs.haskellstack.org/en/stable/pantry/) Really you only need to include the pretty-tree-0.1.0.0 bit; the rest isn’t necessary, but if you do include it, Stack uses it for validation purposes, to ensure that your build is reproducible by checking that it always downloads the same package every time.

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

Pantry is simply the internal component which Stack uses to specify Stack versions. You don’t need to know what Pantry is or how it works in order to use Stack, but if you’re interested, you can refer to https://docs.haskellstack.org/en/stable/pantry/ for more information.

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

I have no idea why you would want to do this: this is pretty much exactly what Stack does to install a package, but if you do it manually you have a much greater chance of messing it up.

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?

Again, I’m not entirely why you would want to do this, since Stack downloads the package from this location anyway when you specify pretty-tree-0.1.0.0. But surprisingly, it turns out that you actually can do this if you really want to! Using the documentation for extra-deps, it appears that you can do the following:

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

(Untested, but this should work. If it doesn’t, you may need to add a subdirs: section, as per the linked documentation.)

bradrn
  • 8,337
  • 2
  • 22
  • 51
  • "I have no idea why you would want to do this: this is pretty much exactly what Stack does to install a package, but if you do it manually you have a much greater chance of messing it up." I think the advantage of this method is that we can modified the source code of `pretty-tree`. Of course, it is another story. – chansey Apr 21 '20 at 13:13
  • @chansey Interesting point! I hadn’t thought of that. But if you want to modify the source code, there is a much simpler way: `git clone` (or some other similar method) the code of `pretty-tree` to another directory, modify the code there, and add an `extra-dep` pointing to that directory. Much simpler, and it doesn’t require you to mess with the internals of Stack. – bradrn Apr 21 '20 at 13:15
  • Following the [documentation for extra-deps](https://docs.haskellstack.org/en/stable/yaml_configuration/#extra-deps), I tested add `url: https://hackage.haskell.org/package/pretty-tree-0.1.0.0/pretty-tree-0.1.0.0.tar.gz` to `extra-deps:` in `stack.yaml`, but failed as I mentioned in question. Anyway, it is not a problem now. – chansey Apr 21 '20 at 13:16
  • @chansey I’ve just looked at that error, and it looks pretty unusual. I’d suggest submitting it as an issue with Stack on the [issues page](https://github.com/commercialhaskell/stack/issues). – bradrn Apr 21 '20 at 13:17
  • I did not add an `extra-dep:` pointing to that directory. I add "pretty-tree-0.1.0.0" to the `packages:` in the `stack.yaml`. (The "pretty-tree-0.1.0.0" is the unzip folder of `pretty-tree-0.1.0.0.tar.gz`). I did not test your method i.e. "add an extra-dep pointing to that directory". – chansey Apr 21 '20 at 13:27
  • @chansey You should be using `extra-deps:` rather than `packages:` for what you are doing. The Stack documentation explains it better than I can, but basically, `packages:` lists the packages which __you__ are developing in that project, whereas `extra-deps:` lists the packages which you __depend on__ from other projects. So as a dependency, you should be listing `pretty-tree` in your `extra-deps`. – bradrn Apr 21 '20 at 13:30
  • When you want to modify source code of that package, it is difficult to distinguish between a package which you are developing in project and and a package you depend on. Another problem is that it seems that when using `extra-deps:`, the packages will install to `C:sr\snapshots\xxxx`, but when using `packages:`, the packages only keep in the project folder locally. – chansey Apr 21 '20 at 13:42
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/212165/discussion-between-bradrn-and-chansey). – bradrn Apr 21 '20 at 13:55