Python.hx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. Display.maybeRunDisplayTests(Python);
  62. changeDirectory(sysDir);
  63. runCommand("haxe", ["compile-python.hxml"].concat(args));
  64. for (py in pys) {
  65. runSysTest(py, ["bin/python/sys.py"]);
  66. }
  67. changeDirectory(getMiscSubDir("python"));
  68. runCommand("haxe", ["run.hxml"]);
  69. changeDirectory(getMiscSubDir('python', "pythonImport"));
  70. runCommand("haxe", ["compile.hxml"]);
  71. for (py in pys) {
  72. runCommand(py, ["test.py"]);
  73. }
  74. changeDirectory(threadsDir);
  75. runCommand("haxe", ["build.hxml", "--python", "export/threads.py"].concat(args));
  76. for (py in pys) {
  77. runCommand(py, ["export/threads.py"]);
  78. }
  79. }
  80. }