Skip to content

Commit 764695e

Browse files
authored
Merge branch 'plugin_api_v2' into plugin_api_v2
2 parents 214f135 + 8ce4c1e commit 764695e

File tree

6 files changed

+3403
-3351
lines changed

6 files changed

+3403
-3351
lines changed

ci/src/test-python.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,36 @@ def get_all_python_plugins(manifest: dict) -> list:
8181
return [plugin for plugin in manifest if plugin["Language"].lower() == "python"]
8282

8383
def run_plugin(plugin_name: str, plugin_path: str, execute_path: str) -> bool:
84-
"""Run plugin and check output. Returns true if test successfull else false"""
84+
"""Run plugin and check output. Returns true if test successful else false"""
8585
os.chdir(plugin_path)
8686
default_settings = init_settings(plugin_name, plugin_path)
8787
args = json.dumps(
8888
{"method": "query", "parameters": [""], "Settings": default_settings}
8989
)
90-
full_args = ["python", "-S", Path(plugin_path, execute_path), args]
90+
9191
# Older Flox used environmental variable to locate Images directory
9292
os.environ["PYTHONPATH"] = str(USER_PATH.joinpath("PythonEmbeddable"))
93+
94+
# Compose the sys.path setup and runpy logic as Flow Launcher does in
95+
# https://github.com/Flow-Launcher/Flow.Launcher/blob/dfe96160ed44684810bcdf853f86fda4305122d6/Flow.Launcher.Core/Plugin/PythonPlugin.cs#L69-L81
96+
sys_path_setup = (
97+
f"import sys; "
98+
f"sys.path.append(r'{plugin_path}'); "
99+
f"sys.path.append(r'{plugin_path}\\lib'); "
100+
f"sys.path.append(r'{plugin_path}\\lib\\win32\\lib'); "
101+
f"sys.path.append(r'{plugin_path}\\lib\\win32'); "
102+
f"sys.path.append(r'{plugin_path}\\plugin'); "
103+
f"import runpy; "
104+
f"runpy.run_path(r'{Path(plugin_path, execute_path)}', None, '__main__')"
105+
)
106+
107+
full_args = [
108+
"python",
109+
"-S",
110+
"-c",
111+
sys_path_setup,
112+
args
113+
]
93114
print_section("Input", full_args)
94115
p = Popen(full_args, text=True, stdout=PIPE, stderr=PIPE)
95116
stdout, stderr = p.communicate()
@@ -104,7 +125,7 @@ def run_plugin(plugin_name: str, plugin_path: str, execute_path: str) -> bool:
104125
return True
105126
else:
106127
print_section(f"{plugin['Name']} test FAILED!", "")
107-
print(f'Plugin returned a non-zero exit code: {max(exit_code, 1)}')
128+
print(f'Plugin has returned a non-zero exit code: {max(exit_code, 1)}')
108129
if stderr != "":
109130
print_section('Trace', stderr)
110131
if json_msg:

0 commit comments

Comments
 (0)