Skip to content

Commit

Permalink
Merge branch 'plugin_api_v2' into new-rtfm-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jjw24 authored Dec 20, 2024
2 parents b931376 + 034e01f commit 5ef5208
Show file tree
Hide file tree
Showing 7 changed files with 293 additions and 223 deletions.
12 changes: 12 additions & 0 deletions ScreenBrightness-eb0c1059-1824-4fa6-b04e-aaeb4303cbe1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"ID": "eb0c1059-1824-4fa6-b04e-aaeb4303cbe1",
"Name": "ScreenBrightness",
"Description": "Control the brightness of your monitors within flow",
"Author": "cibere",
"Version": "0.0.1",
"Language": "python_v2",
"Website": "https://github.com/cibere/Flow.Launcher.Plugin.ScreenBrightness",
"UrlDownload": "https://github.com/cibere/Flow.Launcher.Plugin.ScreenBrightness/releases/download/v0.0.1/Flow.Launcher.Plugin.ScreenBrightness.zip",
"UrlSourceCode": "https://github.com/cibere/Flow.Launcher.Plugin.ScreenBrightness",
"IcoPath": "https://i.imgur.com/AvRgwSl.png"
}
23 changes: 16 additions & 7 deletions ci/src/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,21 @@


def plugin_reader() -> P:
plugin_files = get_plugin_files()
plugin_file_paths = get_plugin_file_paths()

manifests = []

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

return manifests

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

def get_plugin_filenames() -> list[str]:
return [file for file in os.listdir(plugin_dir)]
return os.listdir(plugin_dir)

def etag_reader() -> ETagsType:
with open(etag_file, "r", encoding="utf-8") as f:
Expand Down Expand Up @@ -91,3 +90,13 @@ def check_url(url: str) -> bool:
re.IGNORECASE,
)
return re.match(regex, url) is not None


def get_file_plugins_json_info(required_key: str = "") -> list[dict[str, str]]:
with open("plugins.json", "r", encoding="utf-8") as f:
data = json.load(f)

if not required_key:
return data

return [{required_key: plugin[required_key]} for plugin in data]
24 changes: 22 additions & 2 deletions ci/src/validator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*-coding: utf-8 -*-
from _utils import clean, id_name, language_list, language_name, plugin_reader, check_url, icon_path, get_plugin_files, get_plugin_filenames
import uuid

from _utils import (check_url, clean, get_file_plugins_json_info, get_plugin_file_paths, get_plugin_filenames,
icon_path, id_name, language_list, language_name, plugin_reader)

plugin_infos = plugin_reader()

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

def test_file_type_json():
incorrect_ext_files = [file for file in get_plugin_files() if not file.endswith(".json")]
incorrect_ext_files = [file_path for file_path in get_plugin_file_paths() if not file_path.endswith(".json")]

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

Expand All @@ -35,3 +38,20 @@ def test_file_name_construct():
assert (
f"{info['Name']}-{info['ID']}.json" in filenames
), 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"

def test_submitted_plugin_id_is_valid_uuid():
plugins_json_ids = [item["ID"] for item in get_file_plugins_json_info("ID")]
existing_plugin_file_ids = [info["ID"] for info in plugin_infos]

for id in existing_plugin_file_ids:
# plugins.json would not contain new submission's ID.
if id in plugins_json_ids:
continue

try:
uuid.UUID(id, version=4)
outcome = True
except ValueError:
outcome = False

assert outcome is True, f"The submission plugin ID {id} is not a valid v4 UUID"
Loading

0 comments on commit 5ef5208

Please sign in to comment.