From e58646909fe388b54090be46d144820da39e7f37 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 16 Oct 2021 18:03:41 +1000 Subject: [PATCH] get PyQt working directly with ./run on macOS It's no longer necessary to copy everything into bazel-copy, and you can safely remove that folder. --- docs/mac.md | 4 ++-- qt/aqt/utils.py | 3 +++ qt/bazelfixes.py | 14 ++++++++++++++ qt/runanki.py | 1 + run | 20 +------------------- run-qt5 | 20 +------------------- 6 files changed, 22 insertions(+), 40 deletions(-) diff --git a/docs/mac.md b/docs/mac.md index f28aa8b5a..0dd71e3fe 100644 --- a/docs/mac.md +++ b/docs/mac.md @@ -11,10 +11,10 @@ so it installs the command line tools. Install Homebrew from -Then install deps: +Then install Bazel: ``` -$ brew install rsync bazelisk +$ brew install bazelisk ``` **Python**: diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index 6deb98459..ab3163e9e 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -21,6 +21,9 @@ if TYPE_CHECKING: def aqt_data_folder() -> str: + # running in Bazel on macOS? + if path := os.getenv("AQT_DATA_FOLDER"): + return path # running in place? dir = os.path.join(os.path.dirname(__file__), "data") if os.path.exists(dir): diff --git a/qt/bazelfixes.py b/qt/bazelfixes.py index 6d0430abc..eb223b87f 100644 --- a/qt/bazelfixes.py +++ b/qt/bazelfixes.py @@ -43,3 +43,17 @@ def fix_extraneous_path_in_bazel(): # source folder conflicts with bazel-out source if sys.path[0].endswith("qt"): del sys.path[0] + + +def fix_run_on_macos(): + if not sys.platform.startswith("darwin"): + return + exec_folder = os.path.dirname(sys.argv[0]) + qt_version = 5 if "runanki_qt5" in exec_folder else 6 + pyqt_repo = os.path.join(exec_folder, f"../../../../../../../external/pyqt{qt_version}") + if os.path.exists(pyqt_repo): + # pyqt must point to real folder, not a symlink + sys.path.insert(0, pyqt_repo) + # set the correct data folder base + data = os.path.join(exec_folder, "aqt", "data") + os.environ["AQT_DATA_FOLDER"] = data diff --git a/qt/runanki.py b/qt/runanki.py index 6c79c8ff4..d0f3e0b6b 100644 --- a/qt/runanki.py +++ b/qt/runanki.py @@ -10,6 +10,7 @@ try: bazelfixes.fix_pywin32_in_bazel() bazelfixes.fix_extraneous_path_in_bazel() + bazelfixes.fix_run_on_macos() except ImportError: pass diff --git a/run b/run index 1c9be0bf5..022a72fe9 100755 --- a/run +++ b/run @@ -2,23 +2,5 @@ set -e -run_linux() { - bazel run $BUILDARGS //qt:runanki -- $* -} - -run_mac() { - # QtWebEngineProcess is unable to locate icudtl.dat from a symlinked tree, - # so we need to copy the files into a working folder before running on a Mac. - workspace=$(dirname $0) - bazel build $BUILDARGS //qt:runanki && \ - rsync -aiL --exclude=anki/external --delete -f'-p __pycache__' \ - $workspace/bazel-bin/qt/runanki* $workspace/bazel-copy/ && \ - $workspace/bazel-copy/runanki $* -} - export PYTHONWARNINGS=default -if [[ "$OSTYPE" == "darwin"* ]]; then - run_mac $* -else - run_linux $* -fi +bazel run $BUILDARGS //qt:runanki -- $* diff --git a/run-qt5 b/run-qt5 index 9fd6ef056..c7e9e5b37 100755 --- a/run-qt5 +++ b/run-qt5 @@ -2,23 +2,5 @@ set -e -run_linux() { - bazel run $BUILDARGS //qt:runanki_qt5 -- $* -} - -run_mac() { - # QtWebEngineProcess is unable to locate icudtl.dat from a symlinked tree, - # so we need to copy the files into a working folder before running on a Mac. - workspace=$(dirname $0) - bazel build $BUILDARGS //qt:runanki_qt5 && \ - rsync -aiL --exclude=anki/external --delete -f'-p __pycache__' \ - $workspace/bazel-bin/qt/runanki* $workspace/bazel-copy/ && \ - $workspace/bazel-copy/runanki_qt5 $* -} - export PYTHONWARNINGS=default -if [[ "$OSTYPE" == "darwin"* ]]; then - run_mac $* -else - run_linux $* -fi +bazel run $BUILDARGS //qt:runanki_qt5 -- $*