Initial Poetry infrastructure
This commit is contained in:
parent
c41b92e45f
commit
c277d9f121
|
@ -0,0 +1,98 @@
|
|||
import os
|
||||
import platform
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import sysconfig
|
||||
from distutils.version import LooseVersion
|
||||
from typing import Any, Dict
|
||||
|
||||
from setuptools.command.build_ext import build_ext
|
||||
from setuptools.extension import Extension
|
||||
|
||||
|
||||
class CMakeExtension(Extension):
|
||||
name: str # exists, even though IDE doesn't find it
|
||||
|
||||
def __init__(self, name: str, sourcedir: str="") -> None:
|
||||
super().__init__(name, sources=[])
|
||||
self.sourcedir = os.path.abspath(sourcedir)
|
||||
self.sourcedir_rel = sourcedir
|
||||
|
||||
|
||||
class ExtensionBuilder(build_ext):
|
||||
def run(self) -> None:
|
||||
self.validate_cmake()
|
||||
super().run()
|
||||
|
||||
def build_extension(self, ext: Extension) -> None:
|
||||
if isinstance(ext, CMakeExtension):
|
||||
self.build_cmake_extension(ext)
|
||||
else:
|
||||
super().build_extension(ext)
|
||||
|
||||
def validate_cmake(self) -> None:
|
||||
cmake_extensions = [x for x in self.extensions if isinstance(x, CMakeExtension)]
|
||||
if len(cmake_extensions) > 0:
|
||||
try:
|
||||
out = subprocess.check_output(["cmake", "--version"])
|
||||
except OSError:
|
||||
raise RuntimeErrorPython_CORIOLISDIR(
|
||||
"CMake must be installed to build the following extensions: "
|
||||
+ ", ".join(e.name for e in cmake_extensions)
|
||||
)
|
||||
if platform.system() == "Windows":
|
||||
cmake_version = LooseVersion(re.search(r"version\s*([\d.]+)", out.decode()).group(1)) # type: ignore
|
||||
if cmake_version < "3.1.0":
|
||||
raise RuntimeError("CMake >= 3.1.0 is required on Windows")
|
||||
|
||||
def build_cmake_extension(self, ext: CMakeExtension) -> None:
|
||||
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
|
||||
cmake_args = ["-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + extdir, "-DPYTHON_EXECUTABLE=" + sys.executable]
|
||||
|
||||
cfg = "Debug" if self.debug else "Release"
|
||||
# cfg = 'Debug'
|
||||
build_args = ["--config", cfg]
|
||||
install_args = ["--config", cfg]
|
||||
|
||||
if platform.system() == "Windows":
|
||||
cmake_args += ["-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}".format(cfg.upper(), extdir)]
|
||||
if sys.maxsize > 2 ** 32:
|
||||
cmake_args += ["-A", "x64"]
|
||||
build_args += ["--", "/m"]
|
||||
else:
|
||||
cmake_args += ["-DCMAKE_BUILD_TYPE=" + cfg]
|
||||
build_args += ["--", "-j4", "VERBOSE=1"]
|
||||
cmake_args += ["-DPYTHON_INCLUDE_DIR={}".format(sysconfig.get_path("include"))]
|
||||
|
||||
env = os.environ.copy()
|
||||
env["CXXFLAGS"] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get("CXXFLAGS", ""), self.distribution.get_version())
|
||||
|
||||
build_dir = os.path.join(self.build_temp, ext.sourcedir_rel)
|
||||
install_dir = os.path.join(self.build_temp, "install")
|
||||
os.makedirs(build_dir,exist_ok=True)
|
||||
os.makedirs(os.path.join(install_dir, cfg), exist_ok=True)
|
||||
|
||||
cmake_args += [f"-DCMAKE_MODULE_PATH={os.path.abspath('bootstrap/cmake_modules')};"
|
||||
f"{os.path.join(install_dir, 'share/cmake/Modules')}"]
|
||||
cmake_args += [f"-DCMAKE_INSTALL_PREFIX={install_dir}"]
|
||||
cmake_args += [f"-DPython_CORIOLISLIB={extdir}"]
|
||||
cmake_args += [f"-DPython_CORIOLISARCH={extdir}"]
|
||||
|
||||
|
||||
subprocess.check_call(["cmake", "--debug-find", "--trace-redirect=build.cmake.trace", "--trace-expand", ext.sourcedir] + cmake_args, cwd=build_dir, env=env)
|
||||
subprocess.check_call(["cmake", "--build", "."] + build_args, cwd=build_dir)
|
||||
subprocess.check_call(["cmake", "--install", ".", "--prefix", install_dir] + install_args, cwd=build_dir)
|
||||
|
||||
|
||||
def build(setup_kwargs: Dict[str, Any]) -> None:
|
||||
cmake_modules = [CMakeExtension("coriolis.hurricane", sourcedir="coriolis/hurricane"),
|
||||
CMakeExtension("coriolis.crlcore", sourcedir="coriolis/crlcore")]
|
||||
ext_modules = cmake_modules
|
||||
setup_kwargs.update(
|
||||
{
|
||||
"ext_modules": ext_modules,
|
||||
"cmdclass": dict(build_ext=ExtensionBuilder),
|
||||
"zip_safe": False,
|
||||
}
|
||||
)
|
|
@ -0,0 +1,64 @@
|
|||
[[package]]
|
||||
name = "cmake"
|
||||
version = "3.25.0"
|
||||
description = "CMake is an open-source, cross-platform family of tools designed to build, test and package software"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
|
||||
[package.extras]
|
||||
test = ["codecov (>=2.0.5)", "coverage (>=4.2)", "flake8 (>=3.0.4)", "path.py (>=11.5.0)", "pytest (>=3.0.3)", "pytest-cov (>=2.4.0)", "pytest-runner (>=2.9)", "pytest-virtualenv (>=1.7.0)", "scikit-build (>=0.10.0)", "setuptools (>=28.0.0)", "virtualenv (>=15.0.3)", "wheel"]
|
||||
|
||||
[[package]]
|
||||
name = "ninja"
|
||||
version = "1.11.1"
|
||||
description = "Ninja is a small build system with a focus on speed"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
|
||||
[package.extras]
|
||||
test = ["codecov (>=2.0.5)", "coverage (>=4.2)", "flake8 (>=3.0.4)", "pytest (>=4.5.0)", "pytest-cov (>=2.7.1)", "pytest-runner (>=5.1)", "pytest-virtualenv (>=1.7.0)", "virtualenv (>=15.0.3)"]
|
||||
|
||||
[metadata]
|
||||
lock-version = "1.1"
|
||||
python-versions = "^3.9"
|
||||
content-hash = "d16f582433e9abd89fc7975a1aed410d63635e101eb4544194039e6e287755e8"
|
||||
|
||||
[metadata.files]
|
||||
cmake = [
|
||||
{file = "cmake-3.25.0-py2.py3-none-macosx_10_10_universal2.macosx_10_10_x86_64.macosx_11_0_arm64.macosx_11_0_universal2.whl", hash = "sha256:e90a7a68384b25a05aab0f013cea76b69f00add2592393b0ff71e99c773db017"},
|
||||
{file = "cmake-3.25.0-py2.py3-none-manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:442e311c072ebfb42c42af829bc9394be3fe2bee65460ac7208128bfb867fd5b"},
|
||||
{file = "cmake-3.25.0-py2.py3-none-manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:a8ec4cb981a761f8e45240a130309d967d4d27893b67b886f0b7a534df923894"},
|
||||
{file = "cmake-3.25.0-py2.py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b3776a15ecd7d29d85b27c0ce507ce2ddacca53984ba949580ee629c3e08f345"},
|
||||
{file = "cmake-3.25.0-py2.py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:aeffd7094c99c06f4e1fdeaec5e1ed7be288ad776399b4bc3e9873de51a30f68"},
|
||||
{file = "cmake-3.25.0-py2.py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:f07c237f5e1a97131ea1e531b6a2b37a8b7afc25bcee3fc4d90756672b51e4d7"},
|
||||
{file = "cmake-3.25.0-py2.py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:6bfa23225d81218cac09176da15a0a75ae64d9a4948ee06acd789d8f63cefb96"},
|
||||
{file = "cmake-3.25.0-py2.py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9b7fd744a90e4d804ff77ac50d3570009911fbfdad29c59fc93d2a82faaeb371"},
|
||||
{file = "cmake-3.25.0-py2.py3-none-musllinux_1_1_aarch64.whl", hash = "sha256:096fee057b846a697c78fa83f6ddc82104c3a08b6282de5036537cf1dd642b02"},
|
||||
{file = "cmake-3.25.0-py2.py3-none-musllinux_1_1_i686.whl", hash = "sha256:fdc49b15a478f6be70b7e29d5d03b8af1879810b64f5515bc232f08257aaad15"},
|
||||
{file = "cmake-3.25.0-py2.py3-none-musllinux_1_1_ppc64le.whl", hash = "sha256:d2b6d4fa47cfd286ba13d7890d403f1de7dddd3cd90555c14ca5e04872754ed1"},
|
||||
{file = "cmake-3.25.0-py2.py3-none-musllinux_1_1_s390x.whl", hash = "sha256:36e1ed23332bc04444bcbfa06cfed0f03b3f02126691541cccf1720bc2007850"},
|
||||
{file = "cmake-3.25.0-py2.py3-none-musllinux_1_1_x86_64.whl", hash = "sha256:94b4e9dfccd37dc16cefb37f828766fe3a28a463190215aaa87e5600b4812b98"},
|
||||
{file = "cmake-3.25.0-py2.py3-none-win32.whl", hash = "sha256:7548a3354d37f3c9f56b5b6fd0347a0f8e916d224b93b4e7aa0640a9e6e96f71"},
|
||||
{file = "cmake-3.25.0-py2.py3-none-win_amd64.whl", hash = "sha256:849f3760576810aee84108b3110a7e083c9fdc72fde26401c4ff4c340a2232c7"},
|
||||
{file = "cmake-3.25.0.tar.gz", hash = "sha256:d1658afd3362273782f57697f2fc4637fda1f5798ac64e0f3418a8ba5f6e790f"},
|
||||
]
|
||||
ninja = [
|
||||
{file = "ninja-1.11.1-py2.py3-none-macosx_10_9_universal2.macosx_10_9_x86_64.macosx_11_0_arm64.macosx_11_0_universal2.whl", hash = "sha256:f48c3c6eea204062f6bbf089dfc63e1ad41a08640e1da46ef2b30fa426f7ce23"},
|
||||
{file = "ninja-1.11.1-py2.py3-none-manylinux_2_12_i686.manylinux2010_i686.whl", hash = "sha256:edec1053e141253076b2df7ec03a246ff581e9270aa1ca9759397b21e2760e57"},
|
||||
{file = "ninja-1.11.1-py2.py3-none-manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:817e2aee2a4d28a708a67bcfba1817ae502c32c6d8ef80e50d63b0f23adf3a08"},
|
||||
{file = "ninja-1.11.1-py2.py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:df11b8afea0501883e33faeb1c43d2ef67f466d5f4bd85f9c376e9a93a43a277"},
|
||||
{file = "ninja-1.11.1-py2.py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:a7a564fe755ddfbdbccb07b0b758e3f8460e5f8ba1adaab40a5eaa2f8c01ce68"},
|
||||
{file = "ninja-1.11.1-py2.py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:1c474326e11fba3f8c2582715d79216292e327d3335367c0e87e9647a002cc4a"},
|
||||
{file = "ninja-1.11.1-py2.py3-none-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:6f6465a7efe6473a2a34edab83633594de19d59406a727316e1367ebcc528908"},
|
||||
{file = "ninja-1.11.1-py2.py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:642cb64d859276998f14972724850e0c5b7febbc1bce3d2065b7e0cb7d3a0b79"},
|
||||
{file = "ninja-1.11.1-py2.py3-none-musllinux_1_1_aarch64.whl", hash = "sha256:60179bb4f22c88279c53a5402bb5fe81c97c627a28d93c737d1fa067d892115d"},
|
||||
{file = "ninja-1.11.1-py2.py3-none-musllinux_1_1_i686.whl", hash = "sha256:34753459493543782d87267e4cad63dd4639b07f8394ffe6d4417e9eda05c8a8"},
|
||||
{file = "ninja-1.11.1-py2.py3-none-musllinux_1_1_ppc64le.whl", hash = "sha256:779f228e407c54a8b6e4cbf8f835489998dd250f67bf1b9bd7b8a8ab6bdcdc7b"},
|
||||
{file = "ninja-1.11.1-py2.py3-none-musllinux_1_1_s390x.whl", hash = "sha256:ba50a32424912e5f3ee40d791b506a160dc0eeda7de5ad8faebe7aa8006244dc"},
|
||||
{file = "ninja-1.11.1-py2.py3-none-musllinux_1_1_x86_64.whl", hash = "sha256:3b28b595ed580752240ade7821b6cb7a5a4c6a604c865dc474bd38f06e2eb7f5"},
|
||||
{file = "ninja-1.11.1-py2.py3-none-win32.whl", hash = "sha256:3329b4b7c1694730772522a3ba0ba40fd15c012476ed3e1c9f0fd9e76190394e"},
|
||||
{file = "ninja-1.11.1-py2.py3-none-win_amd64.whl", hash = "sha256:4e547bc759c570773d83d110c41fd5ca9a94c0a9a8388f5a3ea37bdf97d002b0"},
|
||||
{file = "ninja-1.11.1.tar.gz", hash = "sha256:c833a47d39b2d1eee3f9ca886fa1581efd5be6068b82734ac229961ee8748f90"},
|
||||
]
|
|
@ -0,0 +1,20 @@
|
|||
[tool.poetry]
|
||||
name = "coriolis"
|
||||
version = "0.1.0"
|
||||
description = "Place and Route for semiconductors"
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
build = "build.py"
|
||||
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.9"
|
||||
PySide2 = "^5.0"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
ninja = ">=1.10"
|
||||
cmake = ">=3"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core", "setuptools", "cmake"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
Loading…
Reference in New Issue