diff --git a/dependencies.md b/dependencies.md new file mode 100644 index 0000000..f0289cc --- /dev/null +++ b/dependencies.md @@ -0,0 +1,19 @@ +# Dependencies for third-party packages + +## apscheduler + +``` +setuptools >= 0.7 +six >= 1.4.0 +pytz +tzlocal >= 1.2 +``` + +## ptpython + +``` +appdirs +jedi>=0.9.0 +prompt_toolkit>=3.0.0,<3.1.0 +pygments +``` \ No newline at end of file diff --git a/dependencies.txt b/dependencies.txt deleted file mode 100644 index 8b13789..0000000 --- a/dependencies.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/test.py b/src/test.py index ef2949c..4492b5f 100644 --- a/src/test.py +++ b/src/test.py @@ -1,7 +1,6 @@ import os import sys import pprint -import dateutil #from zasd.filesystems.zfs import ZFSFilesystem #from zasd.apsched import AsyncIOPriorityScheduler diff --git a/src/zasd/__init__.py b/src/zasd/__init__.py index 4abcf66..02f0836 100644 --- a/src/zasd/__init__.py +++ b/src/zasd/__init__.py @@ -22,13 +22,6 @@ from zasd.filesystem import FilesystemRegistry from zasd.log import configure_logging, log from zasd.repl import repl -event_loop = asyncio.get_event_loop() -asyncio.ensure_future(repl()) - -scheduler = AsyncIOPriorityScheduler( - event_loop = event_loop, - executors = {'default': AsyncIOPriorityExecutor()}) - async def main(): #event_loop.add_signal_handler( # signal.SIGINT, partial(signal_handler, 'SIGINT')) @@ -47,14 +40,19 @@ async def main(): #if isatty(): # event_loop.create_task(spinner) +event_loop = asyncio.get_event_loop() + +scheduler = AsyncIOPriorityScheduler( + event_loop = event_loop, + executors = {'default': AsyncIOPriorityExecutor()}) + +asyncio.ensure_future(repl()) asyncio.ensure_future(main()) try: event_loop.run_forever() finally: log.info('Terminating') - print(file=stderr) - event_loop.close() def signal_handler(signame): log.info('Received %s', signame) diff --git a/src/zasd/repl.py b/src/zasd/repl.py index a04f484..ccb1771 100644 --- a/src/zasd/repl.py +++ b/src/zasd/repl.py @@ -1,13 +1,37 @@ ''' Interactive Python interpreter ''' -from typing import MutableMapping, Any +from typing import MutableMapping, Any, Callable, ContextManager, Dict, Optional +import builtins import asyncio -import ptpython.repl import re +from ptpython.repl import PythonRepl +from prompt_toolkit.patch_stdout import patch_stdout as patch_stdout_context + import zasd.config as config +@asyncio.coroutine +async def repl(): + _globals = dict( + config = DictObject(config.reference(), 'config')) + + _locals = dict(a = 'b') + + # Create REPL. + _repl = PythonRepl( + get_globals=lambda: _globals, + get_locals=lambda: _locals, + vi_mode=True) + _repl.confirm_exit = False + _repl.highlight_matching_parenthesis = True + _repl.insert_blank_line_after_output = False + try: + with patch_stdout_context(): + await _repl.run_async() + except EOFError: + quit() + class DictObject: def __init__(self, dictionary: MutableMapping[str, Any], name): DictObject._dictionary = dictionary @@ -47,16 +71,3 @@ class DictObject: obj[key], name, level + 1, path = path + [key]) strs.append(value) return '\n'.join(strs) - -@asyncio.coroutine -def repl(): - _globals = dict( - config = DictObject(config.reference(), 'config') - ) - _locals = dict() - try: - yield from ptpython.repl.embed( - globals=_globals, locals=_locals, return_asyncio_coroutine=True, - patch_stdout=True, vi_mode=True) - except EOFError: - asyncio.get_event_loop().stop() \ No newline at end of file