Skip to content

Commit

Permalink
Support Python main files through JSON
Browse files Browse the repository at this point in the history
This change makes it possible to run `libinteractive json
--parent-lang=py`.
  • Loading branch information
lhchavez committed May 12, 2019
1 parent 7261d3d commit af599cd
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/main/scala/com/omegaup/libinteractive/targets/Python.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Python(idl: IDL, options: Options, input: Path, parent: Boolean)
List(
new OutputDirectory(options.resolve(idl.main.name)),
new OutputLink(options.resolve(idl.main.name, mainFile), input),
generateMain,
generateMainFile,
generateMainEntry)
} else {
generateTemplates(input) ++
Expand All @@ -33,11 +33,20 @@ class Python(idl: IDL, options: Options, input: Path, parent: Boolean)
}

override def generateInterface(interface: Interface) = {
List(
new OutputDirectory(options.resolve(interface.name)),
generateLib(interface),
generate(interface),
generateLink(interface, input))
if (interface == idl.main) {
val mainFile = s"${idl.main.name}.$extension"
List(
new OutputDirectory(options.resolve(idl.main.name)),
new OutputLink(options.resolve(idl.main.name, mainFile), input),
generateMainFile,
generateMainEntry)
} else {
List(
new OutputDirectory(options.resolve(interface.name)),
generateLib(interface),
generate(interface),
generateLink(interface, input))
}
}

def pythonExecutable() = {
Expand Down Expand Up @@ -164,7 +173,7 @@ runpy.run_module("${idl.main.name}", run_name="__main__")"""
builder.mkString)
}

private def generateMain() = {
private def generateMainFile() = {
val main = templates.code.python_main(this, options, idl)

OutputFile(
Expand Down

0 comments on commit af599cd

Please sign in to comment.