1+ #!/usr/bin/env -S uv run --script
2+ # /// script
3+ # requires-python = "~=3.14"
4+ # dependencies = [
5+ # "falcon",
6+ # ]
7+ # ///
8+
19import logging
210from pathlib import Path
311from typing import Iterable
614
715import _falcon_helpers
816
9- from .make_ver import LANGUAGES
10- from .language_versions import LanguageVersions
11- from .project_versions import ProjectVersions
17+ from make_ver .make_ver import LANGUAGES
18+ from make_ver .language_versions import LanguageVersions
19+ from make_ver .project_versions import ProjectVersions
1220
1321log = logging .getLogger (__name__ )
1422
@@ -89,13 +97,13 @@ def _filter_file(f):
8997
9098# Setup App -------------------------------------------------------------------
9199
92- def create_wsgi_app (project_path = None , language_path = None , ** kwargs ):
100+ def create_wsgi_app (path_project : Path , path_language : Path , path_static : Path , ** kwargs ):
93101 app = falcon .App ()
94102 app .add_route (r'/' , IndexResource ())
95- app .add_static_route (r'/static' , str (Path ( 'static' ) .resolve ()))
96- app .add_route (r'/api/v1/language_reference.json' , LanguageReferenceResource (language_path ))
97- app .add_route (r'/api/v1/projects.json' , ProjectListResource (project_path ))
98- _falcon_helpers .add_sink (app , r'/api/v1/projects/' , ProjectResource (project_path ), func_path_normalizer = _falcon_helpers .func_path_normalizer_no_extension )
103+ app .add_static_route (r'/static' , str (path_static .resolve ()))
104+ app .add_route (r'/api/v1/language_reference.json' , LanguageReferenceResource (path_language ))
105+ app .add_route (r'/api/v1/projects.json' , ProjectListResource (path_project ))
106+ _falcon_helpers .add_sink (app , r'/api/v1/projects/' , ProjectResource (path_project ), func_path_normalizer = _falcon_helpers .func_path_normalizer_no_extension )
99107 _falcon_helpers .update_json_handlers (app )
100108 # TODO: Currently unable to drop into debugger on error - investigate?
101109 # https://falcon.readthedocs.io/en/stable/api/app.html#falcon.App.add_error_handler
@@ -109,9 +117,9 @@ def export(output_path: Path = Path()) -> None:
109117 test_client = falcon_testing .TestClient (app )
110118 def read_write (url ):
111119 log .info (url )
112- path = output_path .joinpath (url .strip ('/' ))
113- path .parent .mkdir (parents = True , exist_ok = True )
114- with path .open ('wt' , encoding = "utf-8" ) as filehandle :
120+ file_path = output_path .joinpath (url .strip ('/' ))
121+ file_path .parent .mkdir (parents = True , exist_ok = True )
122+ with file_path .open ('wt' , encoding = "utf-8" ) as filehandle :
115123 data = test_client .simulate_get (url )
116124 filehandle .write (data .text )
117125 return data .json
@@ -133,13 +141,14 @@ def get_args():
133141 ''' ,
134142 )
135143
136- parser .add_argument ('project_path' , action = 'store' , default = './' , help = '' )
137- parser .add_argument ('language_path' , action = 'store' , default = './' , help = '' )
144+ parser .add_argument ('--path_project' , action = 'store' , default = './' , help = '' , type = Path )
145+ parser .add_argument ('--path_language' , action = 'store' , default = './' , help = '' , type = Path )
146+ parser .add_argument ('--path_static' , action = 'store' , default = './' , help = '' , type = Path )
138147
139148 parser .add_argument ('--host' , action = 'store' , default = '0.0.0.0' , help = '' )
140149 parser .add_argument ('--port' , action = 'store' , default = 8000 , type = int , help = '' )
141150
142- parser .add_argument ('--export' , action = 'store' , type = Path )
151+ parser .add_argument ('--export' , action = 'store' , default = None , type = Path )
143152
144153 parser .add_argument ('--log_level' , action = 'store' , type = int , help = 'loglevel of output to stdout' , default = logging .INFO )
145154
0 commit comments