Giter VIP home page Giter VIP logo

Comments (9)

avescodes avatar avescodes commented on May 21, 2024

From @micha's response on Question about data readers with datomic and boot:

The data_readers.clj files that are used to set up the tag readers are only parsed by Clojure during its own bootstrap process. This means that only those data_readers.clj files that are on the classpath when the JVM starts will be parsed. Boot, however, allows you to add things to the classpath dynamically. We're going to add this code to boot in the next release, but the workaround for now is to call a private function from clojure.core that will re-scan the classpath and install any new reader files:

(#'clojure.core/load-data-readers)

Be sure to call this function after any calls to set-env! that pull new dependencies or directories into the classpath.

I'd propose one of two solutions:

  • Document this in boot's already great docs.
  • Modify set-env! to reload data readers when it is done adding dependencies.

from boot.

avescodes avatar avescodes commented on May 21, 2024

That said, adding (#'clojure.core/load-data-readers) after set-env! in my build.boot does not seem to change the value of *data-readers*

from boot.

avescodes avatar avescodes commented on May 21, 2024

Repro case of load-data-readers not persisting:

code/tmp  ▸ boot -d com.datomic/datomic-free repl
nREPL server listening: 0.0.0.0:59826
REPL-y 0.3.5, nREPL 0.2.6
Clojure 1.6.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_20-b26
        Exit: Control+D or (exit) or (quit)
    Commands: (user/help)
        Docs: (doc function-name-here)
              (find-doc "part-of-name-here")
Find by Name: (find-name "part-of-name-here")
      Source: (source function-name-here)
     Javadoc: (javadoc java-object-or-class-here)
    Examples from clojuredocs.org: [clojuredocs or cdoc]
              (user/clojuredocs name-here)
              (user/clojuredocs "ns-here" "name-here")
boot.user=> *data-readers*
{}
boot.user=> (#'clojure.core/load-data-readers)
{base64 #'datomic.codec/base-64-literal, db/fn #'datomic.function/construct, db/id #'datomic.db/id-literal}
boot.user=> *data-readers*
{}
boot.user=> (alter-var-root #'clojure.core/*data-readers* (constantly {:foo :bar}))
{:foo :bar}
boot.user=> *data-readers*
{}

EDIT: It seems as if alter-var-root does not take effect on *data-readers* for some reason...

from boot.

avescodes avatar avescodes commented on May 21, 2024

Derp again, it seems like further down in the aforementioned thread the updated suggestion is to run:

(#'clojure.core/load-data-readers)
(set! *data-readers* (.getRawRoot #'*data-readers*))

Seems convoluted enough to wrap up nicely for end users. (Anyways, I've hope you've enjoyed watching me go through the learning process...)

from boot.

martinklepsch avatar martinklepsch commented on May 21, 2024

Tripped upon this very same thing and got to the same solution. Also via the Hoplon forum.

I tried using the REPLs init option to run a file when the real starts but couldn't get it to work.
Probably that's not the right place place to fix this anyway.

from boot.

alandipert avatar alandipert commented on May 21, 2024

Closing, but interested parties may consider moving what they found useful from Discourse and this thread to the wiki.

from boot.

danielsz avatar danielsz commented on May 21, 2024

Tripped on this, too. The workaround works, but brings complexity to the table, since running the code snippet makes sense in development under boot, but not in production where it's deployed as an artefact.

from boot.

danielsz avatar danielsz commented on May 21, 2024

This is fixed in system as of 0.2.1-SNAPSHOT.

https://github.com/danielsz/system

For non-system users, you can try injecting the following task in your build pipeline.

(deftask data-readers []
    (fn [next-task]
      (fn [fileset]
        (#'clojure.core/load-data-readers)
        (with-bindings {#'*data-readers* (.getRawRoot #'*data-readers*)}
          (next-task fileset)))))

from boot.

danielcompton avatar danielcompton commented on May 21, 2024

An update on anyone hitting this still, you can call: (boot.core/load-data-readers!) in your build.boot to force this to be loaded. You can see more discussion at https://hoplon.discoursehosting.net/t/question-about-data-readers-with-datomic-and-boot/99/9.

from boot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.