Why cabal sandbox init does not change PATH like virtualenv does?

試著忘記壹切 提交于 2019-12-09 10:40:25

问题


Haskell newbie and Python guy here.

I think I may be missing something here but if you look at Yesod's quickstart, the autor install some packages before cabal sandbox init. I have seen the same pattern elsewhere. Questions:

  1. Am I missing something? Is this the real way to use cabal sandbox?
  2. Why can't (or shouldn't) I install yesod-bin inside a sandbox?
  3. What if I use different versions of yesod-bin throughout some projects?
  4. If there is some libraries that install binaries inside .cabal-sandbox/bin, why cabal sandbox init don't change PATH in order to match the sandboxed version?

Thank you very much in advance!


回答1:


  1. Yes, this how to use a sandbox.

    cabal sandbox init will create some files / directories for you that will keep track of the packages you have installed.

    cabal install some_package will install that package into the sandbox.

  2. You are more than welcome to install yesod-bin into a sandbox.

  3. Read point 2

  4. cabal sandbox init doesn't change your path, because it doesn't really need to. Just add PATH=.cabal-sandbox/bin:$PATH in your .bash_profile.

    Unlike virtual-env, you never need to 'enable' or 'disable' a sandbox. You just cd into a directory, and it is automatically enabled.

    The only real downside I have found to cabal sandboxes, is that you need to be in the root directory in order to act upon a sandbox. Meaning, if you are in a sub-directory, running cabal install some_package will not install it into the sandbox that is up a level, instead it will install it into either the global or user database, depending on how you have cabal configured.




回答2:


cabal exec lets you execute a program in the context of a sandbox. It changes the path to include the bin folder of the sandbox. You can see it by executing cabal exec printenv inside the sandbox.

Also, the latest versions of cabal let you create sandboxes in folders without .cabal files. Once you run cabal sandbox init, you can just cabal install the dependencies you need.

So, to use different versions of yesod-bin, install them in different sandboxes, and then invoke cabal exec yesod-bin on each one.

(Extra tip: cabal exec gchi is a useful command that makes ghci aware of the contents of the sandbox.)



来源:https://stackoverflow.com/questions/28141705/why-cabal-sandbox-init-does-not-change-path-like-virtualenv-does

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!