Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Something like --save in npm? #1961

Closed
kvanbere opened this issue Jun 25, 2014 · 21 comments
Closed

Something like --save in npm? #1961

kvanbere opened this issue Jun 25, 2014 · 21 comments

Comments

@kvanbere
Copy link

npm (the Node.js package manager) allows you to install packages and automatically add the latest version to the dependency list of your package.

It would be cool if you could add a --save flag, which given any scope (including sandboxes) would look for a .cabal file in the current directory and

  • If it's already installed, add the latest version to the depends
  • If it isn't installed, download, install and then append the latest version to the depends

Example usage:

cabal sandbox init
cabal install pipes --save

At least for my node project, it made dependency version management super breezy.

@tibbe
Copy link
Member

tibbe commented Jun 25, 2014

We already have cabal freeze to freeze versions.

@kvanbere
Copy link
Author

I don't think that's the same thing as I'm suggesting. Could you provide a quick example?

@kvanbere
Copy link
Author

Oh, I see. cabal freeze is halfway there. The other half of my suggestion would be a --save flag on installations to automatically append packages to the cabal file when installing heaps of dependencies into sandboxes.

@tibbe
Copy link
Member

tibbe commented Jun 25, 2014

Is the feature you're really missing the addition of the package to the .cabal file or is it freezing the version of the package. cabal freeze covers the latter, but with a different usage pattern.

Latest often doesn't make sense. There's no guarantee that there's a working install plan that involve the latest version of the dependency. There's a soft preference in cabal freeze to use the latest installed version, if possible.

@kvanbere
Copy link
Author

Just the addition of the package to the cabal file, given that cabal freeze already exists.

@tibbe
Copy link
Member

tibbe commented Jun 25, 2014

If you only want to mention the package ones you can instead do this:

  1. Add package to .cabal file.
  2. Run cabal install --only-dep.

This has the same result. Automatically rewriting the .cabal file is difficult, as we want to preserve spacing and user comments. Some day we'll be able to do it.

@kvanbere
Copy link
Author

I guess that's one way to do it, but it probably doesn't save any time.

Oh well, unto the future.

@Fresheyeball
Copy link

👍 for a --save feature

@hughfdjackson
Copy link

👍 from me too - I really enjoy this feature for fast prototyping in node; something i really enjoy doing in haskell too. A little thing, but it makes a developer-happiness difference for me :)

@ryaninvents
Copy link

👍 -- exactly what hughfdjackson said

@ttuegel ttuegel added this to the cabal-install-1.24 milestone Apr 24, 2015
@a-x-
Copy link

a-x- commented May 3, 2015

👍 for a --save feature (and -S alias) like npm!

It's very inconvenient edit .cabal for adding package!
How you live so?

@folsen
Copy link

folsen commented May 6, 2015

I just sat down to see if I could implement this and found a difference between what cabal does and what npm does that affects this. In npm you only have two types of dependencies, package dependencies and development dependencies, represented by the two --save and --save-dev commands.

In cabal however you have 0 or 1 library and 0 or more executables, test-suites and benchmarks. These can all have their own separate dependencies.

So what makes the most semantic sense for a --save command in cabal? I can see 3 options.

  1. It adds the installed package as a dependency to the library (if there is one).
  2. It adds the installed package as a dependency to all the components in the project (library, all executables etc)
  3. We add an optional argument to the --save flag such that without it, it adds the installed package to the library, and you can optionally add component(s) by name just like the cabal build command.

@a-x-
Copy link

a-x- commented May 7, 2015

@folsen, Thank you for research!

👍 3.

I'm beginner in Haskell, and i think that --save might be working with library by default and would be --save-in-component $component_name with components if they have some unique IDs.

If save to all use case is common, that team would be add something like this --save-to-all too.

Excuse my beginner's English

@Fresheyeball
Copy link

Just a thought

cabal file

executable server
  -- stuff
  build-depends:       base >=4.8 && <4.9

install command

cabal install foo --save server build

or

cabal install foo#1.3.6 --save server build

result

executable server
  -- stuff
  build-depends:       base >=4.8 && <4.9
                               , foo 1.3.6

@Wizek
Copy link

Wizek commented Aug 23, 2015

This is a shell script 'solution' I've put together so we can have this functionality even before it is implemented in cabal: https://github.com/Wizek/cabal-install-save

It looks for the latest version of the specified package, adds it to the *.cabal file then does a cabal install --only-dependencies.

Installation:

$ git clone [email protected]:Wizek/cabal-install-save.git
$ # Export to path:
$ echo 'export $PATH:'`pwd`'/cabal-install-save/bin' >> ~/.*hrc

Usage:

$ cd /to/a/cabal/project
$ cabal-install-save foobar

Questions, comments, issues and pull requests are welcome.

@Fresheyeball
Copy link

Correct me if I'm wrong, but I think this issue has been addressed by stack. No? Shouldn't we just use stack from now on instead of using cabal directly? At the very least for conveniences like those being discussed here?

@23Skidoo
Copy link
Member

How does stack solve this problem?

@phadej
Copy link
Collaborator

phadej commented Aug 25, 2015

AFAIK stack never modifies *.cabal files.

@folsen
Copy link

folsen commented Aug 25, 2015

One of the fundamental problems here is that there's not a "proper" parser for *.cabal files, the parser that's in place in the cabal library (not cabal-install and so stack wouldn't solve this problem) throws away a lot of information like structure, comments, etc. The .cabal format is actually quite complex, allowing conditionals etc in the package description.
Once a better parser exists it would be trivial to add the --save feature, but I personally put the project on the shelf because I didn't have time to write a new parser. I know there's some thought/activity on it though from people like Duncan.

@zsszatmari
Copy link

👍

@23Skidoo 23Skidoo modified the milestones: cabal-install 1.24, cabal-install 1.26 Feb 21, 2016
@ezyang ezyang modified the milestone: cabal-install 2.0 Sep 6, 2016
@gbaz
Copy link
Collaborator

gbaz commented Aug 17, 2021

closing as dup in favor of linked ticket

@gbaz gbaz closed this as completed Aug 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests