Skip to content

Commit

Permalink
EOL Ammonite-Ops and Ammonite-Shell (#1227)
Browse files Browse the repository at this point in the history
These two modules were an interesting experiment almost a decade ago, but overall usage has not panned out. Ammonite-Ops is largely replaced by https://github.com/com-lihaoyi/os-lib, even if it's not an exact match. Ammonite-Shell never really saw widespread usage: the vast majority of Ammonite users use Ammonite as a Scala REPL and script runner in addition to (rather than instead of) their default Bash/Zsh/etc. shells.

This PR deletes everything related to these modules: their implementation, build config, and docs. This should help shrink the codebase, simplify the codebase, and let us focus more clearly on what's important going forward
  • Loading branch information
lihaoyi authored Nov 28, 2021
1 parent 63e9859 commit 7aaa308
Show file tree
Hide file tree
Showing 59 changed files with 131 additions and 3,865 deletions.
3 changes: 1 addition & 2 deletions amm/repl/api/src/main/scala/ammonite/repl/api/ReplAPI.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ammonite.repl.api

import ammonite.ops.Internals
import ammonite.util._

import scala.reflect.runtime.universe._
Expand Down Expand Up @@ -220,5 +219,5 @@ trait Clipboard{
*
* @param data New contents for the clipboard.
*/
def write(data: Internals.Writable): Unit
def write(data: geny.Writable): Unit
}
9 changes: 5 additions & 4 deletions amm/repl/src/main/scala/ammonite/repl/ApiImpls.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package ammonite.repl

import ammonite.ops.Internals
import ammonite.repl.api.{Clipboard, FrontEnd, FrontEndAPI, Session}
import ammonite.runtime._
import ammonite.util.Util._
import ammonite.util.{Frame => _, _}

import java.awt.Toolkit
import java.awt.datatransfer.{DataFlavor, StringSelection}
import java.io.ByteArrayOutputStream
import java.util.Locale

import scala.collection.mutable
Expand Down Expand Up @@ -130,9 +129,11 @@ object ClipboardImpl extends Clipboard {
case _ => ""
}

override def write(data: Internals.Writable): Unit = {
override def write(data: geny.Writable): Unit = {
val out = new ByteArrayOutputStream()
data.writeBytesTo(out)
val newContents = new StringSelection(
data.writeableData.map(new String(_)).mkString
new String(out.toByteArray)
)
systemClipboard.setContents(newContents, newContents)
}
Expand Down
27 changes: 0 additions & 27 deletions amm/repl/src/main/scala/ammonite/repl/PPrints.scala
Original file line number Diff line number Diff line change
@@ -1,36 +1,18 @@
package ammonite.repl

import ammonite.ops.{CommandResult, LsSeq}
import ammonite.repl.api.History
import ammonite.runtime.tools.GrepResult
import ammonite.util.Util
import pprint.Renderer

object PPrints{
def replPPrintHandlers(width: => Int): PartialFunction[Any, pprint.Tree] = {
case x: ammonite.ops.LsSeq => PPrints.lsSeqRepr(x, width)
// case x: os.Path => PPrints.pathRepr(x)
// case x: os.RelPath => PPrints.relPathRepr(x)
// case x: ammonite.ops.Path => PPrints.pathRepr(os.Path(x.toString))
// case x: ammonite.ops.RelPath => PPrints.relPathRepr(os.RelPath(x.toString))
case x: ammonite.ops.CommandResult => PPrints.commandResultRepr(x)
case t: History => pprint.Tree.Lazy(ctx => Iterator(t.mkString(Util.newLine)))
case t: GrepResult => pprint.Tree.Lazy(ctx => Iterator(GrepResult.grepResultRepr(t, ctx)))
case t: scala.xml.Elem => pprint.Tree.Lazy(_ => Iterator(t.toString))
}
def lsSeqRepr(t: LsSeq, width: Int) = pprint.Tree.Lazy { ctx =>
val renderer = new Renderer(
ctx.width, ctx.applyPrefixColor, ctx.literalColor, ctx.indentStep
)
val snippets = for (p <- t) yield {
fansi.Str.join(
renderer.rec(relPathRepr(os.RelPath(p.relativeTo(t.base).toString)), 0, 0)
.iter
.toStream:_*
)
}
Iterator(Util.newLine) ++ FrontEndUtils.tabulate(snippets, width)
}


def reprSection(s: String, cfg: pprint.Tree.Ctx): fansi.Str = {
Expand All @@ -53,14 +35,5 @@ object PPrints{
Iterator("root") ++ p.segments.map("/" + reprSection(_, ctx))
)

def commandResultRepr(x: CommandResult) = pprint.Tree.Lazy(ctx =>
x.chunks.iterator.flatMap { chunk =>
val (color, s) = chunk match{
case Left(s) => (ctx.literalColor, s)
case Right(s) => (fansi.Color.Red, s)
}
Iterator(Util.newLine, color(new String(s.array)).render)
}
)
}

12 changes: 5 additions & 7 deletions amm/repl/src/test/scala/ammonite/session/BuiltinTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,18 @@ object BuiltinTests extends TestSuite{

test("loadCP"){
check.session("""
@ import ammonite.ops._, ImplicitWd._
@ val javaSrc = os.pwd/"amm"/"src"/"test"/"resources"/"loadable"/"hello"/"Hello.java"
@ val javaSrc = pwd/"amm"/"src"/"test"/"resources"/"loadable"/"hello"/"Hello.java"
@ os.makeDir.all(os.pwd/"target"/"loadCP"/"hello")
@ mkdir! pwd/"target"/"loadCP"/"hello"
@ os.copy.over(javaSrc, os.pwd/"target"/"loadCP"/"hello"/"Hello.java")
@ cp.over(javaSrc, pwd/"target"/"loadCP"/"hello"/"Hello.java")
@ %javac "target"/"loadCP"/"hello"/"Hello.java" //This line causes problems in windows
@ os.proc("javac", os.rel / "target"/"loadCP"/"hello"/"Hello.java").call() //This line causes problems in windows
@ import $cp.target.loadCP //This line causes problems in windows
@ hello.Hello.hello()
res6: String = "Hello!"
res5: String = "Hello!"
""")
}
test("settings"){
Expand Down
8 changes: 3 additions & 5 deletions amm/repl/src/test/scala/ammonite/session/ProjectTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,16 @@ object ProjectTests extends TestSuite{
// duplicate type CC#44165; previous was type CC#44157
// (2.13 / 3 compatibility issue?)
if (check.scala2 && !check.scala2_12) check.session("""
@ import ammonite.ops._
@ val path = {
@ resource/"org"/"apache"/"jackrabbit"/"oak"/"plugins"/"blob"/"blobstore.properties"
@ os.resource/"org"/"apache"/"jackrabbit"/"oak"/"plugins"/"blob"/"blobstore.properties"
@ }
@ read! path
@ os.read(path)
error: ResourceNotFoundException
@ import $ivy.`org.apache.jackrabbit:oak-core:1.3.16`
@ read! path // Should work now
@ os.read(path) // Should work now
""")
}
test("scalaparse"){
Expand Down
105 changes: 0 additions & 105 deletions amm/repl/src/test/scala/ammonite/unit/ToolsTests.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repl.load.exec(
ammonite.ops.pwd/"amm"/"src"/"test"/"resources"/"scripts"/"predefWithLoad"/"Loaded.sc"
os.pwd/"amm"/"src"/"test"/"resources"/"scripts"/"predefWithLoad"/"Loaded.sc"
)

@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class InProcessMainMethodRunner(p: os.RelPath, preArgs: List[String], args: Seq[
Console.withErr(err0){
Console.withOut(out0){
ammonite.Main.main0(
List("--home", ammonite.ops.tmp.dir().toString) ++
List("--home", os.temp.dir().toString) ++
preArgs ++
Seq(path.toString) ++
args.toList,
Expand Down
Loading

0 comments on commit 7aaa308

Please sign in to comment.