improve python and meson

pull/18/head
ruki 6 years ago
parent 823df8bd6b
commit 4e3ee5bc02
No known key found for this signature in database
GPG Key ID: 33341DF9719963FA
  1. 2
      packages/m/meson/xmake.lua
  2. 102
      packages/p/python/xmake.lua
  3. 53
      packages/p/python2/xmake.lua

@ -10,7 +10,7 @@ package("meson")
add_deps("ninja", "python 3.x")
on_install("@macosx", "@linux", function (package)
on_install("@macosx", "@linux", "@windows", function (package)
local version = package:dep("python"):version()
local envs = {PYTHONPATH = package:installdir("lib", "python" .. version:major() .. "." .. version:minor(), "site-packages")}
os.vrunv("python3", {"setup.py", "install", "--prefix=" .. package:installdir()}, {envs = envs})

@ -39,23 +39,62 @@ package("python")
if is_host("macosx", "linux") then
add_deps("openssl")
end
on_load(function (package)
if is_host("windows") then
package:addenv("PATH", path.join("share", package:name(), package:version_str()))
else
package:addenv("PATH", path.join("share", package:name(), package:version_str(), "bin"))
end
package:data_set("install_resources", function()
-- imports
import("net.http")
import("utils.archive")
import("lib.detect.find_file")
-- set python environments
local version = package:version()
local envs = {PYTHONPATH = package:installdir("lib", "python" .. version:major() .. "." .. version:minor(), "site-packages")}
package:addenv("PYTHONPATH", envs.PYTHONPATH)
-- install resources
local resources =
{
setuptools =
{
url = "https://files.pythonhosted.org/packages/c2/f7/c7b501b783e5a74cf1768bc174ee4fb0a8a6ee5af6afa92274ff964703e0/setuptools-40.8.0.zip",
sha256 = "6e4eec90337e849ade7103723b9a99631c1f0d19990d6e8412dc42f5ae8b304d"
},
pip =
{
url = "https://files.pythonhosted.org/packages/36/fa/51ca4d57392e2f69397cd6e5af23da2a8d37884a605f9e3f2d3bfdc48397/pip-19.0.3.tar.gz",
sha256 = "6e6f197a1abfb45118dbb878b5c859a0edbdd33fd250100bc015b67fded4b9f2"
},
wheel =
{
url = "https://files.pythonhosted.org/packages/b7/cf/1ea0f5b3ce55cacde1e84cdde6cee1ebaff51bd9a3e6c7ba4082199af6f6/wheel-0.33.1.tar.gz",
sha256 = "66a8fd76f28977bb664b098372daef2b27f60dc4d1688cfab7b37a09448f0e9d"
}
}
local python = path.join(package:installdir("bin"), "python" .. (is_host("windows") and ".exe" or ""))
for name, resource in pairs(resources) do
local resourcefile = path.join(os.curdir(), path.filename(resource.url))
local resourcedir = resourcefile .. ".dir"
http.download(resource.url, resourcefile)
assert(resource.sha256 == hash.sha256(resourcefile), "resource(%s): unmatched checksum!", name)
assert(archive.extract(resourcefile, resourcedir), "resource(%s): extract failed!", name)
local setupfile = assert(find_file("setup.py", path.join(resourcedir, "*")), "resource(%s): setup.py not found!", name)
local oldir = os.cd(path.directory(setupfile))
os.vrunv(python, {"setup.py", "install", "--prefix=" .. package:installdir()}, {envs = envs})
os.cd(oldir)
end
end)
end)
on_install("@windows", function (package)
local installdir = package:installdir("share", package:name(), package:version_str())
os.cp("*", installdir)
os.cp("*", package:installdir())
if package:version():ge("3.0") then
os.cp("python.exe", path.join(installdir, "python3.exe"))
os.cp("python.exe", path.join(package:installdir("bin"), "python3.exe"))
else
os.cp("python.exe", path.join(installdir, "python2.exe"))
os.cp("python.exe", path.join(package:installdir("bin"), "python2.exe"))
end
package:data("install_resources")()
end)
on_install("@macosx", "@linux", function (package)
@ -82,50 +121,15 @@ package("python")
-- and not into some other Python the user has installed.
import("package.tools.autoconf").configure(package, configs, {envs = {PYTHONHOME = "", PYTHONPATH = ""}})
os.vrunv("make", {"install", "-j4", "PYTHONAPPSDIR=" .. package:installdir()})
-- set python environments
local version = package:version()
local envs = {PYTHONPATH = package:installdir("lib", "python" .. version:major() .. "." .. version:minor(), "site-packages")}
package:addenv("PYTHONPATH", envs.PYTHONPATH)
-- install resources
local resources =
{
setuptools =
{
url = "https://files.pythonhosted.org/packages/c2/f7/c7b501b783e5a74cf1768bc174ee4fb0a8a6ee5af6afa92274ff964703e0/setuptools-40.8.0.zip",
sha256 = "6e4eec90337e849ade7103723b9a99631c1f0d19990d6e8412dc42f5ae8b304d"
},
pip =
{
url = "https://files.pythonhosted.org/packages/36/fa/51ca4d57392e2f69397cd6e5af23da2a8d37884a605f9e3f2d3bfdc48397/pip-19.0.3.tar.gz",
sha256 = "6e6f197a1abfb45118dbb878b5c859a0edbdd33fd250100bc015b67fded4b9f2"
},
wheel =
{
url = "https://files.pythonhosted.org/packages/b7/cf/1ea0f5b3ce55cacde1e84cdde6cee1ebaff51bd9a3e6c7ba4082199af6f6/wheel-0.33.1.tar.gz",
sha256 = "66a8fd76f28977bb664b098372daef2b27f60dc4d1688cfab7b37a09448f0e9d"
}
}
import("net.http")
import("utils.archive")
import("lib.detect.find_file")
for name, resource in pairs(resources) do
local resourcefile = path.join(os.curdir(), path.filename(resource.url))
local resourcedir = resourcefile .. ".dir"
http.download(resource.url, resourcefile)
assert(resource.sha256 == hash.sha256(resourcefile), "resource(%s): unmatched checksum!", name)
assert(archive.extract(resourcefile, resourcedir), "resource(%s): extract failed!", name)
local setupfile = assert(find_file("setup.py", path.join(resourcedir, "*")), "resource(%s): setup.py not found!", name)
local oldir = os.cd(path.directory(setupfile))
os.vrunv("python", {"setup.py", "install", "--prefix=" .. package:installdir()}, {envs = envs})
os.cd(oldir)
if package:version():ge("3.0") then
os.cp(path.join(package:installdir("bin"), "python3"), path.join(package:installdir("bin"), "python"))
os.cp(path.join(package:installdir("bin"), "python3-config"), path.join(package:installdir("bin"), "python-config"))
end
package:data("install_resources")()
end)
on_test(function (package)
os.vrun("python --version")
os.vrun("python -c \"import ssl\"")
os.vrun("python -c \"import pip\"")
os.vrun("python -c \"import setuptools\"")
os.vrun("python -c \"import wheel\"")

@ -22,31 +22,7 @@ package("python2")
add_deps("openssl")
end
local resources =
{
setuptools =
{
url = "https://files.pythonhosted.org/packages/c2/f7/c7b501b783e5a74cf1768bc174ee4fb0a8a6ee5af6afa92274ff964703e0/setuptools-40.8.0.zip",
sha256 = "6e4eec90337e849ade7103723b9a99631c1f0d19990d6e8412dc42f5ae8b304d"
},
pip =
{
url = "https://files.pythonhosted.org/packages/36/fa/51ca4d57392e2f69397cd6e5af23da2a8d37884a605f9e3f2d3bfdc48397/pip-19.0.3.tar.gz",
sha256 = "6e6f197a1abfb45118dbb878b5c859a0edbdd33fd250100bc015b67fded4b9f2"
},
wheel =
{
url = "https://files.pythonhosted.org/packages/b7/cf/1ea0f5b3ce55cacde1e84cdde6cee1ebaff51bd9a3e6c7ba4082199af6f6/wheel-0.33.1.tar.gz",
sha256 = "66a8fd76f28977bb664b098372daef2b27f60dc4d1688cfab7b37a09448f0e9d"
}
}
on_load(function (package)
if is_host("windows") then
package:addenv("PATH", path.join("share", package:name(), package:version_str()))
else
package:addenv("PATH", path.join("share", package:name(), package:version_str(), "bin"))
end
package:data_set("install_resources", function()
-- imports
@ -60,6 +36,25 @@ package("python2")
package:addenv("PYTHONPATH", envs.PYTHONPATH)
-- install resources
local resources =
{
setuptools =
{
url = "https://files.pythonhosted.org/packages/c2/f7/c7b501b783e5a74cf1768bc174ee4fb0a8a6ee5af6afa92274ff964703e0/setuptools-40.8.0.zip",
sha256 = "6e4eec90337e849ade7103723b9a99631c1f0d19990d6e8412dc42f5ae8b304d"
},
pip =
{
url = "https://files.pythonhosted.org/packages/36/fa/51ca4d57392e2f69397cd6e5af23da2a8d37884a605f9e3f2d3bfdc48397/pip-19.0.3.tar.gz",
sha256 = "6e6f197a1abfb45118dbb878b5c859a0edbdd33fd250100bc015b67fded4b9f2"
},
wheel =
{
url = "https://files.pythonhosted.org/packages/b7/cf/1ea0f5b3ce55cacde1e84cdde6cee1ebaff51bd9a3e6c7ba4082199af6f6/wheel-0.33.1.tar.gz",
sha256 = "66a8fd76f28977bb664b098372daef2b27f60dc4d1688cfab7b37a09448f0e9d"
}
}
local python = path.join(package:installdir("bin"), "python" .. (is_host("windows") and ".exe" or ""))
for name, resource in pairs(resources) do
local resourcefile = path.join(os.curdir(), path.filename(resource.url))
local resourcedir = resourcefile .. ".dir"
@ -68,18 +63,15 @@ package("python2")
assert(archive.extract(resourcefile, resourcedir), "resource(%s): extract failed!", name)
local setupfile = assert(find_file("setup.py", path.join(resourcedir, "*")), "resource(%s): setup.py not found!", name)
local oldir = os.cd(path.directory(setupfile))
os.vrunv("python2", {"setup.py", "install", "--prefix=" .. package:installdir()}, {envs = envs})
os.vrunv(python, {"setup.py", "install", "--prefix=" .. package:installdir()}, {envs = envs})
os.cd(oldir)
end
end)
end)
on_install("@windows", function (package)
-- install python
local installdir = package:installdir("share", package:name(), package:version_str())
os.cp("*", installdir)
os.cp("python.exe", path.join(installdir, "python2.exe"))
os.cp("*", package:installdir())
os.cp("python.exe", path.join(package:installdir("bin"), "python2.exe"))
package:data("install_resources")()
end)
@ -107,7 +99,6 @@ package("python2")
on_test(function (package)
os.vrun("python2 --version")
os.vrun("python2 -c \"import ssl\"")
os.vrun("python2 -c \"import pip\"")
os.vrun("python2 -c \"import setuptools\"")
os.vrun("python2 -c \"import wheel\"")

Loading…
Cancel
Save