File tree Expand file tree Collapse file tree 2 files changed +7
-7
lines changed
Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ async def program(api):
1818 await api.print(' Hello world!' )
1919```
2020
21+ There must be a separate file for each program with ` program ` coroutine defined.
22+
2123In minecraft, open up any computer and type:
2224
2325``` bash
@@ -45,6 +47,3 @@ async def program(api):
4547 # and this snippet takes approximately 2 seconds to complete.
4648 await asyncio.gather(api.os.sleep(2 ), api.os.sleep(2 ))
4749```
48-
49- TODO:
50- - use current dir for programs
Original file line number Diff line number Diff line change 44from aiohttp import web
55from traceback import print_exc
66from os .path import getmtime , join , dirname , abspath
7- from os import listdir
7+ from os import listdir , getcwd
88import importlib
99import argparse
1010
3333
3434THIS_DIR = dirname (abspath (__file__ ))
3535LUA_FILE = join (THIS_DIR , 'back.lua' )
36+ CURRENT_DIR = getcwd ()
3637
3738
3839exchange = {}
@@ -57,11 +58,11 @@ async def lua_json(request):
5758
5859
5960def program_filenames ():
60- return [f [:- 3 ] for f in listdir (join ( THIS_DIR , 'programs' ) ) if f .endswith ('.py' ) and f != '__init__.py' ]
61+ return [f [:- 3 ] for f in listdir (CURRENT_DIR ) if f .endswith ('.py' ) and f != '__init__.py' ]
6162
6263
6364def m_filename (m ):
64- return join (THIS_DIR , 'programs' , '{}.py' .format (m ))
65+ return join (CURRENT_DIR , '{}.py' .format (m ))
6566
6667
6768async def reload_all_modules (module_map ):
@@ -74,7 +75,7 @@ async def reload_all_modules(module_map):
7475
7576 # loading new modules
7677 for m in nxt - prev :
77- module_map [m ] = importlib .import_module ('programs.{}' . format ( m ) )
78+ module_map [m ] = importlib .import_module (m )
7879 module_map [m ]._mtime_mark = getmtime (m_filename (m ))
7980 print ('Loaded {}' .format (m ))
8081
You can’t perform that action at this time.
0 commit comments