easy dependencies installation

112 views
Skip to first unread message

Vitaly Shvedchenko

unread,
Jul 18, 2017, 5:17:43 PM7/18/17
to elixir-lang-core
Hi guys,

I'd like to suggest a feature and may be implement it. I've found somebody proposed this feature earlier, but it was a long time ago and there was not a single reply to it. So I'd try one more time for that poor guy and for me. 

When you develop elixir project and adding new dependencies to the project, you always have to find needed package onlline, find out it's latest version number and put it in your mix.exs dependencies for yourself. What could be helpful is some equivalent of a
npm install --save
command from nodejs world. It would be like
mix deps.install package_name
What this command has to do is just 
1. check if hex is installed, propose to install it if it is not, 
2. get the hex package info, parse its version, 
3. put it in mix.exs file (with some conventional semantic versioning pattern like "~> x.y")
4. and call mix deps.get—thats it! 
It probably would not put the dependency in OTP applications to start list, but still it is much easier way of installing dependencies.

I guess there is some conventional reasons to not implement such way of installing new dependencies, but it's not obvious for me and many other people why there is no such option.

Thanks! Will be glad to have some feedback. 

Louis Pilfold

unread,
Jul 18, 2017, 5:37:57 PM7/18/17
to elixir-lang-core
Hey Vitaly

The dependency file for mix is an Elixir program rather than just a simple JSON file. There's no way reliably and safely programatically modify the mix.exs file as a result.

Cheers,
Louis

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/9daf03ef-a9a6-44d2-b7d5-68c345b42d76%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vitaly Shvedchenko

unread,
Jul 18, 2017, 7:30:51 PM7/18/17
to elixir-lang-core, lo...@lpil.uk
Ok, so it would be just an option to leave a version string empty to let mix just get the latest version of a package. This is how a ruby gem dependencies with Gemfile works.

Bryan Stearns

unread,
Jul 18, 2017, 7:39:33 PM7/18/17
to elixir-l...@googlegroups.com, lo...@lpil.uk
It’d be hard to reliably parse & edit mix.exs files in general, but since I can promise myself that I’ll adhere to certain formatting rules in my own projects, I wrote https://github.com/bryanstearns/mix_deps_add … and if you don’t like my rules (see the README), please file an issue or send a PR. (As it happens, I didn’t support comments within the deps/0 function in the versions I’ve released, but I’ll eventually finish the branch that supports them.)

I definitely don’t think something this arbitrary belongs in Mix itself!

To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/2c6070cd-f108-4ddc-90f3-77f77d1b6298%40googlegroups.com.

Norbert Melzer

unread,
Jul 19, 2017, 4:03:40 AM7/19/17
to elixir-l...@googlegroups.com
Louis Pilfold <lo...@lpil.uk> schrieb am Di., 18. Juli 2017 um 23:37 Uhr:
Hey Vitaly

The dependency file for mix is an Elixir program rather than just a simple JSON file. There's no way reliably and safely programatically modify the mix.exs file as a result.

This is a thing I do totally understand, and I won't argue about.

But what if did the following workflow?

$ mix deps.preload ecto
[...] downloading most recent version of ecto and its dependencies that fits into current set of constraints [...]

Please add `{:ecto, "~> 2.1"}' to your deps.
$ edit mix.exs
# edit deps
$ mix deps.compile

This way, we do get the most current version of ecto that is capable to work with our project and we do get a hint on what we have to add to our mix-file.

Even though we have to add that line manually, the burden to manually check versions has been taken from the developer.

Of course, there is much room to discuss how to actually name that task. Perhaps even have it in `hex`?

Cheers,
Louis

Bye,
  Norbert 

Vitaly Shvedchenko

unread,
Jul 19, 2017, 5:59:02 AM7/19/17
to elixir-lang-core, lo...@lpil.uk
Nice work, Bryan! Thats quiet close to something I'd have.

Vitaly Shvedchenko

unread,
Aug 18, 2017, 7:44:55 AM8/18/17
to elixir-lang-core, lo...@lpil.uk
But, Louis, isn't abstract syntax tree a way of safely modify elixir code? For example I could quote all the mix.exs file, find dependencies tuple, modify it and unquote it back.


On Wednesday, July 19, 2017 at 12:37:57 AM UTC+3, Louis Pilfold wrote:

Norbert Melzer

unread,
Aug 18, 2017, 8:02:24 AM8/18/17
to elixir-lang-core, lo...@lpil.uk

But the dependencies could be read programmatically from a file elsewhere or even from a remote database or...


Louis Pilfold

unread,
Aug 18, 2017, 8:22:09 AM8/18/17
to elixir-lang-core
Hiya

If you go down that route you'd lose all formatting, comments, etc, which is a shame.

Have a go, no reason this couldn't be a third party mix task rather than an official built-in one.

Cheers,
Louis

Reply all
Reply to author
Forward
0 new messages