From fe78bcd0034f325368d9ac5d74948bf219b4d8b8 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Wed, 27 Oct 2021 19:31:50 +0200 Subject: [PATCH 1/2] Add setup.py --- .gitignore | 3 ++ MANIFEST.in | 4 +++ QTermWidget/__init__.py | 1 + setup.py | 63 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 MANIFEST.in create mode 100644 QTermWidget/__init__.py create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 9e0d4235..3172f358 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ build .kdev4 +dist +QTermWidget.egg-info +__pycache__ diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000..88df7076 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,4 @@ +recursive-include lib * +recursive-include pyqt * +recursive-include cmake * +include CMakeLists.txt \ No newline at end of file diff --git a/QTermWidget/__init__.py b/QTermWidget/__init__.py new file mode 100644 index 00000000..1122b356 --- /dev/null +++ b/QTermWidget/__init__.py @@ -0,0 +1 @@ +from .QTermWidget import QTermWidget \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..0fb4240d --- /dev/null +++ b/setup.py @@ -0,0 +1,63 @@ +from setuptools.command.build_ext import build_ext as build_ext_orig +from setuptools import setup, Extension +import pathlib +import os + + +class CMakeExtension(Extension): + + def __init__(self, name): + # don't invoke the original build_ext for this special extension + super().__init__(name, sources=[]) + + +class build_ext(build_ext_orig): + + def run(self): + for ext in self.extensions: + self.build_cmake(ext) + super().run() + + def build_cmake(self, ext): + cwd = pathlib.Path().absolute() + + # these dirs will be created in build_py, so if you don't have + # any python sources to bundle, the dirs will be missing + build_temp = pathlib.Path(self.build_temp) + build_temp.mkdir(parents=True, exist_ok=True) + extdir = pathlib.Path(self.get_ext_fullpath(ext.name)) + extdir.mkdir(parents=True, exist_ok=True) + + # example of cmake args + config = "Debug" if self.debug else "Release" + cmake_args = [ + "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + str(extdir.parent.absolute()), + "-DCMAKE_BUILD_TYPE=" + config, + "-D", + "QTERMWIDGET_BUILD_PYTHON_BINDING=ON" + ] + + # example of build args + build_args = [ + "--config", config, + "--", "-j4" + ] + + os.chdir(str(build_temp)) + self.spawn(["cmake", str(cwd)] + cmake_args) + if not self.dry_run: + self.spawn(["cmake", "--build", "."] + build_args) + # Troubleshooting: if fail on line above then delete all possible + # temporary CMake files including "CMakeCache.txt" in top level dir. + os.chdir(str(cwd)) + + +setup( + name="QTermWidget", + version='0.1', + packages=["QTermWidget"], + ext_modules=[CMakeExtension("QTermWidget/*")], + cmdclass={ + "build_ext": build_ext, + } +) From d5da3191bf8be246a30ea1aef9b736f99bbffe69 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Tue, 2 Nov 2021 17:50:57 +0100 Subject: [PATCH 2/2] Include data files --- MANIFEST.in | 3 ++- setup.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 88df7076..d06acb2b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,5 @@ recursive-include lib * recursive-include pyqt * recursive-include cmake * -include CMakeLists.txt \ No newline at end of file +include CMakeLists.txt +include README.md diff --git a/setup.py b/setup.py index 0fb4240d..0eb2970e 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,35 @@ from setuptools.command.build_ext import build_ext as build_ext_orig from setuptools import setup, Extension +import subprocess +import tempfile +import platform import pathlib +import shutil +import glob +import sys import os +if platform.system() == "Windows": + print("Windows is not supportet", file=sys.stderr) + sys.exit(1) + + +with open("README.md", "r", encoding="utf-8") as f: + description = f.read() + + +build_dir = tempfile.mkdtemp() + + +def prepare_build(): + shutil.copy("QTermWidget/__init__.py", os.path.join(build_dir, "__init__.py")) + shutil.copytree("lib/color-schemes", os.path.join(build_dir, "color-schemes")) + shutil.copytree("lib/kb-layouts", os.path.join(build_dir, "kb-layouts")) + shutil.copytree("lib/translations", os.path.join(build_dir, "translations")) + subprocess.run(["lrelease"] + glob.glob(os.path.join(build_dir, "translations", "*.ts"))) + + class CMakeExtension(Extension): def __init__(self, name): @@ -52,12 +78,50 @@ def build_cmake(self, ext): os.chdir(str(cwd)) +prepare_build() + setup( name="QTermWidget", version='0.1', + description=" The terminal widget for QTerminal", + long_description=description, + long_description_content_type="text/markdown", + url="https://github.com/lxqt/qtermwidget", + python_requires=">=3.7", + install_requires=["PyQt5"], packages=["QTermWidget"], ext_modules=[CMakeExtension("QTermWidget/*")], cmdclass={ "build_ext": build_ext, - } + }, + package_dir={"QTermWidget": build_dir}, + package_data={ + "QTermWidget": [ + "color-schemes/*", + "color-schemes/historic/*", + "kb-layouts/*", + "kb-layouts/historic/*", + "translations/*.qm" + ] + }, + classifiers=[ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "Environment :: Other Environment", + "Environment :: X11 Applications :: Qt", + "License :: OSI Approved :: BSD License", + "Operating System :: POSIX", + "Operating System :: POSIX :: BSD", + "Operating System :: POSIX :: Linux", + "Operating System :: MacOS :: MacOS X", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: Implementation :: CPython" + ] ) + +shutil.rmtree(build_dir)