Skip to content

Commit 5ef5208

Browse files
authored
Merge branch 'plugin_api_v2' into new-rtfm-plugin
2 parents b931376 + 034e01f commit 5ef5208

7 files changed

+293
-223
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"ID": "eb0c1059-1824-4fa6-b04e-aaeb4303cbe1",
3+
"Name": "ScreenBrightness",
4+
"Description": "Control the brightness of your monitors within flow",
5+
"Author": "cibere",
6+
"Version": "0.0.1",
7+
"Language": "python_v2",
8+
"Website": "https://github.com/cibere/Flow.Launcher.Plugin.ScreenBrightness",
9+
"UrlDownload": "https://github.com/cibere/Flow.Launcher.Plugin.ScreenBrightness/releases/download/v0.0.1/Flow.Launcher.Plugin.ScreenBrightness.zip",
10+
"UrlSourceCode": "https://github.com/cibere/Flow.Launcher.Plugin.ScreenBrightness",
11+
"IcoPath": "https://i.imgur.com/AvRgwSl.png"
12+
}

ci/src/_utils.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,21 @@
4141

4242

4343
def plugin_reader() -> P:
44-
plugin_files = get_plugin_files()
44+
plugin_file_paths = get_plugin_file_paths()
4545

4646
manifests = []
4747

48-
for plugin in plugin_files:
49-
with open(plugin, "r", encoding="utf-8") as f:
50-
manifest = json.load(f)
51-
manifests.append(manifest)
48+
for plugin_path in plugin_file_paths:
49+
with open(plugin_path, "r", encoding="utf-8") as f:
50+
manifests.append(json.load(f))
5251

5352
return manifests
5453

55-
def get_plugin_files() -> list[str]:
54+
def get_plugin_file_paths() -> list[str]:
5655
return [os.path.join(plugin_dir, filename) for filename in get_plugin_filenames()]
5756

5857
def get_plugin_filenames() -> list[str]:
59-
return [file for file in os.listdir(plugin_dir)]
58+
return os.listdir(plugin_dir)
6059

6160
def etag_reader() -> ETagsType:
6261
with open(etag_file, "r", encoding="utf-8") as f:
@@ -91,3 +90,13 @@ def check_url(url: str) -> bool:
9190
re.IGNORECASE,
9291
)
9392
return re.match(regex, url) is not None
93+
94+
95+
def get_file_plugins_json_info(required_key: str = "") -> list[dict[str, str]]:
96+
with open("plugins.json", "r", encoding="utf-8") as f:
97+
data = json.load(f)
98+
99+
if not required_key:
100+
return data
101+
102+
return [{required_key: plugin[required_key]} for plugin in data]

ci/src/validator.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# -*-coding: utf-8 -*-
2-
from _utils import clean, id_name, language_list, language_name, plugin_reader, check_url, icon_path, get_plugin_files, get_plugin_filenames
2+
import uuid
3+
4+
from _utils import (check_url, clean, get_file_plugins_json_info, get_plugin_file_paths, get_plugin_filenames,
5+
icon_path, id_name, language_list, language_name, plugin_reader)
36

47
plugin_infos = plugin_reader()
58

@@ -25,7 +28,7 @@ def test_valid_icon_url():
2528
assert check_url(plugin[icon_path]), msg
2629

2730
def test_file_type_json():
28-
incorrect_ext_files = [file for file in get_plugin_files() if not file.endswith(".json")]
31+
incorrect_ext_files = [file_path for file_path in get_plugin_file_paths() if not file_path.endswith(".json")]
2932

3033
assert len(incorrect_ext_files) == 0, f"Expected the following file to be of .json extension: {incorrect_ext_files}"
3134

@@ -35,3 +38,20 @@ def test_file_name_construct():
3538
assert (
3639
f"{info['Name']}-{info['ID']}.json" in filenames
3740
), f"Plugin {info['Name']} with ID {info['ID']} does not have the correct filename. Make sure it's name + ID, i.e. {info['Name']}-{info['ID']}.json"
41+
42+
def test_submitted_plugin_id_is_valid_uuid():
43+
plugins_json_ids = [item["ID"] for item in get_file_plugins_json_info("ID")]
44+
existing_plugin_file_ids = [info["ID"] for info in plugin_infos]
45+
46+
for id in existing_plugin_file_ids:
47+
# plugins.json would not contain new submission's ID.
48+
if id in plugins_json_ids:
49+
continue
50+
51+
try:
52+
uuid.UUID(id, version=4)
53+
outcome = True
54+
except ValueError:
55+
outcome = False
56+
57+
assert outcome is True, f"The submission plugin ID {id} is not a valid v4 UUID"

0 commit comments

Comments
 (0)