From 7078cf576d68704a759ceeb8a6a6dacc2c5717bd Mon Sep 17 00:00:00 2001 From: Zero Date: Tue, 10 Aug 2021 11:20:28 +0800 Subject: [PATCH 01/29] lint code via black --- .../commands.py | 60 +++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/commands.py b/Flow.Launcher.Plugin.PythonTemplate/commands.py index 5432812..03e4915 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/commands.py +++ b/Flow.Launcher.Plugin.PythonTemplate/commands.py @@ -5,10 +5,20 @@ import click -from plugin import (ICON_PATH, PLUGIN_ACTION_KEYWORD, PLUGIN_AUTHOR, - PLUGIN_EXECUTE_FILENAME, PLUGIN_ID, PLUGIN_PROGRAM_LANG, - PLUGIN_URL, __long_description__, __package_name__, - __short_description__, __version__, basedir) +from plugin import ( + ICON_PATH, + PLUGIN_ACTION_KEYWORD, + PLUGIN_AUTHOR, + PLUGIN_EXECUTE_FILENAME, + PLUGIN_ID, + PLUGIN_PROGRAM_LANG, + PLUGIN_URL, + __long_description__, + __package_name__, + __short_description__, + __version__, + basedir, +) @click.group() @@ -18,38 +28,38 @@ def translate(): @translate.command() -@click.argument('locale') +@click.argument("locale") def init(locale): """Initialize a new language.""" - if os.system('pybabel extract -F babel.cfg -k _l -o messages.pot .'): - raise RuntimeError('extract command failed') - if os.system('pybabel init -i messages.pot -d plugin/translations -l ' + locale): - raise RuntimeError('init command failed') - os.remove('messages.pot') + if os.system("pybabel extract -F babel.cfg -k _l -o messages.pot ."): + raise RuntimeError("extract command failed") + if os.system("pybabel init -i messages.pot -d plugin/translations -l " + locale): + raise RuntimeError("init command failed") + os.remove("messages.pot") - click.echo('Done.') + click.echo("Done.") @translate.command() def update(): """Update all languages.""" - if os.system('pybabel extract -F babel.cfg -k _l -o messages.pot .'): - raise RuntimeError('extract command failed') - if os.system('pybabel update -i messages.pot -d plugin/translations'): - raise RuntimeError('update command failed') - os.remove('messages.pot') + if os.system("pybabel extract -F babel.cfg -k _l -o messages.pot ."): + raise RuntimeError("extract command failed") + if os.system("pybabel update -i messages.pot -d plugin/translations"): + raise RuntimeError("update command failed") + os.remove("messages.pot") - click.echo('Done.') + click.echo("Done.") @translate.command() def compile(): """Compile all languages.""" - if os.system('pybabel compile -d plugin/translations'): - raise RuntimeError('compile command failed') + if os.system("pybabel compile -d plugin/translations"): + raise RuntimeError("compile command failed") - click.echo('Done.') + click.echo("Done.") @click.group() @@ -72,14 +82,14 @@ def gen_plugin_info(): "Language": PLUGIN_PROGRAM_LANG, "Website": PLUGIN_URL, "IcoPath": ICON_PATH, - "ExecuteFileName": PLUGIN_EXECUTE_FILENAME + "ExecuteFileName": PLUGIN_EXECUTE_FILENAME, } - json_path = os.path.join(basedir, 'plugin.json') - with open(json_path, 'w') as f: - json.dump(plugin_infos, f, indent=' '*4) + json_path = os.path.join(basedir, "plugin.json") + with open(json_path, "w") as f: + json.dump(plugin_infos, f, indent=" " * 4) - click.echo('Done.') + click.echo("Done.") cli = click.CommandCollection(sources=[plugin, translate]) From 792609933350a9bb7cdaaba35803cca1348d8058 Mon Sep 17 00:00:00 2001 From: Zero Date: Tue, 10 Aug 2021 11:36:08 +0800 Subject: [PATCH 02/29] lint codes via black --- Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py b/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py index 02ef341..51d979d 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py +++ b/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py @@ -10,15 +10,15 @@ pludir = setting_pyfile.parent basedir = pludir.parent -dotenv_path = basedir / '.env' +dotenv_path = basedir / ".env" if dotenv_path.exists(): load_dotenv(dotenv_path) -ICON_PATH = 'assets/favicon.ico' +ICON_PATH = "assets/favicon.ico" # The default value can work, if no user config. -CONFIG = os.getenv('CONFIG', 'default config') +CONFIG = os.getenv("CONFIG", "default config") LOCAL = os.getenv("local", "en") From a94b5bb7736077b2027f63cf2684bf083a5dee8a Mon Sep 17 00:00:00 2001 From: Zero Date: Tue, 10 Aug 2021 14:03:50 +0800 Subject: [PATCH 03/29] using pathlib to locate file --- Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py b/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py index 51d979d..f179b7e 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py +++ b/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py @@ -29,7 +29,7 @@ GITHUB_USERNAME = "USERNAME" -readme_path = os.path.join(basedir, 'README.md') +readme_path = basedir / "README.md" try: __long_description__ = open(readme_path, "r").read() except: From bfb3768a43b24eea366efd59ead8b716def759f2 Mon Sep 17 00:00:00 2001 From: Zero Date: Tue, 10 Aug 2021 15:41:48 +0800 Subject: [PATCH 04/29] lint codes via black --- Flow.Launcher.Plugin.PythonTemplate/plugin/ui.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/plugin/ui.py b/Flow.Launcher.Plugin.PythonTemplate/plugin/ui.py index 6197a8e..6ee13e6 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/plugin/ui.py +++ b/Flow.Launcher.Plugin.PythonTemplate/plugin/ui.py @@ -13,21 +13,21 @@ class Main(FlowLauncher): def sendNormalMess(self, title: str, subtitle: str): message = copy.deepcopy(RESULT_TEMPLATE) - message['Title'] = title - message['SubTitle'] = subtitle + message["Title"] = title + message["SubTitle"] = subtitle self.messages_queue.append(message) def sendActionMess(self, title: str, subtitle: str, method: str, value: List): # information message = copy.deepcopy(RESULT_TEMPLATE) - message['Title'] = title - message['SubTitle'] = subtitle + message["Title"] = title + message["SubTitle"] = subtitle # action action = copy.deepcopy(ACTION_TEMPLATE) - action['JsonRPCAction']['method'] = method - action['JsonRPCAction']['parameters'] = value + action["JsonRPCAction"]["method"] = method + action["JsonRPCAction"]["parameters"] = value message.update(action) self.messages_queue.append(message) From bab45a178a7935df0336b1a7ee7a3b3b57d03a7b Mon Sep 17 00:00:00 2001 From: Zero Date: Tue, 10 Aug 2021 15:42:10 +0800 Subject: [PATCH 05/29] lint codes via black --- .../plugin/__init__.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/plugin/__init__.py b/Flow.Launcher.Plugin.PythonTemplate/plugin/__init__.py index 684d885..2401922 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/plugin/__init__.py +++ b/Flow.Launcher.Plugin.PythonTemplate/plugin/__init__.py @@ -7,8 +7,18 @@ from plugin.settings import ( - GITHUB_USERNAME, ICON_PATH, PLUGIN_ACTION_KEYWORD, PLUGIN_AUTHOR, - PLUGIN_EXECUTE_FILENAME, PLUGIN_ID, PLUGIN_PROGRAM_LANG, PLUGIN_URL, - __long_description__, __package_name__, __short_description__, __version__, - basedir) + GITHUB_USERNAME, + ICON_PATH, + PLUGIN_ACTION_KEYWORD, + PLUGIN_AUTHOR, + PLUGIN_EXECUTE_FILENAME, + PLUGIN_ID, + PLUGIN_PROGRAM_LANG, + PLUGIN_URL, + __long_description__, + __package_name__, + __short_description__, + __version__, + basedir, +) from plugin.ui import Main From 893126afa3baf39379b935db012e8ccca73254e9 Mon Sep 17 00:00:00 2001 From: Zero Date: Tue, 10 Aug 2021 17:37:17 +0800 Subject: [PATCH 06/29] separate project ignore and plugin ignore --- .gitignore | 8 -------- Flow.Launcher.Plugin.PythonTemplate/.gitignore | 7 +++++++ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index c2d7493..c3751c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,3 @@ # vscode .history/ .vscode/ - - -# python cache -__pycache__/ - - -# mypy cache -.mypy_cache/ \ No newline at end of file diff --git a/Flow.Launcher.Plugin.PythonTemplate/.gitignore b/Flow.Launcher.Plugin.PythonTemplate/.gitignore index e69de29..a28b021 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/.gitignore +++ b/Flow.Launcher.Plugin.PythonTemplate/.gitignore @@ -0,0 +1,7 @@ +# build +lib/ +build/ + +# python cache +__pycache__/ +.mypy_cache/ From d0ca135008c6c564a77cd8681733c11e65ca3edb Mon Sep 17 00:00:00 2001 From: Zero Date: Tue, 10 Aug 2021 17:42:37 +0800 Subject: [PATCH 07/29] add blank line in code and description --- Flow.Launcher.Plugin.PythonTemplate/commands.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/commands.py b/Flow.Launcher.Plugin.PythonTemplate/commands.py index 03e4915..7bb04df 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/commands.py +++ b/Flow.Launcher.Plugin.PythonTemplate/commands.py @@ -56,6 +56,7 @@ def update(): @translate.command() def compile(): """Compile all languages.""" + if os.system("pybabel compile -d plugin/translations"): raise RuntimeError("compile command failed") @@ -70,7 +71,7 @@ def plugin(): @plugin.command() def gen_plugin_info(): - """Auto generate the `plugin.json` file for Flow""" + """Auto generate the 'plugin.json' file for Flow.""" plugin_infos = { "ID": PLUGIN_ID, From 7dd2b294c14defec65af4310ca8b010327fb06c5 Mon Sep 17 00:00:00 2001 From: Zero Date: Tue, 10 Aug 2021 17:43:34 +0800 Subject: [PATCH 08/29] simplify a bit inputting keyword --- Flow.Launcher.Plugin.PythonTemplate/commands.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/commands.py b/Flow.Launcher.Plugin.PythonTemplate/commands.py index 7bb04df..ef07ca9 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/commands.py +++ b/Flow.Launcher.Plugin.PythonTemplate/commands.py @@ -86,9 +86,8 @@ def gen_plugin_info(): "ExecuteFileName": PLUGIN_EXECUTE_FILENAME, } - json_path = os.path.join(basedir, "plugin.json") - with open(json_path, "w") as f: - json.dump(plugin_infos, f, indent=" " * 4) + with open(basedir / "plugin.json", "w") as f: + json.dump(plugin_infos, f, indent=4) click.echo("Done.") From 92d0dd430617bb38f4c123e9fc36edf0eea4bf3b Mon Sep 17 00:00:00 2001 From: Zero Date: Tue, 10 Aug 2021 17:46:15 +0800 Subject: [PATCH 09/29] using f-string replace string concating --- Flow.Launcher.Plugin.PythonTemplate/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/commands.py b/Flow.Launcher.Plugin.PythonTemplate/commands.py index ef07ca9..accfdf9 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/commands.py +++ b/Flow.Launcher.Plugin.PythonTemplate/commands.py @@ -34,7 +34,7 @@ def init(locale): if os.system("pybabel extract -F babel.cfg -k _l -o messages.pot ."): raise RuntimeError("extract command failed") - if os.system("pybabel init -i messages.pot -d plugin/translations -l " + locale): + if os.system(f"pybabel init -i messages.pot -d plugin/translations -l {locale}"): raise RuntimeError("init command failed") os.remove("messages.pot") From d1728b9825199fc9f9f1fa7e2582ade0e7043bb0 Mon Sep 17 00:00:00 2001 From: Zero Date: Tue, 10 Aug 2021 17:48:05 +0800 Subject: [PATCH 10/29] add install dependencies command --- .../commands.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/commands.py b/Flow.Launcher.Plugin.PythonTemplate/commands.py index accfdf9..53c7b69 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/commands.py +++ b/Flow.Launcher.Plugin.PythonTemplate/commands.py @@ -69,6 +69,16 @@ def plugin(): ... +@plugin.command() +def install_dependencies(): + """Install dependencies to local.""" + + lib_path = basedir / "lib" + os.system(f"pip install -r requirements.txt -t {lib_path} --upgrade") + + click.echo("Done.") + + @plugin.command() def gen_plugin_info(): """Auto generate the 'plugin.json' file for Flow.""" @@ -92,7 +102,11 @@ def gen_plugin_info(): click.echo("Done.") -cli = click.CommandCollection(sources=[plugin, translate]) - if __name__ == "__main__": + cli = click.CommandCollection( + sources=[ + plugin, + translate, + ] + ) cli() From 0ddfb9af1819e7099b131f769067c9ac8edd4b57 Mon Sep 17 00:00:00 2001 From: Zero Date: Tue, 10 Aug 2021 17:49:05 +0800 Subject: [PATCH 11/29] add clean command group --- .../commands.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Flow.Launcher.Plugin.PythonTemplate/commands.py b/Flow.Launcher.Plugin.PythonTemplate/commands.py index 53c7b69..370e39a 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/commands.py +++ b/Flow.Launcher.Plugin.PythonTemplate/commands.py @@ -102,9 +102,35 @@ def gen_plugin_info(): click.echo("Done.") +@click.group() +def clean(): + """Clean commands.""" + ... + + +@clean.command() +def clean_build(): + """Remove build artifacts""" + + os.system("rm -fr build/") + click.echo("Done.") + + +@clean.command() +def clean_pyc(): + "Remove Python file artifacts" + + os.system(f"find {basedir} -name '*.pyc' -exec rm -f {{}} +") + os.system(f"find {basedir} -name '*.pyo' -exec rm -f {{}} +") + os.system(f"find {basedir} -name '*~' -exec rm -f {{}} +") + + click.echo("Done.") + + if __name__ == "__main__": cli = click.CommandCollection( sources=[ + clean, plugin, translate, ] From e72ab2893a7a4557f3490467b8306a9029be5b55 Mon Sep 17 00:00:00 2001 From: Zero Date: Tue, 10 Aug 2021 17:57:39 +0800 Subject: [PATCH 12/29] add build command --- .../commands.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/Flow.Launcher.Plugin.PythonTemplate/commands.py b/Flow.Launcher.Plugin.PythonTemplate/commands.py index 370e39a..c0fd1bf 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/commands.py +++ b/Flow.Launcher.Plugin.PythonTemplate/commands.py @@ -2,6 +2,7 @@ import json import os +from textwrap import dedent import click @@ -102,6 +103,52 @@ def gen_plugin_info(): click.echo("Done.") +@plugin.command() +def build(): + "Pack plugin to a zip file." + + # zip plugin + build_path = basedir / "build" + build_path.mkdir(exist_ok=True) + zip_path = build_path / f"{__package_name__.title()}-{__version__}.zip" + zip_path.unlink(missing_ok=True) + + ignore_list = [ + # folder + ".git/*", + ".vscode/*", + ".history/*", + "*/__pycache__/*", + "build/*", + # file + ".gitignore", + ".gitattributes", + ] + os.system(f"zip -r {zip_path} . -x {' '.join(ignore_list)}") + + # hook lib folder path to python system environment variable path + env_snippet = dedent( + """\ + import os + import sys + + basedir = os.path.dirname(os.path.abspath(__file__)) + sys.path.append(os.path.join(basedir, "lib")) + """ + ) + + entry_src = basedir / "main.py" + entry_src_temp = build_path / "main.py" + with open(entry_src, "r") as f_r: + with open(entry_src_temp, "w", encoding="utf-8") as f_w: + f_w.write(env_snippet + f_r.read()) + + os.system(f"zip -j {zip_path} {entry_src_temp}") + entry_src_temp.unlink() + + click.echo("Done.") + + @click.group() def clean(): """Clean commands.""" From 7863a8d4190ac43a04bcd3c5cf1084a510b40d77 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Thu, 12 Aug 2021 20:51:35 +1000 Subject: [PATCH 13/29] add setup environment command --- Flow.Launcher.Plugin.PythonTemplate/commands.py | 7 +++++++ Flow.Launcher.Plugin.PythonTemplate/requirements-dev.txt | 1 + 2 files changed, 8 insertions(+) diff --git a/Flow.Launcher.Plugin.PythonTemplate/commands.py b/Flow.Launcher.Plugin.PythonTemplate/commands.py index c0fd1bf..acbba29 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/commands.py +++ b/Flow.Launcher.Plugin.PythonTemplate/commands.py @@ -79,6 +79,13 @@ def install_dependencies(): click.echo("Done.") +@plugin.command() +def setup_dev_env(): + """Set up the development environment for the first time. This installs requirements-dev.txt """ + + os.system(f"pip install -r requirements-dev.txt --upgrade") + + click.echo("Dev environment ready to go.") @plugin.command() def gen_plugin_info(): diff --git a/Flow.Launcher.Plugin.PythonTemplate/requirements-dev.txt b/Flow.Launcher.Plugin.PythonTemplate/requirements-dev.txt index 03f4fbc..8a2d292 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/requirements-dev.txt +++ b/Flow.Launcher.Plugin.PythonTemplate/requirements-dev.txt @@ -1,2 +1,3 @@ click babel +python-dotenv \ No newline at end of file From 0362866027cc2f621a3302b10c0ec8851cdf9339 Mon Sep 17 00:00:00 2001 From: Zero Date: Fri, 13 Aug 2021 17:17:00 +0800 Subject: [PATCH 14/29] EHN: add `get_build_ignores` func --- .../.buildignore | 12 +++++++ .../commands.py | 31 ++++++++++++------- 2 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 Flow.Launcher.Plugin.PythonTemplate/.buildignore diff --git a/Flow.Launcher.Plugin.PythonTemplate/.buildignore b/Flow.Launcher.Plugin.PythonTemplate/.buildignore new file mode 100644 index 0000000..8daa537 --- /dev/null +++ b/Flow.Launcher.Plugin.PythonTemplate/.buildignore @@ -0,0 +1,12 @@ +# folder +.git/* +.github/* +.vscode/* +.history/* +*/__pycache__/* +build/* + +# file +.gitignore +.gitattributes +.buildignore diff --git a/Flow.Launcher.Plugin.PythonTemplate/commands.py b/Flow.Launcher.Plugin.PythonTemplate/commands.py index c0fd1bf..11a16cb 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/commands.py +++ b/Flow.Launcher.Plugin.PythonTemplate/commands.py @@ -3,6 +3,7 @@ import json import os from textwrap import dedent +from typing import List import click @@ -21,6 +22,24 @@ basedir, ) +build_ignore_path = basedir / ".buildignore" +build_ignore_path.touch() # if no existed, would be created + + +def get_build_ignores(comment: str = "#") -> List[str]: + """ + Ignore file or folder when building a plugin, similar to '.gitignore'. + """ + ignore_list = [] + + with open(build_ignore_path, "r") as f: + for line in f.readlines(): + line = line.strip() + if line and not line.startswith(comment): + ignore_list.append(line) + + return ignore_list + @click.group() def translate(): @@ -113,17 +132,7 @@ def build(): zip_path = build_path / f"{__package_name__.title()}-{__version__}.zip" zip_path.unlink(missing_ok=True) - ignore_list = [ - # folder - ".git/*", - ".vscode/*", - ".history/*", - "*/__pycache__/*", - "build/*", - # file - ".gitignore", - ".gitattributes", - ] + ignore_list = get_build_ignores() os.system(f"zip -r {zip_path} . -x {' '.join(ignore_list)}") # hook lib folder path to python system environment variable path From 19cec9a6a4ad08073c1d5f5d3d442b5de618ed9e Mon Sep 17 00:00:00 2001 From: Zero Date: Fri, 13 Aug 2021 17:19:55 +0800 Subject: [PATCH 15/29] MAINT: gather all constants to one place --- Flow.Launcher.Plugin.PythonTemplate/commands.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/commands.py b/Flow.Launcher.Plugin.PythonTemplate/commands.py index 11a16cb..c5f6a97 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/commands.py +++ b/Flow.Launcher.Plugin.PythonTemplate/commands.py @@ -22,8 +22,17 @@ basedir, ) +# constants +# folder +build_path = basedir / "build" +build_path.mkdir(exist_ok=True) +lib_path = basedir / "lib" +lib_path.mkdir(exist_ok=True) + +# file build_ignore_path = basedir / ".buildignore" build_ignore_path.touch() # if no existed, would be created +entry_src = basedir / PLUGIN_EXECUTE_FILENAME def get_build_ignores(comment: str = "#") -> List[str]: @@ -93,7 +102,6 @@ def plugin(): def install_dependencies(): """Install dependencies to local.""" - lib_path = basedir / "lib" os.system(f"pip install -r requirements.txt -t {lib_path} --upgrade") click.echo("Done.") @@ -127,8 +135,6 @@ def build(): "Pack plugin to a zip file." # zip plugin - build_path = basedir / "build" - build_path.mkdir(exist_ok=True) zip_path = build_path / f"{__package_name__.title()}-{__version__}.zip" zip_path.unlink(missing_ok=True) @@ -146,7 +152,6 @@ def build(): """ ) - entry_src = basedir / "main.py" entry_src_temp = build_path / "main.py" with open(entry_src, "r") as f_r: with open(entry_src_temp, "w", encoding="utf-8") as f_w: From 01cb621f5fb6961529801374dff7bffeaa95b9df Mon Sep 17 00:00:00 2001 From: Zero Date: Fri, 13 Aug 2021 17:28:56 +0800 Subject: [PATCH 16/29] EHN: add `hook_env_snippet` func --- .../commands.py | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/commands.py b/Flow.Launcher.Plugin.PythonTemplate/commands.py index c5f6a97..1800180 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/commands.py +++ b/Flow.Launcher.Plugin.PythonTemplate/commands.py @@ -50,6 +50,24 @@ def get_build_ignores(comment: str = "#") -> List[str]: return ignore_list +def hook_env_snippet(temp_path): + """Hook lib folder path to python system environment variable path.""" + + env_snippet = dedent( + f"""\ + import os + import sys + + basedir = os.path.dirname(os.path.abspath(__file__)) + sys.path.append(os.path.join(basedir, "{lib_path.name}")) + """ + ) + + with open(entry_src, "r") as f_r: + with open(temp_path, "w") as f_w: + f_w.write(env_snippet + f_r.read()) + + @click.group() def translate(): """Translation and localization commands.""" @@ -141,24 +159,10 @@ def build(): ignore_list = get_build_ignores() os.system(f"zip -r {zip_path} . -x {' '.join(ignore_list)}") - # hook lib folder path to python system environment variable path - env_snippet = dedent( - """\ - import os - import sys - - basedir = os.path.dirname(os.path.abspath(__file__)) - sys.path.append(os.path.join(basedir, "lib")) - """ - ) - - entry_src_temp = build_path / "main.py" - with open(entry_src, "r") as f_r: - with open(entry_src_temp, "w", encoding="utf-8") as f_w: - f_w.write(env_snippet + f_r.read()) - - os.system(f"zip -j {zip_path} {entry_src_temp}") - entry_src_temp.unlink() + entry_src_hooked = build_path / PLUGIN_EXECUTE_FILENAME + hook_env_snippet(entry_src_hooked) + os.system(f"zip -j {zip_path} {entry_src_hooked}") + entry_src_hooked.unlink() click.echo("Done.") From 5091986f150696ae4d9e6c1c365802ae60ede101 Mon Sep 17 00:00:00 2001 From: Zero Date: Fri, 13 Aug 2021 17:38:03 +0800 Subject: [PATCH 17/29] add `UrlDownload` and `UrlSourceCode` fields --- .../commands.py | 33 ++++++++++--------- .../plugin/__init__.py | 3 +- .../plugin/settings.py | 2 ++ 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/commands.py b/Flow.Launcher.Plugin.PythonTemplate/commands.py index 1800180..5555ece 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/commands.py +++ b/Flow.Launcher.Plugin.PythonTemplate/commands.py @@ -15,6 +15,8 @@ PLUGIN_ID, PLUGIN_PROGRAM_LANG, PLUGIN_URL, + PLUGIN_URL_DOWNLOAD, + PLUGIN_URL_SOURCE_CODE, __long_description__, __package_name__, __short_description__, @@ -34,6 +36,21 @@ build_ignore_path.touch() # if no existed, would be created entry_src = basedir / PLUGIN_EXECUTE_FILENAME +plugin_infos = { + "ID": PLUGIN_ID, + "ActionKeyword": PLUGIN_ACTION_KEYWORD, + "Name": __package_name__, + "Description": __short_description__, + "Author": PLUGIN_AUTHOR, + "Version": __version__, + "Language": PLUGIN_PROGRAM_LANG, + "Website": PLUGIN_URL, + "IcoPath": ICON_PATH, + "ExecuteFileName": PLUGIN_EXECUTE_FILENAME, + "UrlDownload": PLUGIN_URL_DOWNLOAD, + "UrlSourceCode": PLUGIN_URL_SOURCE_CODE, +} + def get_build_ignores(comment: str = "#") -> List[str]: """ @@ -129,19 +146,6 @@ def install_dependencies(): def gen_plugin_info(): """Auto generate the 'plugin.json' file for Flow.""" - plugin_infos = { - "ID": PLUGIN_ID, - "ActionKeyword": PLUGIN_ACTION_KEYWORD, - "Name": __package_name__.title(), - "Description": __short_description__, - "Author": PLUGIN_AUTHOR, - "Version": __version__, - "Language": PLUGIN_PROGRAM_LANG, - "Website": PLUGIN_URL, - "IcoPath": ICON_PATH, - "ExecuteFileName": PLUGIN_EXECUTE_FILENAME, - } - with open(basedir / "plugin.json", "w") as f: json.dump(plugin_infos, f, indent=4) @@ -152,8 +156,7 @@ def gen_plugin_info(): def build(): "Pack plugin to a zip file." - # zip plugin - zip_path = build_path / f"{__package_name__.title()}-{__version__}.zip" + zip_path = build_path / f"{__package_name__}-{__version__}.zip" zip_path.unlink(missing_ok=True) ignore_list = get_build_ignores() diff --git a/Flow.Launcher.Plugin.PythonTemplate/plugin/__init__.py b/Flow.Launcher.Plugin.PythonTemplate/plugin/__init__.py index 2401922..6162284 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/plugin/__init__.py +++ b/Flow.Launcher.Plugin.PythonTemplate/plugin/__init__.py @@ -7,7 +7,6 @@ from plugin.settings import ( - GITHUB_USERNAME, ICON_PATH, PLUGIN_ACTION_KEYWORD, PLUGIN_AUTHOR, @@ -15,6 +14,8 @@ PLUGIN_ID, PLUGIN_PROGRAM_LANG, PLUGIN_URL, + PLUGIN_URL_DOWNLOAD, + PLUGIN_URL_SOURCE_CODE, __long_description__, __package_name__, __short_description__, diff --git a/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py b/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py index f179b7e..ea0d085 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py +++ b/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py @@ -44,3 +44,5 @@ PLUGIN_PROGRAM_LANG = "python" PLUGIN_URL = f"https://github.com/{GITHUB_USERNAME}/{__package_name__}" PLUGIN_EXECUTE_FILENAME = "main.py" +PLUGIN_URL_DOWNLOAD = f"https://github.com/{GITHUB_USERNAME}/{__package_name__}" +PLUGIN_URL_SOURCE_CODE = f"https://github.com/{GITHUB_USERNAME}/{__package_name__}" From dbbdb8bd986e0e1e322f91e4c841e36c4d5230e4 Mon Sep 17 00:00:00 2001 From: Zero Date: Fri, 13 Aug 2021 17:39:11 +0800 Subject: [PATCH 18/29] add field description + remove same keyword --- Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py b/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py index ea0d085..2a954fe 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py +++ b/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py @@ -15,8 +15,6 @@ load_dotenv(dotenv_path) -ICON_PATH = "assets/favicon.ico" - # The default value can work, if no user config. CONFIG = os.getenv("CONFIG", "default config") LOCAL = os.getenv("local", "en") @@ -37,12 +35,12 @@ # other information -PLUGIN_ID = "uuid" +PLUGIN_ID = "uuid" # could generate via python `uuid` official package ICON_PATH = "assets/favicon.ico" -PLUGIN_ACTION_KEYWORD = "KEYWORD" PLUGIN_AUTHOR = "AUTHOR_NAME" +PLUGIN_ACTION_KEYWORD = "KEYWORD" PLUGIN_PROGRAM_LANG = "python" -PLUGIN_URL = f"https://github.com/{GITHUB_USERNAME}/{__package_name__}" PLUGIN_EXECUTE_FILENAME = "main.py" +PLUGIN_URL = f"https://github.com/{GITHUB_USERNAME}/{__package_name__}" PLUGIN_URL_DOWNLOAD = f"https://github.com/{GITHUB_USERNAME}/{__package_name__}" PLUGIN_URL_SOURCE_CODE = f"https://github.com/{GITHUB_USERNAME}/{__package_name__}" From dd13448e12f0ceba7b4bd928a92fe351e7c0ec21 Mon Sep 17 00:00:00 2001 From: Zero Date: Fri, 13 Aug 2021 17:44:21 +0800 Subject: [PATCH 19/29] use oop path replace fixed string --- Flow.Launcher.Plugin.PythonTemplate/commands.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/commands.py b/Flow.Launcher.Plugin.PythonTemplate/commands.py index 5555ece..ae043d2 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/commands.py +++ b/Flow.Launcher.Plugin.PythonTemplate/commands.py @@ -35,6 +35,8 @@ build_ignore_path = basedir / ".buildignore" build_ignore_path.touch() # if no existed, would be created entry_src = basedir / PLUGIN_EXECUTE_FILENAME +translations_path = basedir / "plugin/translations" +plugin_info_path = basedir / "plugin.json" plugin_infos = { "ID": PLUGIN_ID, @@ -98,7 +100,7 @@ def init(locale): if os.system("pybabel extract -F babel.cfg -k _l -o messages.pot ."): raise RuntimeError("extract command failed") - if os.system(f"pybabel init -i messages.pot -d plugin/translations -l {locale}"): + if os.system(f"pybabel init -i messages.pot -d {translations_path} -l {locale}"): raise RuntimeError("init command failed") os.remove("messages.pot") @@ -110,7 +112,7 @@ def update(): """Update all languages.""" if os.system("pybabel extract -F babel.cfg -k _l -o messages.pot ."): raise RuntimeError("extract command failed") - if os.system("pybabel update -i messages.pot -d plugin/translations"): + if os.system(f"pybabel update -i messages.pot -d {translations_path}"): raise RuntimeError("update command failed") os.remove("messages.pot") @@ -121,7 +123,7 @@ def update(): def compile(): """Compile all languages.""" - if os.system("pybabel compile -d plugin/translations"): + if os.system(f"pybabel compile -d {translations_path}"): raise RuntimeError("compile command failed") click.echo("Done.") @@ -146,7 +148,7 @@ def install_dependencies(): def gen_plugin_info(): """Auto generate the 'plugin.json' file for Flow.""" - with open(basedir / "plugin.json", "w") as f: + with open(plugin_info_path, "w") as f: json.dump(plugin_infos, f, indent=4) click.echo("Done.") From 873bae86386748a0db25e15c8471d3257985291a Mon Sep 17 00:00:00 2001 From: Zero Date: Fri, 13 Aug 2021 18:10:22 +0800 Subject: [PATCH 20/29] Create release.yml --- .../.github/workflows/release.yml | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Flow.Launcher.Plugin.PythonTemplate/.github/workflows/release.yml diff --git a/Flow.Launcher.Plugin.PythonTemplate/.github/workflows/release.yml b/Flow.Launcher.Plugin.PythonTemplate/.github/workflows/release.yml new file mode 100644 index 0000000..2b09bde --- /dev/null +++ b/Flow.Launcher.Plugin.PythonTemplate/.github/workflows/release.yml @@ -0,0 +1,68 @@ +name: Publish Plugin to GitHub + +on: + push: + tags: + - "v*" + +jobs: + build-publish: + name: Build and publish geopandas to PyPI + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.x" + + - name: Setup Environment + run: | + python -m pip install --upgrade pip + python install -r requirements.txt + python install -r requirements-dev.txt + + - name: Install Dependencies to Local + run: python commands.py install-dependencies + + - name: Compile all languages + run: python commands.py compile + + - name: Update 'plugin.json' information + run: python commands.py gen-plugin-info + + - name: Remove Python file artifacts + run: python commands.py clean-pyc + + - name: Pack plugin to a zip file + run: python commands.py build + + - name: Create GitHub Release + id: create_release + uses: actions/create-release@v1 + env: + # This token is provided by Actions + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + draft: false + prerelease: false + + - name: Get Asset name + run: | + export PKG=$(ls build/ | grep zip) + set -- $PKG + echo "name=$1" >> $GITHUB_ENV + + - name: Upload Release (zip) to GitHub + id: upload-release-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: build/${{ env.name }} + asset_name: ${{ env.name }} + asset_content_type: application/zip From 65ca68a9a3f477b32582bc60eece5f9329dae7f5 Mon Sep 17 00:00:00 2001 From: Zero Date: Fri, 13 Aug 2021 18:20:21 +0800 Subject: [PATCH 21/29] extract all TRANSLATIONS_PATH to one place --- Flow.Launcher.Plugin.PythonTemplate/commands.py | 8 ++++---- Flow.Launcher.Plugin.PythonTemplate/plugin/__init__.py | 1 + Flow.Launcher.Plugin.PythonTemplate/plugin/extensions.py | 7 +++++-- Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py | 5 ++++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/commands.py b/Flow.Launcher.Plugin.PythonTemplate/commands.py index ae043d2..ddb075f 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/commands.py +++ b/Flow.Launcher.Plugin.PythonTemplate/commands.py @@ -17,6 +17,7 @@ PLUGIN_URL, PLUGIN_URL_DOWNLOAD, PLUGIN_URL_SOURCE_CODE, + TRANSLATIONS_PATH, __long_description__, __package_name__, __short_description__, @@ -35,7 +36,6 @@ build_ignore_path = basedir / ".buildignore" build_ignore_path.touch() # if no existed, would be created entry_src = basedir / PLUGIN_EXECUTE_FILENAME -translations_path = basedir / "plugin/translations" plugin_info_path = basedir / "plugin.json" plugin_infos = { @@ -100,7 +100,7 @@ def init(locale): if os.system("pybabel extract -F babel.cfg -k _l -o messages.pot ."): raise RuntimeError("extract command failed") - if os.system(f"pybabel init -i messages.pot -d {translations_path} -l {locale}"): + if os.system(f"pybabel init -i messages.pot -d {TRANSLATIONS_PATH} -l {locale}"): raise RuntimeError("init command failed") os.remove("messages.pot") @@ -112,7 +112,7 @@ def update(): """Update all languages.""" if os.system("pybabel extract -F babel.cfg -k _l -o messages.pot ."): raise RuntimeError("extract command failed") - if os.system(f"pybabel update -i messages.pot -d {translations_path}"): + if os.system(f"pybabel update -i messages.pot -d {TRANSLATIONS_PATH}"): raise RuntimeError("update command failed") os.remove("messages.pot") @@ -123,7 +123,7 @@ def update(): def compile(): """Compile all languages.""" - if os.system(f"pybabel compile -d {translations_path}"): + if os.system(f"pybabel compile -d {TRANSLATIONS_PATH}"): raise RuntimeError("compile command failed") click.echo("Done.") diff --git a/Flow.Launcher.Plugin.PythonTemplate/plugin/__init__.py b/Flow.Launcher.Plugin.PythonTemplate/plugin/__init__.py index 6162284..da854ae 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/plugin/__init__.py +++ b/Flow.Launcher.Plugin.PythonTemplate/plugin/__init__.py @@ -16,6 +16,7 @@ PLUGIN_URL, PLUGIN_URL_DOWNLOAD, PLUGIN_URL_SOURCE_CODE, + TRANSLATIONS_PATH, __long_description__, __package_name__, __short_description__, diff --git a/Flow.Launcher.Plugin.PythonTemplate/plugin/extensions.py b/Flow.Launcher.Plugin.PythonTemplate/plugin/extensions.py index df38abf..eb4b0d1 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/plugin/extensions.py +++ b/Flow.Launcher.Plugin.PythonTemplate/plugin/extensions.py @@ -2,10 +2,13 @@ import gettext -from plugin.settings import LOCAL +from plugin.settings import LOCAL, TRANSLATIONS_PATH # localization translation = gettext.translation( - "messages", "plugin/translations/", languages=[LOCAL]) + "messages", + TRANSLATIONS_PATH, + languages=[LOCAL], +) _l = translation.gettext diff --git a/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py b/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py index 2a954fe..6097ff4 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py +++ b/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py @@ -34,7 +34,10 @@ __long_description__ = __short_description__ -# other information +# extensions +TRANSLATIONS_PATH = basedir / "plugin/translations" + +# plugin.json PLUGIN_ID = "uuid" # could generate via python `uuid` official package ICON_PATH = "assets/favicon.ico" PLUGIN_AUTHOR = "AUTHOR_NAME" From a214108f692af5dcf711938a6c62a4d34e18edc8 Mon Sep 17 00:00:00 2001 From: Zero Date: Fri, 13 Aug 2021 18:36:21 +0800 Subject: [PATCH 22/29] should be `pip` --- .../.github/workflows/release.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/.github/workflows/release.yml b/Flow.Launcher.Plugin.PythonTemplate/.github/workflows/release.yml index 2b09bde..b289c86 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/.github/workflows/release.yml +++ b/Flow.Launcher.Plugin.PythonTemplate/.github/workflows/release.yml @@ -12,7 +12,7 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up Python + - name: Setup Python uses: actions/setup-python@v2 with: python-version: "3.x" @@ -20,8 +20,8 @@ jobs: - name: Setup Environment run: | python -m pip install --upgrade pip - python install -r requirements.txt - python install -r requirements-dev.txt + pip install -r requirements.txt + pip install -r requirements-dev.txt - name: Install Dependencies to Local run: python commands.py install-dependencies From 8dcfe95375964a912d4a9b1556086c167ffae37f Mon Sep 17 00:00:00 2001 From: Zero Date: Fri, 13 Aug 2021 18:47:15 +0800 Subject: [PATCH 23/29] rename ci --- .../.github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/.github/workflows/release.yml b/Flow.Launcher.Plugin.PythonTemplate/.github/workflows/release.yml index b289c86..02ad22f 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/.github/workflows/release.yml +++ b/Flow.Launcher.Plugin.PythonTemplate/.github/workflows/release.yml @@ -7,7 +7,7 @@ on: jobs: build-publish: - name: Build and publish geopandas to PyPI + name: Build and publish plugin runs-on: ubuntu-latest steps: From 4e277fd34feb2da8d56f664dbe96de63a06a4ab8 Mon Sep 17 00:00:00 2001 From: Zero Date: Mon, 16 Aug 2021 11:04:18 +0800 Subject: [PATCH 24/29] rename CI --- .../.github/workflows/release.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/.github/workflows/release.yml b/Flow.Launcher.Plugin.PythonTemplate/.github/workflows/release.yml index 02ad22f..a8e7166 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/.github/workflows/release.yml +++ b/Flow.Launcher.Plugin.PythonTemplate/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Publish Plugin to GitHub +name: Build and Publish on: push: @@ -7,17 +7,18 @@ on: jobs: build-publish: - name: Build and publish plugin + name: Build and Publish runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Setup Python + + - name: Set up Python uses: actions/setup-python@v2 with: python-version: "3.x" - - name: Setup Environment + - name: Set up Environment run: | python -m pip install --upgrade pip pip install -r requirements.txt From b6897ef3fbddc2594a6024f64327e411160b6098 Mon Sep 17 00:00:00 2001 From: Zero Date: Mon, 16 Aug 2021 11:08:14 +0800 Subject: [PATCH 25/29] add plugin zip file constant --- Flow.Launcher.Plugin.PythonTemplate/plugin/__init__.py | 3 ++- Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/plugin/__init__.py b/Flow.Launcher.Plugin.PythonTemplate/plugin/__init__.py index da854ae..cf9e2ec 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/plugin/__init__.py +++ b/Flow.Launcher.Plugin.PythonTemplate/plugin/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ Plugin -===== +====== Introduce the plugin. """ @@ -16,6 +16,7 @@ PLUGIN_URL, PLUGIN_URL_DOWNLOAD, PLUGIN_URL_SOURCE_CODE, + PLUGIN_ZIP_NAME, TRANSLATIONS_PATH, __long_description__, __package_name__, diff --git a/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py b/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py index 6097ff4..fbf44fc 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py +++ b/Flow.Launcher.Plugin.PythonTemplate/plugin/settings.py @@ -44,6 +44,9 @@ PLUGIN_ACTION_KEYWORD = "KEYWORD" PLUGIN_PROGRAM_LANG = "python" PLUGIN_EXECUTE_FILENAME = "main.py" +PLUGIN_ZIP_NAME = f"{__package_name__}-{__version__}.zip" PLUGIN_URL = f"https://github.com/{GITHUB_USERNAME}/{__package_name__}" -PLUGIN_URL_DOWNLOAD = f"https://github.com/{GITHUB_USERNAME}/{__package_name__}" PLUGIN_URL_SOURCE_CODE = f"https://github.com/{GITHUB_USERNAME}/{__package_name__}" +PLUGIN_URL_DOWNLOAD = ( + f"{PLUGIN_URL_SOURCE_CODE}/releases/download/v{__version__}/{PLUGIN_ZIP_NAME}" +) From 4fb7ab517d21b32a0516fefc52acd18e8d114ce6 Mon Sep 17 00:00:00 2001 From: Zero Date: Mon, 16 Aug 2021 11:10:51 +0800 Subject: [PATCH 26/29] import `PLUGIN_ZIP_NAME` from settings.py --- Flow.Launcher.Plugin.PythonTemplate/commands.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/commands.py b/Flow.Launcher.Plugin.PythonTemplate/commands.py index ddb075f..014d76b 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/commands.py +++ b/Flow.Launcher.Plugin.PythonTemplate/commands.py @@ -17,6 +17,7 @@ PLUGIN_URL, PLUGIN_URL_DOWNLOAD, PLUGIN_URL_SOURCE_CODE, + PLUGIN_ZIP_NAME, TRANSLATIONS_PATH, __long_description__, __package_name__, @@ -37,6 +38,7 @@ build_ignore_path.touch() # if no existed, would be created entry_src = basedir / PLUGIN_EXECUTE_FILENAME plugin_info_path = basedir / "plugin.json" +zip_path = build_path / f"{PLUGIN_ZIP_NAME}" plugin_infos = { "ID": PLUGIN_ID, @@ -158,7 +160,6 @@ def gen_plugin_info(): def build(): "Pack plugin to a zip file." - zip_path = build_path / f"{__package_name__}-{__version__}.zip" zip_path.unlink(missing_ok=True) ignore_list = get_build_ignores() From 266cd0d0af8d45657e2cff4f7bed84f7a39b10f4 Mon Sep 17 00:00:00 2001 From: Zero Date: Mon, 16 Aug 2021 11:12:47 +0800 Subject: [PATCH 27/29] add single quotation to fix Linux env zip command can't ignore --- Flow.Launcher.Plugin.PythonTemplate/commands.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/commands.py b/Flow.Launcher.Plugin.PythonTemplate/commands.py index 014d76b..a15e41e 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/commands.py +++ b/Flow.Launcher.Plugin.PythonTemplate/commands.py @@ -163,7 +163,8 @@ def build(): zip_path.unlink(missing_ok=True) ignore_list = get_build_ignores() - os.system(f"zip -r {zip_path} . -x {' '.join(ignore_list)}") + ignore_string = "'" + "' '".join(ignore_list) + "'" + os.system(f"zip -r {zip_path} . -x {ignore_string}") entry_src_hooked = build_path / PLUGIN_EXECUTE_FILENAME hook_env_snippet(entry_src_hooked) From fd03d768f3d99b684b3513452975a9a7100845d0 Mon Sep 17 00:00:00 2001 From: Zero Date: Mon, 16 Aug 2021 11:19:24 +0800 Subject: [PATCH 28/29] let hook env function return new entry script path --- Flow.Launcher.Plugin.PythonTemplate/commands.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/commands.py b/Flow.Launcher.Plugin.PythonTemplate/commands.py index a15e41e..1322972 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/commands.py +++ b/Flow.Launcher.Plugin.PythonTemplate/commands.py @@ -36,7 +36,6 @@ # file build_ignore_path = basedir / ".buildignore" build_ignore_path.touch() # if no existed, would be created -entry_src = basedir / PLUGIN_EXECUTE_FILENAME plugin_info_path = basedir / "plugin.json" zip_path = build_path / f"{PLUGIN_ZIP_NAME}" @@ -71,7 +70,7 @@ def get_build_ignores(comment: str = "#") -> List[str]: return ignore_list -def hook_env_snippet(temp_path): +def hook_env_snippet(exec_file: str = PLUGIN_EXECUTE_FILENAME) -> str: """Hook lib folder path to python system environment variable path.""" env_snippet = dedent( @@ -84,10 +83,14 @@ def hook_env_snippet(temp_path): """ ) + temp_path = build_path / exec_file + entry_src = basedir / exec_file with open(entry_src, "r") as f_r: with open(temp_path, "w") as f_w: f_w.write(env_snippet + f_r.read()) + return temp_path + @click.group() def translate(): @@ -166,8 +169,7 @@ def build(): ignore_string = "'" + "' '".join(ignore_list) + "'" os.system(f"zip -r {zip_path} . -x {ignore_string}") - entry_src_hooked = build_path / PLUGIN_EXECUTE_FILENAME - hook_env_snippet(entry_src_hooked) + entry_src_hooked = hook_env_snippet() os.system(f"zip -j {zip_path} {entry_src_hooked}") entry_src_hooked.unlink() From 63b51d30e87db77a1a726270bd88ddca82cb8645 Mon Sep 17 00:00:00 2001 From: Zero Date: Mon, 16 Aug 2021 11:32:57 +0800 Subject: [PATCH 29/29] merge env related command to env group --- .../.github/workflows/release.yml | 5 +-- .../commands.py | 44 ++++++++++++------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/Flow.Launcher.Plugin.PythonTemplate/.github/workflows/release.yml b/Flow.Launcher.Plugin.PythonTemplate/.github/workflows/release.yml index a8e7166..7cbcaeb 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/.github/workflows/release.yml +++ b/Flow.Launcher.Plugin.PythonTemplate/.github/workflows/release.yml @@ -21,11 +21,10 @@ jobs: - name: Set up Environment run: | python -m pip install --upgrade pip - pip install -r requirements.txt - pip install -r requirements-dev.txt + python commands.py setup-env - name: Install Dependencies to Local - run: python commands.py install-dependencies + run: python commands.py setup-env-to-lib - name: Compile all languages run: python commands.py compile diff --git a/Flow.Launcher.Plugin.PythonTemplate/commands.py b/Flow.Launcher.Plugin.PythonTemplate/commands.py index 75682b6..73b98f8 100644 --- a/Flow.Launcher.Plugin.PythonTemplate/commands.py +++ b/Flow.Launcher.Plugin.PythonTemplate/commands.py @@ -140,22 +140,6 @@ def plugin(): ... -@plugin.command() -def install_dependencies(): - """Install dependencies to local.""" - - os.system(f"pip install -r requirements.txt -t {lib_path} --upgrade") - - click.echo("Done.") - -@plugin.command() -def setup_dev_env(): - """Set up the development environment for the first time. This installs requirements-dev.txt """ - - os.system(f"pip install -r requirements-dev.txt --upgrade") - - click.echo("Dev environment ready to go.") - @plugin.command() def gen_plugin_info(): """Auto generate the 'plugin.json' file for Flow.""" @@ -183,6 +167,33 @@ def build(): click.echo("Done.") +@click.group() +def env(): + ... + + +@env.command() +def setup_env(): + """ + Set up the environment for the first time. + This installs requirements.txt and requirements-dev.txt + """ + + os.system("pip install -r requirements.txt --upgrade") + os.system("pip install -r requirements-dev.txt --upgrade") + + click.echo("Environment ready to go.") + + +@env.command() +def setup_env_to_lib(): + """Install dependencies to local.""" + + os.system(f"pip install -r requirements.txt -t {lib_path} --upgrade") + + click.echo("Done.") + + @click.group() def clean(): """Clean commands.""" @@ -212,6 +223,7 @@ def clean_pyc(): cli = click.CommandCollection( sources=[ clean, + env, plugin, translate, ]