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.
This commit is contained in:
Damien Elmes 2021-10-16 18:03:41 +10:00
parent 424bb5bc68
commit e58646909f
6 changed files with 22 additions and 40 deletions

View File

@ -11,10 +11,10 @@ so it installs the command line tools.
Install Homebrew from <https://brew.sh/>
Then install deps:
Then install Bazel:
```
$ brew install rsync bazelisk
$ brew install bazelisk
```
**Python**:

View File

@ -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):

View File

@ -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

View File

@ -10,6 +10,7 @@ try:
bazelfixes.fix_pywin32_in_bazel()
bazelfixes.fix_extraneous_path_in_bazel()
bazelfixes.fix_run_on_macos()
except ImportError:
pass

20
run
View File

@ -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 -- $*

20
run-qt5
View File

@ -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 -- $*