Python.hx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package runci.targets;
  2. import sys.FileSystem;
  3. import runci.System.*;
  4. import runci.Config.*;
  5. class Python {
  6. static public function getPythonDependencies():Array<String> {
  7. switch (systemName) {
  8. case "Linux":
  9. if (commandSucceed("python3", ["-V"]))
  10. infoMsg('python3 has already been installed.');
  11. else
  12. Linux.requireAptPackages(["python3"]);
  13. runCommand("python3", ["-V"]);
  14. var pypy = "pypy3";
  15. if (commandSucceed(pypy, ["-V"])) {
  16. infoMsg('pypy3 has already been installed.');
  17. } else {
  18. final pypyVersion = "pypy3.8-v7.3.7-" + (switch Linux.arch {
  19. case Arm64: "aarch64";
  20. case Amd64: "linux64";
  21. });
  22. final file = '${pypyVersion}.tar.bz2';
  23. if(!FileSystem.exists(file)) {
  24. runNetworkCommand("wget", ["-nv", 'https://downloads.python.org/pypy/$file']);
  25. }
  26. runCommand("tar", ["-xf", file]);
  27. pypy = FileSystem.fullPath('${pypyVersion}/bin/pypy3');
  28. }
  29. runCommand(pypy, ["-V"]);
  30. return ["python3", pypy];
  31. case "Mac":
  32. if (commandSucceed("python3", ["-V"]))
  33. infoMsg('python3 has already been installed.');
  34. else
  35. runNetworkCommand("brew", ["install", "python3"]);
  36. runCommand("python3", ["-V"]);
  37. if (commandSucceed("pypy3", ["-V"]))
  38. infoMsg('pypy3 has already been installed.');
  39. else
  40. runNetworkCommand("brew", ["install", "pypy3"]);
  41. runCommand("pypy3", ["-V"]);
  42. return ["python3", "pypy3"];
  43. case "Windows":
  44. if (commandSucceed("python3", ["-V"]))
  45. infoMsg('python3 has already been installed.');
  46. else
  47. throw "please install python 3.x and make it available as python3 in PATH";
  48. runCommand("python3", ["-V"]);
  49. return ["python3"];
  50. }
  51. return [];
  52. }
  53. static public function run(args:Array<String>) {
  54. final pys = getPythonDependencies();
  55. runCommand("haxe", ["compile-python.hxml"].concat(args));
  56. for (py in pys) {
  57. runCommand(py, ["bin/unit.py"]);
  58. // Additional test for python-version >= 3.4
  59. runCommand(py, ["bin/unit34.py"]);
  60. }
  61. changeDirectory(sysDir);
  62. runCommand("haxe", ["compile-python.hxml"].concat(args));
  63. for (py in pys) {
  64. runSysTest(py, ["bin/python/sys.py"]);
  65. }
  66. changeDirectory(getMiscSubDir("python"));
  67. runCommand("haxe", ["run.hxml"]);
  68. changeDirectory(getMiscSubDir('python', "pythonImport"));
  69. runCommand("haxe", ["compile.hxml"]);
  70. for (py in pys) {
  71. runCommand(py, ["test.py"]);
  72. }
  73. changeDirectory(threadsDir);
  74. runCommand("haxe", ["build.hxml", "--python", "export/threads.py"].concat(args));
  75. for (py in pys) {
  76. runCommand(py, ["export/threads.py"]);
  77. }
  78. }
  79. }