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

stack install package --save to add a dependency to the cabal file #1933

Open
ajnsit opened this issue Mar 20, 2016 · 18 comments
Open

stack install package --save to add a dependency to the cabal file #1933

ajnsit opened this issue Mar 20, 2016 · 18 comments

Comments

@ajnsit
Copy link

ajnsit commented Mar 20, 2016

It would be nice to have a way for stack to automatically add a package dependency to the cabal file using version bounds (in accordance to some accepted package versioning policy) which accept the current version of the package in the snapshot being used.

NPM provides such a functionality with npm install --save <package> which adds the dependency to the local package.json. So one possible command could be stack install --save <package>.

For example, if I want to use the bound package, and the current version in the snapshot is 1.0.7, then running stack install --save bound in the local package directory would add bound >= 1.0 && < 1.1 to the project cabal file (or something else, as long as it's consistent, and admits v1.0.7). The user is free to manually modify the version range in the cabal file later.

If there are multiple sections in the cabal file where the dependency could be added, then perhaps the user can be prompted for each one with an Add package 'bound >= 1.0 && < 1.1' to the dependency list for this section?.

@mgsloan mgsloan added this to the P3: Optional milestone Mar 21, 2016
@mgsloan
Copy link
Contributor

mgsloan commented Mar 21, 2016

stack upload --pvp-bounds will do this on upload. #1568 is also relevant - it tracks having pvp-bounds use multiple configurations. This allows you to test various points within the version intervals.

The main issue is that there isn't currently a good way to refactor cabal files, as far as I know. Perhaps some heuristics could do a decent job. One reason I'm excited about hpack is that since it generates cabal files, this would be a great time to add in the version constraints - sol/hpack#61 . Alternatively, this could be done as a refactoring on the hpack yaml file, which seems like an easier format to automatically manipulate.

I'm totally in favor of being able to automatically add constraints to cabal files, but someone would need to either write a munger that does this correctly or write a more generic system for automatic changes to cabal files.

@ajnsit
Copy link
Author

ajnsit commented Mar 22, 2016

Hpack is great! It would resolve my use case if stack could automatically add deps to hpack's package.yaml, and then automatically regenerate the cabal file.

I just really dislike having to manually edit configuration files :)

@mgsloan
Copy link
Contributor

mgsloan commented Mar 22, 2016

I'm the most pumped about just omitting most version constraints from the package.yaml. This will helpfully call out which dependencies are manual constraints that have some particular reason for existing. Adding constraints while generating the cabal file would be consistent with some of hpack's other magic, such as inferring other-modules / exposed-modules / extra-source-files. We can also check in the cabal file, letting us know when the automatically generated constraints change.

@bitemyapp
Copy link
Contributor

bitemyapp commented May 2, 2016

Here's another (+1) for this from the IRC channel:

Does stack have a command to add a dependency to my cabal file along with its deps? I am new to Haskell and I am looking for something like npm install --save

…and my personal support. Editing and then building when I could've just told it "add this and build it" would be nicer.

@doppioslash
Copy link

+1 it's a common feature in many package manager of other languages, and it was surprising to discover it's not implemented

@ChinaXing
Copy link

+1

@leolimasa
Copy link

I am new to stack and googled this exact functionality. Coming from the JS world, it is pretty common to use "npm install --save" to install libraries. It does save a lot of time.

@dkoontz
Copy link

dkoontz commented May 25, 2017

Big 👍 here as well

@SirensOfTitan
Copy link

Would love this as well.

@jerbaroo
Copy link

jerbaroo commented Aug 4, 2017

Suggest that what version bounds are added is determined with a flag such as --bounds. And have flag values consistent with --pvp-bounds from stack upload, where a value is one of none, upper, lower, both.

If --bounds is omitted a default value is used, perhaps none since this results in a minimal cabal file edit and allows package version be determined by the snapshot.

@CMCDragonkai
Copy link

How would this interact with global-project? Would it save to global-project/stack.yaml or some global-project cabal file?

@decentral1se
Copy link
Member

How would this interact with global-project? Would it save to global-project/stack.yaml

Yep - it should be the same behaviour.

@anhmiuhv
Copy link

anhmiuhv commented Jan 3, 2018

+1

@mgsloan
Copy link
Contributor

mgsloan commented Jan 4, 2018

If someone wants to implement this, my suggestion would be to first implement the following:

  1. A pretty printer for the stack yaml configuration that outputs correct yaml, but in a nice ordering / layout.

  2. Add the feature to automate this particular feature, by loading the configuration, modifying it, and pretty printing it. This will get rid of any of the user's comments, etc.

Having this feature, but not as a proper refactoring, might motivate someone to do the full on support for yaml refactoring, which would require a parser that knows about layout and comments, and a exactprint implementation. Not trivial.

Implementing just the proper refactoring would be less work than doing both, but it's a bit tricky, certainly a fair bit of code would need to be written.

@Kurren123
Copy link

+1 to this, I'm new and was looking for a stack install servant --save

@balazser
Copy link

balazser commented May 2, 2020

+1

@philderbeast
Copy link
Contributor

might motivate someone to do the full on support for yaml refactoring

@mgsloan #5813 adds YAML update that preserves ordering, whitespace and comments.

@sdykae
Copy link

sdykae commented Jun 4, 2023

needed

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