Fork me on GitHub
#clojure
<
2019-08-23
>
hiredman00:08:38

looking at the code I recall it being super fun to work on, so you know, maybe do it anyway

ghaskins02:08:28

Hi all…just a quick note that I’m pleased to announce that we’ve open-sourced our tool “protojure”, which is native support for protobuf/grpc for Clojure: https://protojure.github.io/

👍 16
dominicm09:08:44

There's still a step for generating clojure code?

ghaskins12:08:37

Yeah, it works like any other protoc plugin, but adds “--clojure_out” to the mix.

ghaskins12:08:42

by default, it will only generate the protobuf definitions, but you can also optionally add grpc-server or grpc-client generators by specifying an argument, e.g. “--clojure_out=grpc-client:path/to/output”

ghaskins12:08:29

There is some preliminary documentation available on the GH page. We will be enhancing this moving forward.

dominicm12:08:06

How difficult would it be to do it without generating source files using this code? I've always thought that an interpreter would be more useful in clojure as clojure is very source-oriented. For example this would be incompatible with certain styles of deps.edn local/git dependency

ghaskins15:08:27

well, its not impossible, but it would be a fairly major change from the way its currently designed. For one, it depends on the protoc compiler to parse all the .proto files and generate the AST, which protojure consumes to generate its output

ghaskins15:08:57

that said, I have a similar project in Hyperledger which does its own proto parsing via Instaparse

ghaskins15:08:31

so I can see of a pure clojure lib that parses protos directly at runtime

ghaskins15:08:24

but thats not how Protojure works today: Protojure works like pretty much 99% of the rest of the protobuf/grpc language support works: as a plugin to protoc that generates native code

ghaskins15:08:00

The closest thing I have seen to what you describe is using protobufjs via cljs interop

ghaskins15:08:08

(which is quite slick, I agree)

dominicm15:08:19

Ah. Having protoc do the ast parsing explains why I don't see this get often.

ghaskins15:08:20

but for me, a proto compilation step is quite natural flow

ghaskins15:08:22

if you are curious, this is another project I have: https://github.com/hyperledger/fabric-chaintool

ghaskins15:08:33

that one can do pure clojure parsing of protofiles

ghaskins15:08:43

so, a blend of the two would get to what you are looking for

ghaskins15:08:29

> Ah. Having protoc do the ast parsing explains why I don’t see this get often. Yeah, the ecosystem is definitely structured this way

ghaskins15:08:00

I do think it would be quite possible to leverage the helper routines I have in protojure/lib for a runtime implementation

ghaskins15:08:34

its primarily a matter of doing the parsing and then interning the symbols dynamically

ghaskins15:08:34

in any case, I understand your usecase and it interests me as well…however, competing priorities didn’t allow any time to be spent on it

ghaskins15:08:45

perhaps a future PR

dominicm15:08:02

When I need protobufs next I'll look into it!

👍 4
dodo04:08:17

Like sql => like hugsql => like hugwhere, yes, you do! https://github.com/xiao-ne-zha/hugwhere

🚀 4
vemv10:08:02

can one consolidate the two let steps into one?

(let [the-map (->> x
                                                               rest
                                                               (group-by reader-conditional?))
                                                  [normal-forms reader-conditionals] (map (partial get the-map)
                                                                                          [false true])
...                                       
...I guess I'm asking for a values-at function, but want to have a handy pattern doesn't require me to introduce that dependency whenever needed. i.e. do the thing inline within the ->>

yuhan11:08:10

@vemv you could use map destructuring instead on the result of group-by?

yuhan11:08:51

eg.

(let [xs [1 2 3 5 8 10]
      {odds false, evens true} (group-by even? xs)]
  ...)

vemv11:08:05

yes! fantastic, I had forgotten about this one 🙂

yuhan11:08:18

I think 90% of my uses of group-by are immediately destructured in this way 🙂

clj 12
Matheus Moreira14:08:45

hello! another question about spec and stest/instrument. the function documentation states that there are some parameters that can be used to override specs or mock stuff (:spec, :stub, :gen, :replace). i am not sure how to use these options in my case.

Matheus Moreira14:08:03

i have a function with two parameters, the second more like a dependency: (defn create-todo [task repo] ...) and the spec definition is:

(spec/fdef create-todo
  :args (spec/cat :task :todo/task
                  :repo :repo/repo)
  :ret :model/todo
  :fn (fn [{:keys [args ret]}]
        (and (= (:task args) (:todo/task ret))
             (not (:todo/completed? ret)))))

Matheus Moreira14:08:07

repo/repo is basically (partial satisfies? Repository) and Repository is a protocol. in this case i suppose i should mock the second parameter, e.g. to pass an implementation that holds stuff in memory.

Matheus Moreira14:08:22

how could i do that when using stest/instrument?

alexmiller14:08:23

I'm not sure any of the stest/instrument options directly help you do that

alexmiller14:08:23

really you probably want to use a replacement generator for :repo/repo that just always returns your mock impl

👍 4
unbalanced18:08:22

is there a way to dynamically namespace functions?

unbalanced18:08:57

ehh nvm I'm just being lazy

unbalanced18:08:22

hahaaaaaaa... thx ... needed that today

bmaddy20:08:46

Does anyone know where I could find directions on how to deploy a library (based on deps.edn) to a maven repo (an internal one, not clojars)? Is pomegranate the way to go? Do I need to write the pom file manually?

andy.fingerhut20:08:05

I have not used these tools, so if you are looking for a recommendation based upon successful use, I would wait for another answer, but mevyn listed on this page might do what you hope: https://github.com/clojure/tools.deps.alpha/wiki/Tools

bmaddy20:08:51

Oh, how'd I miss that? Thanks, I'll give it a try!

seancorfield20:08:07

clj -Spom will generate a minimal pom.xml with dependencies but you'll want to expand it quite a bit (then clj -Spom is safe to use again since it will update the dependencies in an existing pom.xml file).

seancorfield20:08:53

FWIW, we use depstar to build JAR (and uberjar) files from source and the generated/expanded pom.xml file. And then we use mvn deploy to actually push the JAR file to a repo.

seancorfield20:08:34

The author of mevyn recently said that if depstar had included the pom-reading/manifest-generating logic from day one, they wouldn't have written mevyn 🙂

andy.fingerhut21:08:26

^^^ That is the answer you wanted to wait for 🙂

bmaddy21:08:21

Oh, nice. I expected -Spom to overwrite instead of update. I think that'll do what I need. Thanks!