From 33696229af1315b768546178673d8a77da1509dc Mon Sep 17 00:00:00 2001 From: dours Date: Wed, 22 Jun 2022 00:54:11 +0300 Subject: [PATCH] add a number of hacks to make the django test pass again --- transpiler/src/main/eo/preface/newUID.eo | 2 +- transpiler/src/main/eo/preface/xTypeError.eo | 13 +++++++++++++ transpiler/src/main/eo/preface/xiter.eo | 4 ++++ .../org/polystat/py2eo/transpiler/Main.scala | 2 +- .../PrintLinearizedMutableEOWithCage.scala | 4 ++++ .../polystat/py2eo/transpiler/Transpile.scala | 4 ++-- .../org/polystat/py2eo/transpiler/Commons.scala | 8 +++++++- .../org/polystat/py2eo/transpiler/Tests.scala | 16 +++++++++++----- 8 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 transpiler/src/main/eo/preface/xTypeError.eo create mode 100644 transpiler/src/main/eo/preface/xiter.eo diff --git a/transpiler/src/main/eo/preface/newUID.eo b/transpiler/src/main/eo/preface/newUID.eo index b0d9168c7..59739c5af 100644 --- a/transpiler/src/main/eo/preface/newUID.eo +++ b/transpiler/src/main/eo/preface/newUID.eo @@ -2,7 +2,7 @@ +alias pyint preface.pyint [] > newUID - memory 11 > cur + memory 12 > cur [unused] > apply seq > @ cur.write (cur.plus (1)) diff --git a/transpiler/src/main/eo/preface/xTypeError.eo b/transpiler/src/main/eo/preface/xTypeError.eo new file mode 100644 index 000000000..5e0f7082b --- /dev/null +++ b/transpiler/src/main/eo/preface/xTypeError.eo @@ -0,0 +1,13 @@ ++package preface ++alias pyint preface.pyint ++alias return preface.return ++alias cage org.eolang.cage + +[] > xTypeError + pyint 11 > x__id__ + [] > apply + [stackUp] > @ + cage result > pResult + [] > result + xTypeError > x__class__ + stackUp.forward (return pResult) > @ diff --git a/transpiler/src/main/eo/preface/xiter.eo b/transpiler/src/main/eo/preface/xiter.eo new file mode 100644 index 000000000..f7f1162e6 --- /dev/null +++ b/transpiler/src/main/eo/preface/xiter.eo @@ -0,0 +1,4 @@ ++package preface + +[] > xiter + diff --git a/transpiler/src/main/scala/org/polystat/py2eo/transpiler/Main.scala b/transpiler/src/main/scala/org/polystat/py2eo/transpiler/Main.scala index ddd82cc4f..e02d5f6e3 100644 --- a/transpiler/src/main/scala/org/polystat/py2eo/transpiler/Main.scala +++ b/transpiler/src/main/scala/org/polystat/py2eo/transpiler/Main.scala @@ -74,7 +74,7 @@ object Main { } Transpile(input.stripExtension, input.slurp) match { - case None => println("Not Supported: input file syntax is not python 3.8") + case None => println("\"Not Supported: input file syntax is not python 3.8\" > error") case Some(transpiled) => output.createFile().writeAll(transpiled) } } diff --git a/transpiler/src/main/scala/org/polystat/py2eo/transpiler/PrintLinearizedMutableEOWithCage.scala b/transpiler/src/main/scala/org/polystat/py2eo/transpiler/PrintLinearizedMutableEOWithCage.scala index ef06028e0..ef821022a 100644 --- a/transpiler/src/main/scala/org/polystat/py2eo/transpiler/PrintLinearizedMutableEOWithCage.scala +++ b/transpiler/src/main/scala/org/polystat/py2eo/transpiler/PrintLinearizedMutableEOWithCage.scala @@ -38,7 +38,9 @@ object PrintLinearizedMutableEOWithCage { "+alias raiseEmpty preface.raiseEmpty", "+alias xmyArray preface.xmyArray", "+alias xlen preface.xlen", + "+alias xiter preface.xiter", "+alias xStopIteration preface.xStopIteration", + "+alias xTypeError preface.xTypeError", "+alias xZeroDivisionError preface.xZeroDivisionError", "+alias xrange preface.xrange", // "+alias sprintf org.eolang.txt.sprintf", @@ -340,6 +342,8 @@ object PrintLinearizedMutableEOWithCage { "xlen > dummy-xlen", "xStopIteration > dummy-stop-iteration", "xZeroDivisionError > dummy-xZeroDivisionError", + "xTypeError > dummy-xTypeError", + "xiter > dummy-xiter", "xrange > dummy-xrange", ) } diff --git a/transpiler/src/main/scala/org/polystat/py2eo/transpiler/Transpile.scala b/transpiler/src/main/scala/org/polystat/py2eo/transpiler/Transpile.scala index ebec87ba6..c1453890c 100644 --- a/transpiler/src/main/scala/org/polystat/py2eo/transpiler/Transpile.scala +++ b/transpiler/src/main/scala/org/polystat/py2eo/transpiler/Transpile.scala @@ -20,7 +20,7 @@ object Transpile { } def transpile(debugPrinter: (Statement.T, String) => Unit)(moduleName: String, opt : Parameters, pythonCode: String): String = { - transpileOption(debugPrinter)(moduleName, opt, pythonCode).getOrElse("Not Supported: input file syntax is not python 3.8") + transpileOption(debugPrinter)(moduleName, opt, pythonCode).getOrElse("\"Not Supported: input file syntax is not python 3.8\" > error") } def applyStyle(pythonCode: String): Option[String] = { @@ -120,7 +120,7 @@ object Transpile { })(immutable.HashSet(), hacked) PrintEO.printSt( - moduleName, hacked, + ("y" + moduleName).replaceAll("[^0-9a-zA-Z]", ""), hacked, "+package org.eolang" :: "+alias pyint preface.pyint" :: "+alias pyfloat preface.pyfloat" :: diff --git a/transpiler/src/test/scala/org/polystat/py2eo/transpiler/Commons.scala b/transpiler/src/test/scala/org/polystat/py2eo/transpiler/Commons.scala index 4b2cb06cd..0c7a11a03 100644 --- a/transpiler/src/test/scala/org/polystat/py2eo/transpiler/Commons.scala +++ b/transpiler/src/test/scala/org/polystat/py2eo/transpiler/Commons.scala @@ -92,7 +92,13 @@ trait Commons { } def writeFile(test: File, dirSuffix: String, fileSuffix: String, what: String, otherLocation: Boolean = false): File = { - val moduleName = test.getName.substring(0, test.getName.lastIndexOf(".")) + val moduleName0 = test.getName.substring(0, test.getName.lastIndexOf(".")) + // do something with hidden files, because current EO fails them + val moduleName = if (moduleName0.startsWith(".")) { + "p" + moduleName0.substring(1, moduleName0.length) + } else { + moduleName0 + } val outPath = if (!otherLocation) test.getAbsoluteFile.getParentFile.getPath + "/" + dirSuffix else dirSuffix val d = new File(outPath) if (!d.exists()) d.mkdir() diff --git a/transpiler/src/test/scala/org/polystat/py2eo/transpiler/Tests.scala b/transpiler/src/test/scala/org/polystat/py2eo/transpiler/Tests.scala index 0afb489f9..8bfc51d14 100644 --- a/transpiler/src/test/scala/org/polystat/py2eo/transpiler/Tests.scala +++ b/transpiler/src/test/scala/org/polystat/py2eo/transpiler/Tests.scala @@ -5,21 +5,23 @@ import org.polystat.py2eo.parser.Statement import org.polystat.py2eo.transpiler.Common.dfsFiles import java.io.File +import java.nio.file.{Files, StandardCopyOption} import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.duration.Duration import scala.concurrent.{Await, Future} +import scala.jdk.javaapi.CollectionConverters.asScala import scala.language.postfixOps -import scala.sys.process.Process +import scala.sys.process.{Process, ProcessLogger} class Tests extends Commons { @Ignore @Test def genUnsupportedDjango() : Unit = { - val root = new File(testsPrefix) - val django = new File(testsPrefix + "/django") + val root = new File("/tmp") + val django = new File("/tmp/django") if (!django.exists()) { // assert(0 == Process("git clone file:///home/bogus/pythonProjects/django", root).!) - assert(0 == Process("git clone https://github.com/django/django", root).!) + assert(0 == Process("git clone -b 4.0 https://github.com/django/django", root).!) } val test = dfsFiles(django).filter(f => f.getName.endsWith(".py")) val futures = test.map(test => @@ -28,7 +30,11 @@ class Tests extends Commons { val name = test.getName println(s"parsing $name") val eoText = try { - Transpile.transpile(db)(chopExtension(name), Transpile.Parameters(wrapInAFunction = false), readFile(test)) + Transpile.transpile(db)( + chopExtension(name), + Transpile.Parameters(wrapInAFunction = false), + readFile(test) + ) } catch { case e : Throwable => println(s"failed to transpile $name: ${e.toString}")