librelist archives

« back to archive

Access project data from REPL

Access project data from REPL

From:
Julien Eluard
Date:
2014-06-12 @ 01:56
Hi,

What is the recommended way to access data defined in the project when in a
REPL session?
I've seen some suggestions but they feel hackish and only provide access to
the static definition of the project.

Ideally the repl-options/init expression could have access to the project
map. Could that be a potential enhancement request?

Thanks,
Julien

Re: [leiningen] Access project data from REPL

From:
Phil Hagelberg
Date:
2014-06-12 @ 16:35
Julien Eluard <julien.eluard@gmail.com> writes:

> What is the recommended way to access data defined in the project when in a
> REPL session?
> I've seen some suggestions but they feel hackish and only provide access to
> the static definition of the project.

Part of the design of Leiningen is that projects shouldn't be aware of
whether they're running inside Leiningen or not. If you're looking for a
bit of config, it's best to set that in a config file and use
project.clj to indicate which config should go on the classpath. If it
needs to be exposed at runtime, it probably doesn't belong in project.clj.

What is the specific information from the project map that you are
looking for? For every use case I've seen, there is usually[1] a better
place to put it.

If you really want the full project map, you can use the configleaf
plugin, but this doesn't fit with the goals of Leiningen.

-Phil

[1] - the one exception here is the version number. This is exposed via
pom.properties in an uberjar and a system property when running under
Leiningen. It would probably be good to unify this so you can use
pom.properties during development too.

Re: [leiningen] Access project data from REPL

From:
Julien Eluard
Date:
2014-06-12 @ 19:40
Hi Phil,

yes I understand your points and it makes perfect sense.
That said I believe this particular use-case is specific and doesn't
violate the isolation leiningen / project as the :init option is leiningen
specific anyway.

I want to start a REPL session that can serve all my development needs. As
I use cljx/ClojureScript associated files must be regenerated / recompiled
when changed. That with the reload pattern and I am all set. That's pretty
easy to achieve but I need to access the cljx/cljsbuild configuration when
initializing the REPL session.

Alternatively I could start several processes to achieve the same but I
loose in reactiveness and control. I could also create a leiningen plugin
but it's not really something that can be reused between projects.

Given leiningen already offers a number of options to configure your REPL
session relying on those seems like the best option.

Cheers,
Julien


2014-06-12 13:35 GMT-03:00 Phil Hagelberg <phil@hagelb.org>:

>
> Julien Eluard <julien.eluard@gmail.com> writes:
>
> > What is the recommended way to access data defined in the project when
> in a
> > REPL session?
> > I've seen some suggestions but they feel hackish and only provide access
> to
> > the static definition of the project.
>
> Part of the design of Leiningen is that projects shouldn't be aware of
> whether they're running inside Leiningen or not. If you're looking for a
> bit of config, it's best to set that in a config file and use
> project.clj to indicate which config should go on the classpath. If it
> needs to be exposed at runtime, it probably doesn't belong in project.clj.
>
> What is the specific information from the project map that you are
> looking for? For every use case I've seen, there is usually[1] a better
> place to put it.
>
> If you really want the full project map, you can use the configleaf
> plugin, but this doesn't fit with the goals of Leiningen.
>
> -Phil
>
> [1] - the one exception here is the version number. This is exposed via
> pom.properties in an uberjar and a system property when running under
> Leiningen. It would probably be good to unify this so you can use
> pom.properties during development too.
>

Re: [leiningen] Access project data from REPL

From:
Phil Hagelberg
Date:
2014-06-12 @ 20:23
Julien Eluard <julien.eluard@gmail.com> writes:

> I want to start a REPL session that can serve all my development needs. As
> I use cljx/ClojureScript associated files must be regenerated / recompiled
> when changed. That with the reload pattern and I am all set. That's pretty
> easy to achieve but I need to access the cljx/cljsbuild configuration when
> initializing the REPL session.

I see. I don't really know anything about the ClojureScript tooling, but
it sounds like it doesn't have a clear distinction between project
config and things required at runtime. In that case the configleaf
plugin might be your best bet.

