summaryrefslogtreecommitdiff
path: root/lang/python37/files/python3.7.ucl.in
blob: a9ebb18f9c2772fa9b7a09e2f0ba17ece58bcf7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
path_glob: "%%PYTHON_SITELIBDIR%%/*"
trigger: {
	type: lua
	sandbox: false
	script: <<EOS
function cleanup(directory)
  for _,d in ipairs(pkg.readdir(directory)) do
    local full_path = directory .. "/" .. d
    local stat = pkg.stat(full_path)
    if stat["type"] == "dir" then
      if (d ~= "__pycache__") then
        cleanup(full_path)
      else
        for _,bytecode_file in ipairs(pkg.readdir(full_path)) do
          local file_origin = string.gsub(bytecode_file, "[.]cpython[-]%%PYTHON_SUFFIX%%[.].*pyc", ".py")
          if file_origin  then
            local origin_path = directory .. "/" .. file_origin
            if (not pkg.stat(origin_path)) then
              --print("  >=> removed stale bytecode " .. bytecode_file)
              os.remove(full_path .. "/" .. bytecode_file)
            end
          end
        end
      end
      local res = pkg.readdir(full_path)
      if #res == 0 then
        --print("  >=> removed empty directory " .. full_path )
        os.remove(full_path)
      end
    end
  end
end

print(">=> Cleaning stale bytecode files...")
cleanup("%%PYTHON_SITELIBDIR%%")

print(">=> Byte-compiling Python source files...")
pkg.exec({"%%PYTHON_VERSION%%", "-m", "compileall", "-q", "%%PYTHON_SITELIBDIR%%"})
pkg.exec({"%%PYTHON_VERSION%%", "-O", "-m", "compileall", "-q", "%%PYTHON_SITELIBDIR%%"})
pkg.exec({"%%PYTHON_VERSION%%", "-OO", "-m", "compileall", "-q", "%%PYTHON_SITELIBDIR%%"})
EOS
}