diff options
author | Florian Bruhin <me@the-compiler.org> | 2020-04-15 15:01:12 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2020-04-15 15:02:12 +0200 |
commit | a264c25314edb10d1506ee04654f2a0ef12d1d4b (patch) | |
tree | 6e280b7c15086e8e3290daef7fc9a5e808de3b82 | |
parent | d5c9c41019bfd0431c21c627f80976b55dc33192 (diff) | |
download | qutebrowser-a264c25314edb10d1506ee04654f2a0ef12d1d4b.tar.gz qutebrowser-a264c25314edb10d1506ee04654f2a0ef12d1d4b.zip |
scripts: Add some tooling to build/install PyQt wheels
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | scripts/dev/build_pyqt_wheel.py | 72 | ||||
-rw-r--r-- | scripts/mkvenv.py | 16 |
3 files changed, 88 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore index 6074de319..2f5c25116 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,4 @@ TODO /doc/extapi/_build /misc/nsis/include /misc/nsis/plugins +/wheels diff --git a/scripts/dev/build_pyqt_wheel.py b/scripts/dev/build_pyqt_wheel.py new file mode 100644 index 000000000..da0d32cbe --- /dev/null +++ b/scripts/dev/build_pyqt_wheel.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2020 Florian Bruhin (The Compiler) <mail@qutebrowser.org> +# +# This file is part of qutebrowser. +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>. + +"""Build updated PyQt wheels.""" + +import os +import subprocess +import argparse +import sys +import pathlib + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir, + os.pardir)) +from scripts import utils + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('qt_location', help='Qt compiler directory') + parser.add_argument('--wheels-dir', help='Directory to use for wheels') + args = parser.parse_args() + + old_cwd = pathlib.Path.cwd() + + wheels_dir = pathlib.Path(args.wheels_dir).resolve() + wheels_dir.mkdir(exist_ok=True) + + if list(wheels_dir.glob('*')): + utils.print_col("Wheels directory is not empty, " + "unexpected behavior might occur!", 'yellow') + + os.chdir(wheels_dir) + + utils.print_title("Downloading wheels") + subprocess.run([sys.executable, '-m', 'pip', 'download', + '--no-deps', '--only-binary', 'PyQt5,PyQtWebEngine', + 'PyQt5', 'PyQtWebEngine'], check=True) + + utils.print_title("Patching wheels") + input_files = wheels_dir.glob('*.whl') + for wheel in input_files: + utils.print_subtitle(wheel.stem.split('-')[0]) + bin_path = pathlib.Path(sys.executable).parent + subprocess.run([str(bin_path / 'pyqt-bundle'), + '--qt-dir', args.qt_location, wheel], + check=True) + wheel.unlink() + + print("Done, output files:") + for wheel in wheels_dir.glob('*.whl'): + print(wheel.relative_to(old_cwd)) + + +if __name__ == '__main__': + main() diff --git a/scripts/mkvenv.py b/scripts/mkvenv.py index 6dc52b82e..c01052b64 100644 --- a/scripts/mkvenv.py +++ b/scripts/mkvenv.py @@ -52,9 +52,12 @@ def parse_args() -> argparse.Namespace: default='auto', help="PyQt version to install.") parser.add_argument('--pyqt-type', - choices=['binary', 'source', 'link', 'skip'], + choices=['binary', 'source', 'link', 'wheels', 'skip'], default='binary', help="How to install PyQt/Qt.") + parser.add_argument('--pyqt-wheels-dir', + default='wheels', + help="Directory to get PyQt wheels from.") parser.add_argument('--virtualenv', action='store_true', help="Use virtualenv instead of venv.") @@ -207,6 +210,14 @@ def install_pyqt_link(venv_dir: pathlib.Path) -> None: link_pyqt.link_pyqt(sys.executable, lib_path) +def install_pyqt_wheels(venv_dir: pathlib.Path, + wheels_dir: pathlib.Path) -> None: + """Install PyQt from the wheels/ directory.""" + utils.print_title("Installing PyQt wheels") + wheels = [str(wheel) for wheel in wheels_dir.glob('*.whl')] + pip_install(venv_dir, *wheels) + + def install_requirements(venv_dir: pathlib.Path) -> None: """Install qutebrowser's requirement.txt.""" utils.print_title("Installing other qutebrowser dependencies") @@ -247,6 +258,7 @@ def main() -> None: """Install qutebrowser in a virtualenv..""" args = parse_args() venv_dir = pathlib.Path(args.venv_dir) + wheels_dir = pathlib.Path(args.pyqt_wheels_dir) utils.change_cwd() if args.tox_error: @@ -270,6 +282,8 @@ def main() -> None: install_pyqt_source(venv_dir, args.pyqt_version) elif args.pyqt_type == 'link': install_pyqt_link(venv_dir) + elif args.pyqt_type == 'wheels': + install_pyqt_wheels(venv_dir, wheels_dir) elif args.pyqt_type == 'skip': pass else: |