@@ -69,7 +69,7 @@ def make_application(debug=None, apps_dir='apps', project_dir=None,
6969 include_apps = None , debug_console = True , settings_file = None ,
7070 local_settings_file = None , start = True , default_settings = None ,
7171 dispatcher_cls = None , dispatcher_kwargs = None , debug_cls = None , debug_kwargs = None ,
72- reuse = True , verbose = False ):
72+ reuse = True , verbose = False , pythonpath = None ):
7373 """
7474 Make an application object
7575 """
@@ -92,12 +92,19 @@ def make_application(debug=None, apps_dir='apps', project_dir=None,
9292 if not project_dir :
9393 project_dir = os .path .abspath (os .path .normpath (os .path .abspath (os .path .join (apps_dir , '..' ))))
9494
95+ if pythonpath :
96+ if isinstance (pythonpath , str ):
97+ pythonpath = pythonpath .split (';' )
98+ for x in pythonpath :
99+ if x not in sys .path :
100+ sys .path .insert (0 , x )
101+
95102 if project_dir not in sys .path :
96103 sys .path .insert (0 , project_dir )
97104
98105 if apps_dir not in sys .path :
99106 sys .path .insert (0 , apps_dir )
100-
107+
101108 install_config (apps_dir )
102109
103110 application = app = dispatcher_cls (apps_dir = apps_dir ,
@@ -159,14 +166,15 @@ def make_application(debug=None, apps_dir='apps', project_dir=None,
159166
160167def make_simple_application (apps_dir = 'apps' , project_dir = None , include_apps = None ,
161168 settings_file = '' , local_settings_file = '' ,
162- default_settings = None , dispatcher_cls = None , dispatcher_kwargs = None , reuse = True ):
169+ default_settings = None , dispatcher_cls = None , dispatcher_kwargs = None , reuse = True ,
170+ pythonpath = None ):
163171 settings = {'ORM/AUTO_DOTRANSACTION' :False }
164172 settings .update (default_settings or {})
165173 return make_application (apps_dir = apps_dir , project_dir = project_dir ,
166174 include_apps = include_apps , debug_console = False , debug = False ,
167175 settings_file = settings_file , local_settings_file = local_settings_file ,
168176 start = False , default_settings = settings , dispatcher_cls = dispatcher_cls ,
169- dispatcher_kwargs = dispatcher_kwargs , reuse = reuse )
177+ dispatcher_kwargs = dispatcher_kwargs , reuse = reuse , pythonpath = pythonpath )
170178
171179class MakeAppCommand (Command ):
172180 name = 'makeapp'
@@ -721,8 +729,8 @@ def _render_tempfile(self, tmplname, vars=None):
721729
722730class RunserverCommand (Command ):
723731 name = 'runserver'
724- help = 'Start a new development server.'
725- args = ''
732+ help = 'Start a new development server. And it can also startup an app without a whole project. '
733+ args = '[appname appname ...] '
726734 option_list = (
727735 make_option ('-h' , dest = 'hostname' , default = 'localhost' ,
728736 help = 'Hostname or IP.' ),
@@ -754,17 +762,35 @@ class RunserverCommand(Command):
754762 help = 'Start uliweb server with coverage.' ),
755763 )
756764 develop = False
765+ check_apps_dirs = False
757766
758767 def handle (self , options , global_options , * args ):
759768 import logging
760769 from logging import StreamHandler
761770 from uliweb .utils .coloredlog import ColoredFormatter
762-
771+ from uliweb .utils .common import check_apps_dir
772+ import subprocess
773+
763774 if self .develop :
764775 include_apps = ['plugs.develop' ]
765776 else :
766777 include_apps = []
767-
778+
779+ #add appname runable support, it'll automatically create a default project
780+ #if you want to startup an app, it'll use a temp directory, default is
781+ if args :
782+ include_apps .extend (args )
783+ old_apps_dir = os .path .abspath (global_options .apps_dir )
784+ project_home_dir = os .path .join (os .path .expanduser ('~' ), '.uliweb' )
785+ if not os .path .exists (project_home_dir ):
786+ os .makedirs (project_home_dir )
787+
788+ subprocess .call ('uliweb makeproject -y project' , cwd = project_home_dir , shell = True )
789+ global_options .project = os .path .join (project_home_dir , 'project' )
790+ global_options .apps_dir = os .path .join (global_options .project , 'apps' )
791+
792+ check_apps_dir (global_options .apps_dir )
793+
768794 extra_files = collect_files (global_options , global_options .apps_dir , self .get_apps (global_options , include_apps ))
769795
770796 if options .color :
@@ -781,10 +807,10 @@ def format(self, record):
781807 setattr (StreamHandler , 'format' , format )
782808
783809 def get_app (debug_cls = None ):
784- return make_application (options .debug , project_dir = global_options .project ,
810+ return make_application (options .debug , project_dir = global_options .project ,
785811 include_apps = include_apps , settings_file = global_options .settings ,
786812 local_settings_file = global_options .local_settings , debug_cls = debug_cls ,
787- verbose = global_options .verbose )
813+ verbose = global_options .verbose , pythonpath = old_apps_dir )
788814
789815 cov = None
790816 try :
0 commit comments