11#!/usr/bin/env python
22
3+ import importlib
34import json
45import subprocess
6+ import sys
57from pathlib import Path
68from uuid import uuid4
79from zipfile import ZipFile
810
911import click
12+ from ualfred import Workflow3
1013
11- FILENAME_LIST = (
12- "info.plist" ,
13- "entry_point.py" ,
14- "core.py" ,
15- )
16-
17- PATH_LIST = (
18- "arrow" ,
19- "backports" ,
20- "dateutil" ,
21- "ualfred" ,
22- )
23-
24-
25- # def main():
26- # with open("version") as f:
27- # version = f.readline().rstrip("\n\r ")
28- #
29- # zip_filename = f"time-converter.{version}.alfredworkflow"
30- # z = ZipFile(zip_filename, mode="w")
31- #
32- # for filename in FILENAME_LIST:
33- # z.write(filename)
34- #
35- # for pathname in PATH_LIST:
36- # for root, dirs, files in walk(pathname):
37- # for filename in files:
38- # if filename.rfind(".pyc") == -1:
39- # z.write(join(root, filename))
40- #
41- # z.close()
42- #
43- # print(f"Create Alfred workflow({zip_filename}) finished.")
14+ WORKFLOW_BASE_FILES = ["info.plist" , "workflow_main.py" , "__init__.py" ]
15+ AFW_ENTRY_POINT_FILE = "afw_entry_point.py"
16+ AFW_REQUIREMENTS = []
4417
4518
4619@click .group ()
@@ -76,6 +49,7 @@ def build(workflow_path: str):
7649
7750 requirements .append (line )
7851
52+ requirements += AFW_REQUIREMENTS
7953 for requirement in requirements :
8054 subprocess .run (
8155 ["pip" , "install" , "-U" , f"--target={ str (build_path )} " , requirement ],
@@ -99,22 +73,31 @@ def build(workflow_path: str):
9973 package_file .write (file , arcname = arc_name )
10074
10175 print ("Add workflow files..." )
102- workflow_files : list [str ] = [ "info.plist" , "main.py" , "__init__.py" ]
76+ workflow_files : list [str ] = WORKFLOW_BASE_FILES
10377 icon_file = package_info .get ("icon" )
10478 if icon_file :
10579 workflow_files .append (icon_file )
10680
10781 for file in workflow_files :
10882 package_file .write (workflow_path .joinpath (file ), arcname = file )
10983
110- package_file .write ("entry_point.py" )
84+ package_file .write (AFW_ENTRY_POINT_FILE )
11185
11286 package_file .close ()
11387 print (f"Create Alfred workflow[{ package_path } ] finished." )
11488
11589
11690@cli .command ()
117- def test ():
91+ @click .argument ("workflow_path" )
92+ @click .argument ("query" )
93+ def test (workflow_path : str , query : str ):
94+ try :
95+ module = importlib .import_module (workflow_path )
96+ except ImportError as e :
97+ print (e )
98+ pass
99+
100+ print (module .call_workflow (wf = Workflow3 ()))
118101 click .echo ("test...todo" )
119102
120103
0 commit comments