Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A Python client for nREPL, the Clojure network REPL

License

NotificationsYou must be signed in to change notification settings

clojure-vim/nrepl-python-client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Surprisingly, annREPL clientwritten in Python.

It pretty much works.

Requires Python 2.7 or 3.3. Will work with any nREPL >= 0.2.0 endpoint that uses thedefault bencode socket transport. Support forothertransportsshould be straightforward, thanks to an unpythonic multimethod thing thatnrepl.connect() uses.

Installation

Clone from here and use the source, or you can install fromPyPI, e.g.:

$ easy_install nrepl-python-client

Or alternatively:

$ pip install nrepl-python-client

Usage

Two options, currently. First, explicit, synchronous send/receive of messagesto an nREPL endpoint:

>>>importnrepl>>>c=nrepl.connect("nrepl://localhost:58226")>>>c.write({"op":"eval","code":"(reduce + (range 20))"})>>>c.read(){u'session':u'7fb4b7a0-f9e5-4f5f-b506-eb2d0a6e21b1',u'ns':u'user',u'value':u'190'}>>>c.read(){u'status': [u'done'],u'session':u'7fb4b7a0-f9e5-4f5f-b506-eb2d0a6e21b1'}

WatchableConnection provides a facility vaguely similar to Clojure watches,where a function is called asynchronously when an nREPL response is received ifa predicate or a set of pattern-matching criteria provided with that functionmatches the response. For example (from the tests), this code willasynchronously captureout (i.e.stdout) content from multiplesessions' responses:

c=nrepl.connect("nrepl://localhost:58226")wc=nrepl.WatchableConnection(c)outs= {}defadd_resp (session,msg):out=msg.get("out",None)ifout:outs[session].append(out)defwatch_new_sessions (msg,wc,key):session=msg.get("new-session")outs[session]= []wc.watch("session"+session, {"session":session},lambdamsg,wc,key:add_resp(session,msg))wc.watch("sessions", {"new-session":None},watch_new_sessions)wc.send({"op":"clone"})wc.send({"op":"clone"})wc.send({"op":"eval","session":outs.keys()[0],"code":'(println "hello" "%s")'%outs.keys()[0]})wc.send({"op":"eval","session":outs.keys()[1],"code":'(println "hello" "%s")'%outs.keys()[1]})outs#>> {u'fee02643-c5c6-479d-9fb4-d1934cfdd29f': [u'hello fee02643-c5c6-479d-9fb4-d1934cfdd29f\n'],u'696130c8-0310-4bb2-a880-b810d2a198d0': [u'hello 696130c8-0310-4bb2-a880-b810d2a198d0\n']}

The watch criteria dicts (e.g.{"new-session": None}) are used to constrainwhich responses received by theWatchableConnection will be passed to thecorresponding callbacks:

  • {"new-session": None} will match any response that has any value in the"new-session" slot
  • {"session": session} will match any response that has the valuesession inthe"session" slot.

Sets may also be used as values in criteria dicts to match responses thatcontain any of the set's values in the slot that the set is fond in the criteriadict.

Finally, regular predicates may be passed towatch() to handle more complexfiltering.

The callbacks provided towatch() must accept three arguments: the matchedincoming message, the instance ofWatchableConnection, and the key under whichthe watch was registered.

Send help

  • Make this amore Proper Python Library. I've been away from Python for aloooooong time, and I don't know what the current best practices are aroundeggs, distribution, and so on. The library is on PyPI, but may not befollowing the latest best practices for all I know. Open an issue if you seea problem or some corner that could be made better.
  • Fix my busted Python. Like I said, the last time I did any serious Pythoningwas in the 2.3 days or something (to use new-style classes, or not, that wasthe question, etc). If I goofed, open an issue with a fix.

Need Help?

Pingcemerick on freenode irc ortwitter if you have questions or wouldlike to contribute patches.

License

Copyright ©2013Chas Emerick and other contributors

Distributed under the MIT License. Please see theLICENSE file at the toplevel of this repo.

About

A Python client for nREPL, the Clojure network REPL

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python100.0%

[8]ページ先頭

©2009-2025 Movatter.jp