Access a REPL for a Target
You're working on a Scala or Python project and would like to interact with a library target through a read-eval-print loop (REPL).
repl goal will open up an interactive Scala or Python REPL session for a library target.
$ ./pants repl myproject/src/main/scala
When using the
repl goal, you need to target a
BUILD file containing either a
python_library target. The REPL that you open up via Pants is just a normal Scala or Python REPL with all of the functionality that you're used to if you're familiar with those languages. When using the Scala REPL, Pants will compile the specified dependencies along with your code and load the resulting classes into your classpath.
If you're working on a Scala project that has, for example,
com.twitter.util.Future listed as a dependency, you can load that dependency into the REPL like you usually would:
scala> import com.twitter.util.Future import com.twitter.util.Future
Note: When opening up a REPL via Pants, only those dependencies that are available to the chosen target can be imported (meaning that the dependencies specified in the
python_library definition). If there's a dependency that you'd like to use only in the REPL, you will need to create a library target that includes that dependency.
It's also possible to open the Scala REPL without first compiling the specified library using the
$ ./pants repl-dirty myproject/src/main/scala