Skip to content

Commit

Permalink
add a number of hacks to make the django test pass again
Browse files Browse the repository at this point in the history
  • Loading branch information
dours committed Jun 21, 2022
1 parent ad60f8f commit 3369622
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion transpiler/src/main/eo/preface/newUID.eo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
+alias pyint preface.pyint

[] > newUID
memory 11 > cur
memory 12 > cur
[unused] > apply
seq > @
cur.write (cur.plus (1))
Expand Down
13 changes: 13 additions & 0 deletions transpiler/src/main/eo/preface/xTypeError.eo
Original file line number Diff line number Diff line change
@@ -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) > @
4 changes: 4 additions & 0 deletions transpiler/src/main/eo/preface/xiter.eo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
+package preface

[] > xiter

Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down Expand Up @@ -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" ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand All @@ -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}")
Expand Down

0 comments on commit 3369622

Please sign in to comment.