compilertools support python dependencies in virtualenv. close #37
This commit is contained in:
@@ -24,7 +24,7 @@ typedef CompilationArgs = {
|
|||||||
?importHxFile:String,
|
?importHxFile:String,
|
||||||
// path to a file with hxml args in it (SHOULD NOT specify target or main class)
|
// path to a file with hxml args in it (SHOULD NOT specify target or main class)
|
||||||
?hxmlFile:String,
|
?hxmlFile:String,
|
||||||
// path to a package.json or requirements.txt file
|
// path to a package.json, requirements.txt, or setup.py file
|
||||||
?langProjectFile:String,
|
?langProjectFile:String,
|
||||||
// path to a haxe file defining the Main class
|
// path to a haxe file defining the Main class
|
||||||
?mainHxFile:String,
|
?mainHxFile:String,
|
||||||
@@ -56,6 +56,8 @@ class CompilerTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if folder exists, delete it
|
// if folder exists, delete it
|
||||||
|
// TODO this assumes the user hasn't put folders in the folder, which
|
||||||
|
// would cause a failure because we're not deleting recursively
|
||||||
if (FileSystem.exists(args.outputFolder)) {
|
if (FileSystem.exists(args.outputFolder)) {
|
||||||
for (file in FileSystem.readDirectory(args.outputFolder)) {
|
for (file in FileSystem.readDirectory(args.outputFolder)) {
|
||||||
FileSystem.deleteFile(Path.join([args.outputFolder, file]));
|
FileSystem.deleteFile(Path.join([args.outputFolder, file]));
|
||||||
@@ -123,20 +125,40 @@ class CompilerTools {
|
|||||||
Prelude.assertProcess("haxelib", ["install", "--always", args.hxmlFile]);
|
Prelude.assertProcess("haxelib", ["install", "--always", args.hxmlFile]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO install language-specific dependencies from langProjectFile (which might be tricky because we can't set the working directory)
|
|
||||||
|
|
||||||
// Compile the script
|
// Compile the script
|
||||||
Prelude.assertProcess("haxe", ["--cwd", args.outputFolder].concat(hxmlFiles.map(Path.withoutDirectory)));
|
Prelude.assertProcess("haxe", ["--cwd", args.outputFolder].concat(hxmlFiles.map(Path.withoutDirectory)));
|
||||||
|
|
||||||
|
// TODO install language-specific dependencies from langProjectFile (which might be tricky because we can't set the working directory)
|
||||||
|
|
||||||
var command = "";
|
var command = "";
|
||||||
var scriptExt = "";
|
var scriptExt = "";
|
||||||
switch (lang) {
|
switch (lang) {
|
||||||
case JavaScript:
|
case JavaScript:
|
||||||
command = "node";
|
command = "node";
|
||||||
scriptExt = "js";
|
scriptExt = "js";
|
||||||
|
// npm install outputfolder
|
||||||
case Python:
|
case Python:
|
||||||
command = "python";
|
command = "python";
|
||||||
scriptExt = "py";
|
scriptExt = "py";
|
||||||
|
if (args.langProjectFile != null) {
|
||||||
|
trace(args.langProjectFile);
|
||||||
|
// Make a virtual environment
|
||||||
|
// NOTE this is placed outside the output folder, so it will get reused.
|
||||||
|
// In some cases this might be bad if the virtual environment gets bad
|
||||||
|
// versions of dependencies stuck in it
|
||||||
|
var envFolder = '${args.outputFolder}-env';
|
||||||
|
Prelude.assertProcess("python", ["-m", "venv", envFolder]);
|
||||||
|
var envPython = Path.join([envFolder, "Scripts", "python"]);
|
||||||
|
command = envPython;
|
||||||
|
switch (args.langProjectFile.extension()) {
|
||||||
|
case "txt":
|
||||||
|
// the requirements file's original path is fine for this case
|
||||||
|
Prelude.assertProcess(envPython, ["-m", "pip", "install", "-r", args.langProjectFile]);
|
||||||
|
case "py":
|
||||||
|
// python setup.py install
|
||||||
|
Prelude.assertProcess(envPython, [Path.join([args.outputFolder, args.langProjectFile.withoutDirectory()]), "install"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return an expression for a lambda that calls new Process() that runs the target-specific file
|
// return an expression for a lambda that calls new Process() that runs the target-specific file
|
||||||
|
@@ -15,6 +15,7 @@ class CompilerToolsTestCase extends Test {
|
|||||||
#if ((sys || hxnodejs) && !cs)
|
#if ((sys || hxnodejs) && !cs)
|
||||||
function testCompileHelloWorldJs() {
|
function testCompileHelloWorldJs() {
|
||||||
Assert.equals("Hello world!", _testCompileHelloWorldJs()());
|
Assert.equals("Hello world!", _testCompileHelloWorldJs()());
|
||||||
|
Assert.equals("Hello world!", _testCompileHelloWorldJsWithPackageJson()());
|
||||||
}
|
}
|
||||||
|
|
||||||
static macro function _testCompileHelloWorldJs() {
|
static macro function _testCompileHelloWorldJs() {
|
||||||
@@ -24,8 +25,18 @@ class CompilerToolsTestCase extends Test {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static macro function _testCompileHelloWorldJsWithPackageJson() {
|
||||||
|
return CompilerTools.compileFileToScript(
|
||||||
|
"kiss/template/src/template/Main.kiss", JavaScript, {
|
||||||
|
outputFolder: "bin/helloWorldJsTestWithPackageJson",
|
||||||
|
// langProjectFile: "kiss/src/test/files/package.json"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function testCompileHelloWorldPy() {
|
function testCompileHelloWorldPy() {
|
||||||
Assert.equals("Hello world!", _testCompileHelloWorldPy()());
|
Assert.equals("Hello world!", _testCompileHelloWorldPy()());
|
||||||
|
Assert.equals("Hello world!", _testCompileHelloWorldPyWithRequirementsTxt()());
|
||||||
|
Assert.equals("Hello world!", _testCompileHelloWorldPyWithSetupPy()());
|
||||||
}
|
}
|
||||||
|
|
||||||
static macro function _testCompileHelloWorldPy() {
|
static macro function _testCompileHelloWorldPy() {
|
||||||
@@ -35,6 +46,22 @@ class CompilerToolsTestCase extends Test {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static macro function _testCompileHelloWorldPyWithRequirementsTxt() {
|
||||||
|
return CompilerTools.compileFileToScript(
|
||||||
|
"kiss/template/src/template/Main.kiss", Python, {
|
||||||
|
outputFolder: "bin/helloWorldPyTestWithRequirementsTxt",
|
||||||
|
langProjectFile: "kiss/src/test/files/requirements.txt"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static macro function _testCompileHelloWorldPyWithSetupPy() {
|
||||||
|
return CompilerTools.compileFileToScript(
|
||||||
|
"kiss/template/src/template/Main.kiss", Python, {
|
||||||
|
outputFolder: "bin/helloWorldPyTestWithSetupPy",
|
||||||
|
langProjectFile: "kiss/src/test/files/setup.py"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// TODO test what happens when passing more arguments/files
|
// TODO test what happens when passing more arguments/files
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
1
kiss/src/test/files/requirements.txt
Normal file
1
kiss/src/test/files/requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
requests
|
12
kiss/src/test/files/setup.py
Normal file
12
kiss/src/test/files/setup.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from distutils.core import setup
|
||||||
|
|
||||||
|
setup(name='HelloWorld',
|
||||||
|
version='1.0',
|
||||||
|
description='HelloWorld python extern program',
|
||||||
|
author='Nat',
|
||||||
|
author_email='natquaylenelson@gmail.com',
|
||||||
|
url='https://github.com/NQNStudios/kisslang',
|
||||||
|
install_requires=[
|
||||||
|
'requests',
|
||||||
|
],
|
||||||
|
)
|
Reference in New Issue
Block a user