-Phil

Re: [leiningen] Access project data from REPL

From:
Julien Eluard
Date:
2014-06-12 @ 20:49
lein-cljsbuild itself doesn't need anything at runtime if you stick with
the 'lein cljsbuild auto' but I want to reuse its config to
programmatically trigger the compilation.
It sounds like configleaf can help here (the sticky profile part sounds
scary though). I'll give it a try.

Thanks,
Julien


2014-06-12 17:23 GMT-03:00 Phil Hagelberg <phil@hagelb.org>:

>
> Julien Eluard <julien.eluard@gmail.com> writes:
>
> > I want to start a REPL session that can serve all my development needs.
> As
> > I use cljx/ClojureScript associated files must be regenerated /
> recompiled
> > when changed. That with the reload pattern and I am all set. That's
> pretty
> > easy to achieve but I need to access the cljx/cljsbuild configuration
> when
> > initializing the REPL session.
>
> I see. I don't really know anything about the ClojureScript tooling, but
> it sounds like it doesn't have a clear distinction between project
> config and things required at runtime. In that case the configleaf
> plugin might be your best bet.
>
> -Phil
>

Re: [leiningen] Access project data from REPL

From:
Dave Tenny
Date:
2014-06-12 @ 16:50
I have a related question I've been pondering, where I want to define
version information exactly once.
So I have a version in project.clj, I either want to expose that to the
project some how, or define version information in the project and expose
it to project.clj.

I hadn't experimented with what happened if I just put a def or a load in
the project.clj file, but now seems to be a good time ask on how to define
project version information once and only once for both lein and clojars
publishing, and reasoning about version information in the project code.


On Thu, Jun 12, 2014 at 12:35 PM, Phil Hagelberg <phil@hagelb.org> wrote:

>
> Julien Eluard <julien.eluard@gmail.com> writes:
>
> > What is the recommended way to access data defined in the project when
> in a
> > REPL session?
> > I've seen some suggestions but they feel hackish and only provide access
> to
> > the static definition of the project.
>
> Part of the design of Leiningen is that projects shouldn't be aware of
> whether they're running inside Leiningen or not. If you're looking for a
> bit of config, it's best to set that in a config file and use
> project.clj to indicate which config should go on the classpath. If it
> needs to be exposed at runtime, it probably doesn't belong in project.clj.
>
> What is the specific information from the project map that you are
> looking for? For every use case I've seen, there is usually[1] a better
> place to put it.
>
> If you really want the full project map, you can use the configleaf
> plugin, but this doesn't fit with the goals of Leiningen.
>
> -Phil
>
> [1] - the one exception here is the version number. This is exposed via
> pom.properties in an uberjar and a system property when running under
> Leiningen. It would probably be good to unify this so you can use
> pom.properties during development too.
>

Re: [leiningen] Access project data from REPL

From:
Phil Hagelberg
Date:
2014-06-12 @ 18:01
Dave Tenny <dave.tenny@gmail.com> writes:

> I have a related question I've been pondering, where I want to define
> version information exactly once.
> So I have a version in project.clj, I either want to expose that to the
> project some how, or define version information in the project and expose
> it to project.clj.

Right now the best way to do that is with the Versioneer library.

  https://github.com/trptcolin/versioneer

If you're running from a jar, you can just read pom.properties from the
classpath, but this doesn't work in lein repl, etc. I think it would be
a good idea to make that work, so a single approach could work for both
contexts.

-Phil

Re: [leiningen] Access project data from REPL

From:
Phil Hagelberg
Date:
2014-06-13 @ 23:24
Phil Hagelberg <phil@hagelb.org> writes:

> [1] - the one exception here is the version number. This is exposed via
> pom.properties in an uberjar and a system property when running under
> Leiningen. It would probably be good to unify this so you can use
> pom.properties during development too.

I've implemented this:


https://github.com/technomancy/leiningen/commit/12ec7b92002995b92f3f02c0317728d9c34c3c09


https://github.com/technomancy/leiningen/commit/a7415d2dbe1d3d5f0cbb09d4a9bb7751ba81ca2d

-Phil