Proposal: Path.relative_to_file

29 views
Skip to first unread message

Sam Davies

unread,
May 12, 2017, 9:02:54 AM5/12/17
to elixir-lang-core
I've seen this pattern a lot:

`Path.expand('./some_file.ex', Path.dirname(__ENV__.file))`

which returns the path relative to the location of the file it is specified in.

I wonder if we can package this up in a convenient helper method, something like:

`Path.relative_to_file('./some_file.ex')` or `Path.relative_to_current_file('./some_file.ex')`

José Valim

unread,
May 12, 2017, 9:06:45 AM5/12/17
to elixir-l...@googlegroups.com
That pattern should be rewritten to:

Path.expand("some_file.ex", __DIR__)

or:

Path.join(__DIR__, "some_file.ex")

I don't believe we should introduce Path.relative_to_current_file because it would have to be a macro in order to retrieve the current file and __DIR__ is readable enough.


José Valim
Skype: jv.ptec
Founder and Director of R&D

--
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-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/c4b963b4-5c08-4b42-9fac-f7268c1d976c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

José Valim

unread,
May 12, 2017, 12:12:17 PM5/12/17
to elixir-lang-core, jose....@plataformatec.com.br
In any case, thanks for the proposal! Identifying idioms that could be improved is definitely important. I just believe in this case we already do have a good idiom. :)
Reply all
Reply to author
Forward
0 new messages