Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add support for Python; refactor support for Ruby #1

Merged
8 commits merged into from

2 participants

@olix0r

This change refactors CompileThriftRuby out of CompileThriftJava, and also introduces CompileThriftPython and CompileThriftPythonTwisted (all of which extend the common base CompileThrift).

src/main/scala/com/twitter/sbt/CompileThriftPython.scala
@@ -0,0 +1,25 @@
+package com.twitter.sbt
+
+import _root_.sbt._
+
+
+trait CompileThriftPython extends CompileThrift {
+ lazy val compileThriftPython =
+ compileThriftAction("py:new_style") describedAs("Compile thrift into python")
+
+ lazy val autoCompileThriftPython = task {
+ if (autoCompileThriftEnabled)
@robey
robey added a note

code style.

@olix0r
olix0r added a note

this should be without the newline?

@robey
robey added a note

just that it should be like:

if (foo) {
bar
} else {
baz
}

@robey
robey added a note

ugh, github messed it up, but the idea is that the scala code style says use braces if the "if" takes up more than one line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/main/scala/com/twitter/sbt/CompileThriftPython.scala
@@ -0,0 +1,25 @@
+package com.twitter.sbt
+
+import _root_.sbt._
+
+
+trait CompileThriftPython extends CompileThrift {
+ lazy val compileThriftPython =
+ compileThriftAction("py:new_style") describedAs("Compile thrift into python")
+
+ lazy val autoCompileThriftPython = task {
+ if (autoCompileThriftEnabled)
+ compileThriftPython.run
+ else {
+ log.info(name+": not auto-compiling thrift-python; you may need to run compile-thrift-python manually")
@robey
robey added a note

code style (name + ")

@olix0r
olix0r added a note

this was copy/pasted, but the dude abides

@robey
robey added a note

yeah, sorry, i realized that it was a paste halfway thru the review, but it would still be good to fix them while they're being messed with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/main/scala/com/twitter/sbt/CompileThriftRuby.scala
@@ -0,0 +1,18 @@
+package com.twitter.sbt
+
+import _root_.sbt._
+
+
+trait CompileThriftRuby extends CompileThrift {
+ lazy val compileThriftRuby = compileThriftAction("rb") describedAs("Compile thrift into ruby")
+
+ lazy val autoCompileThriftRuby = task {
+ if (autoCompileThriftEnabled) compileThriftRuby.run
@robey
robey added a note

ditto

@olix0r
olix0r added a note

eh? this was copy/pasted from CompileThirftJava... should this have brackets?

@robey
robey added a note

just another if/else block style thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@robey robey commented on the diff
src/main/scala/com/twitter/sbt/GeneratedSources.scala
((15 lines not shown))
override def mainSourceRoots = super.mainSourceRoots +++ (outputPath / generatedJavaDirectoryName ##)
- lazy val cleanGenerated = (cleanTask(generatedJavaPath) && cleanTask(generatedRubyPath)) describedAs
- "Clean generated source folders"
+ lazy val cleanGenerated = (
@robey
robey added a note

indentation

@olix0r
olix0r added a note

should be out-dented?

i.e.:
val foo = (
expr && expr
) decorate()

?

@robey
robey added a note

yeah, to keep the blocks aligned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@robey

+1 after code style... tho it occurs to me that it's confusing to have ruby be automatic with java now. might as well make the all be explicit.

@olix0r

Ruby is not automatically generated with Java? only with Scala (which is necessary afaiu)

@robey

i guess just leave that for now. it just occurred to me that it's a little confusing that ruby bindings are auto-generated for some cases, but that's not true of any other language.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 12, 2011
  1. @olix0r

    Refactor Ruby out of CompileThriftJava.

    olix0r authored
    Add Python [+Twisted] support.
  2. @olix0r

    Update README with changes

    olix0r authored
  3. @olix0r

    typo

    olix0r authored
  4. @olix0r

    Fix typos and compile errors

    olix0r authored
Commits on Mar 13, 2011
  1. @olix0r

    Style scrub

    olix0r authored
  2. @olix0r

    Make twisted-generation a feature of python-generation.

    olix0r authored
    (A flag rather than a separate class)
Commits on Mar 14, 2011
  1. @olix0r
  2. @olix0r

    Style nit: braces in if-clauses

    olix0r authored
This page is out of date. Refresh to see the latest.
View
9 README.md
@@ -2,8 +2,9 @@
Sbt-thrift is an sbt plugin that adds a mixin for doing thrift code auto-generation during your
compile phase. Choose one of these three:
+- `CompileThriftFinagle` - create the java bindings with alternative async interfaces for finagle, in `target/gen-java/`
- `CompileThriftJava` - create just the java bindings, in `target/gen-java/`
-- `CompileThriftFinagle` - create the java bindings with alternative async interfaces for finagle,
- in `target/gen-java/`
-- `CompileThriftScala` - do `CompileThriftFinagle`, but also generate scala wrappers and implicit
- conversions in `target/gen-scala/`
+- `CompileThriftPython` - create just the python bindings, in `target/gen-py/`
+- `CompileThriftPythonTwisted` - create just the python bindings with twisted support, in `target/gen-py/`
+- `CompileThriftRuby` - create just the ruby bindings, in `target/gen-ruby/`
+- `CompileThriftScala` - do `CompileThriftFinagle` and `CompileThriftRuby`, but also generate scala wrappers and implicit conversions in `target/gen-scala/`
View
24 src/main/scala/com/twitter/sbt/CompileThrift.scala
@@ -0,0 +1,24 @@
+package com.twitter.sbt
+
+import _root_.sbt._
+
+import scala.collection.jcl
+
+trait CompileThrift extends DefaultProject with GeneratedSources {
+ def thriftBin = jcl.Map(System.getenv()).get("THRIFT_BIN").getOrElse("thrift")
+
+ def thriftSources = (mainSourcePath / "thrift" ##) ** "*.thrift"
+
+ /** override to disable auto-compiling of thrift */
+ def autoCompileThriftEnabled = true
+
+ // thrift generation.
+ def compileThriftAction(lang: String) = task {
+ import Process._
+ outputPath.asFile.mkdirs()
+ val tasks = thriftSources.getPaths.map { path =>
+ execTask { "%s --gen %s -o %s %s".format(thriftBin, lang, outputPath.absolutePath, path) }
+ }
+ if (tasks.isEmpty) None else tasks.reduceLeft { _ && _ }.run
+ } describedAs("Compile thrift into %s".format(lang))
+}
View
40 src/main/scala/com/twitter/sbt/CompileThriftJava.scala
@@ -1,44 +1,18 @@
package com.twitter.sbt
-import scala.collection.jcl
import _root_.sbt._
-trait CompileThriftJava extends DefaultProject with GeneratedSources {
- def thriftBin = jcl.Map(System.getenv()).get("THRIFT_BIN").getOrElse("thrift")
-
- // thrift generation.
- def compileThriftAction(lang: String) = task {
- import Process._
- outputPath.asFile.mkdirs()
- val tasks = thriftSources.getPaths.map { path =>
- execTask { "%s --gen %s -o %s %s".format(thriftBin,lang, outputPath.absolutePath, path) }
- }
- if (tasks.isEmpty) None else tasks.reduceLeft { _ && _ }.run
- }
-
- def thriftSources = (mainSourcePath / "thrift" ##) ** "*.thrift"
-
- lazy val compileThriftJava = compileThriftAction("java") describedAs("Compile thrift into java")
- lazy val compileThriftRuby = compileThriftAction("rb") describedAs("Compile thrift into ruby")
-
- /** override to disable auto-compiling of thrift */
- def autoCompileThriftEnabled = true
+trait CompileThriftJava extends CompileThrift {
+ lazy val compileThriftJava = compileThriftAction("java")
lazy val autoCompileThriftJava = task {
- if (autoCompileThriftEnabled) compileThriftJava.run
- else {
- log.info(name+": not auto-compiling thrift-java; you may need to run compile-thrift-java manually")
- None
- }
- }
-
- lazy val autoCompileThriftRuby = task {
- if (autoCompileThriftEnabled) compileThriftRuby.run
- else {
- log.info(name+": not auto-compiling thrift-ruby; you may need to run compile-thrift-ruby manually")
+ if (autoCompileThriftEnabled) {
+ compileThriftJava.run
+ } else {
+ log.info("%s: not auto-compiling thrift-java; you may need to run compile-thrift-java manually".format(name))
None
}
}
- override def compileAction = super.compileAction dependsOn(autoCompileThriftJava, autoCompileThriftRuby)
+ override def compileAction = super.compileAction dependsOn(autoCompileThriftJava)
}
View
20 src/main/scala/com/twitter/sbt/CompileThriftPython.scala
@@ -0,0 +1,20 @@
+package com.twitter.sbt
+
+import _root_.sbt._
+
+trait CompileThriftPython extends CompileThrift {
+ val compileThriftPythonTwistedEnabled = false
+ val pythonThriftSpec = if (compileThriftPythonTwistedEnabled) "py:new_style,twisted" else "py:new_style"
+ lazy val compileThriftPython = compileThriftAction(pythonThriftSpec)
+
+ lazy val autoCompileThriftPython = task {
+ if (autoCompileThriftEnabled) {
+ compileThriftPython.run
+ } else {
+ log.info("%s: not auto-compiling thrift-python; you may need to run compile-thrift-python manually".format(name))
+ None
+ }
+ }
+
+ override def compileAction = super.compileAction dependsOn(autoCompileThriftPython)
+}
View
19 src/main/scala/com/twitter/sbt/CompileThriftRuby.scala
@@ -0,0 +1,19 @@
+package com.twitter.sbt
+
+import _root_.sbt._
+
+
+trait CompileThriftRuby extends CompileThrift {
+ lazy val compileThriftRuby = compileThriftAction("rb")
+
+ lazy val autoCompileThriftRuby = task {
+ if (autoCompileThriftEnabled) {
+ compileThriftRuby.run
+ } else {
+ log.info("%s: not auto-compiling thrift-ruby; you may need to run compile-thrift-java manually".format(name))
+ None
+ }
+ }
+
+ override def compileAction = super.compileAction dependsOn(autoCompileThriftRuby)
+}
View
7 src/main/scala/com/twitter/sbt/CompileThriftScala.scala
@@ -10,7 +10,7 @@ import org.jruby.embed._
* called "quack", that has an extremely heinous thrift IDL, which exercises every thrift type
* (with nesting and structs). Grab it and compile it, to make sure this still works :).
*/
-trait CompileThriftScala extends DefaultProject with CompileThriftFinagle {
+trait CompileThriftScala extends DefaultProject with CompileThriftRuby with CompileThriftFinagle {
def scalaThriftTargetNamespace: String
@Deprecated
@@ -29,7 +29,10 @@ trait CompileThriftScala extends DefaultProject with CompileThriftFinagle {
container.runScriptlet(reader, "__TMP__")
val module = container.runScriptlet("Codegen")
for ((_rubyThriftNamespace, _javaThriftNamespace) <- originalThriftNamespaces) {
- container.callMethod(module, "run", (outputPath / generatedRubyDirectoryName ##).toString, (outputPath / generatedScalaDirectoryName ##).toString, _javaThriftNamespace, _rubyThriftNamespace, scalaThriftTargetNamespace)
+ container.callMethod(module, "run",
+ (outputPath / generatedRubyDirectoryName ##).toString,
+ (outputPath / generatedScalaDirectoryName ##).toString,
+ _javaThriftNamespace, _rubyThriftNamespace, scalaThriftTargetNamespace)
}
None
}.dependsOn(autoCompileThriftRuby)
View
15 src/main/scala/com/twitter/sbt/GeneratedSources.scala
@@ -3,16 +3,19 @@ package com.twitter.sbt
import _root_.sbt._
trait GeneratedSources extends DefaultProject {
- def generatedJavaDirectoryName = "gen-java"
- def generatedRubyDirectoryName = "gen-rb"
+ def generatedJavaDirectoryName = "gen-java"
+ def generatedRubyDirectoryName = "gen-rb"
+ def generatedPythonDirectoryName = "gen-py"
- def generatedJavaPath = outputPath / generatedJavaDirectoryName
- def generatedRubyPath = outputPath / generatedRubyDirectoryName
+ def generatedJavaPath = outputPath / generatedJavaDirectoryName
+ def generatedRubyPath = outputPath / generatedRubyDirectoryName
+ def generatedPythonPath = outputPath / generatedPythonDirectoryName
override def mainSourceRoots = super.mainSourceRoots +++ (outputPath / generatedJavaDirectoryName ##)
- lazy val cleanGenerated = (cleanTask(generatedJavaPath) && cleanTask(generatedRubyPath)) describedAs
- "Clean generated source folders"
+ lazy val cleanGenerated = (
@robey
robey added a note

indentation

@olix0r
olix0r added a note

should be out-dented?

i.e.:
val foo = (
expr && expr
) decorate()

?

@robey
robey added a note

yeah, to keep the blocks aligned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ cleanTask(generatedJavaPath) && cleanTask(generatedRubyPath) && cleanTask(generatedPythonPath)
+ ) describedAs "Clean generated source folders"
override def cleanAction = super.cleanAction dependsOn(cleanGenerated)
}
Something went wrong with that request. Please try again.