mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 07:22:23 -04:00
fix pywintypes issue when running tests on Windows
This commit is contained in:
parent
69bdd73de5
commit
4de71eb662
4 changed files with 56 additions and 39 deletions
|
@ -26,10 +26,11 @@ py_binary(
|
|||
|
||||
py_test(
|
||||
name = "pytest",
|
||||
srcs = glob(["tests/*.py"]),
|
||||
srcs = glob(["tests/*.py"]) + ["bazelfixes.py"],
|
||||
data = [
|
||||
"//qt/aqt_data",
|
||||
],
|
||||
imports = ["."],
|
||||
main = "tests/run_pytest.py",
|
||||
deps = [
|
||||
"//pylib/anki",
|
||||
|
@ -123,7 +124,10 @@ py_binary(
|
|||
|
||||
py_binary(
|
||||
name = "runanki",
|
||||
srcs = ["runanki.py"],
|
||||
srcs = [
|
||||
"bazelfixes.py",
|
||||
"runanki.py",
|
||||
],
|
||||
data = [
|
||||
"//qt/aqt_data",
|
||||
],
|
||||
|
|
37
qt/bazelfixes.py
Normal file
37
qt/bazelfixes.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
def fix_pywin32_in_bazel(force=False):
|
||||
if sys.platform != "win32":
|
||||
return
|
||||
if not force and "BAZEL_SH" not in os.environ:
|
||||
return
|
||||
|
||||
import imp
|
||||
|
||||
# get path to pywin32 package
|
||||
path = None
|
||||
for path in sys.path:
|
||||
if "pywin32" in path:
|
||||
break
|
||||
|
||||
# trigger pywin32 bootstrap
|
||||
import site
|
||||
site.addsitedir(path)
|
||||
|
||||
# sys.path has been extended; use final
|
||||
# path to locate dll folder and add it to path
|
||||
path = sys.path[-1]
|
||||
path = path.replace("Pythonwin", "pywin32_system32")
|
||||
os.environ["PATH"] += ";" + path
|
||||
|
||||
# import pythoncom module
|
||||
filename = os.path.join(path, "pythoncom38.dll")
|
||||
mod = imp.load_module("pythoncom", None, filename,
|
||||
('.dll', 'rb', imp.C_EXTENSION))
|
||||
|
||||
|
||||
def fix_extraneous_path_in_bazel():
|
||||
# source folder conflicts with bazel-out source
|
||||
if sys.path[0].endswith("qt"):
|
||||
del sys.path[0]
|
|
@ -2,44 +2,13 @@
|
|||
|
||||
import os
|
||||
import sys
|
||||
try:
|
||||
import bazelfixes
|
||||
|
||||
def fix_pywin32_in_bazel():
|
||||
if sys.platform != "win32":
|
||||
return
|
||||
if "BAZEL_SH" not in os.environ:
|
||||
return
|
||||
|
||||
import imp
|
||||
|
||||
# get path to pywin32 package
|
||||
path = None
|
||||
for path in sys.path:
|
||||
if "pywin32" in path:
|
||||
break
|
||||
|
||||
# trigger pywin32 bootstrap
|
||||
import site
|
||||
site.addsitedir(path)
|
||||
|
||||
# sys.path has been extended; use final
|
||||
# path to locate dll folder and add it to path
|
||||
path = sys.path[-1]
|
||||
path = path.replace("Pythonwin", "pywin32_system32")
|
||||
os.environ["PATH"] += ";" + path
|
||||
|
||||
# import pythoncom module
|
||||
filename = os.path.join(path, "pythoncom38.dll")
|
||||
mod = imp.load_module("pythoncom", None, filename,
|
||||
('.dll', 'rb', imp.C_EXTENSION))
|
||||
|
||||
|
||||
def fix_extraneous_path_in_bazel():
|
||||
# source folder conflicts with bazel-out source
|
||||
if sys.path[0].endswith("qt"):
|
||||
del sys.path[0]
|
||||
|
||||
fix_pywin32_in_bazel()
|
||||
fix_extraneous_path_in_bazel()
|
||||
bazelfixes.fix_pywin32_in_bazel()
|
||||
bazelfixes.fix_extraneous_path_in_bazel()
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
import aqt
|
||||
|
||||
|
|
|
@ -3,6 +3,13 @@ import sys
|
|||
|
||||
import pytest
|
||||
|
||||
try:
|
||||
import bazelfixes
|
||||
|
||||
bazelfixes.fix_pywin32_in_bazel(force=True)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(os.path.dirname(__file__))
|
||||
folder = os.path.join(os.path.dirname(__file__), "..", "tests")
|
||||
|
|
Loading…
Reference in a new issue