From 66148650ed561bdba0bd0f7419aae7a1c52a32b1 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Fri, 10 Apr 2015 21:17:03 +0300 Subject: [PATCH] setup.py: fix entry_point to use amodem/__main__.py --- amodem-cli => amodem/__main__.py | 32 +++++++++++++++++++------------- setup.py | 2 +- 2 files changed, 20 insertions(+), 14 deletions(-) rename amodem-cli => amodem/__main__.py (95%) diff --git a/amodem-cli b/amodem/__main__.py similarity index 95% rename from amodem-cli rename to amodem/__main__.py index 7de9b25..dca1e56 100755 --- a/amodem-cli +++ b/amodem/__main__.py @@ -94,8 +94,8 @@ def get_volume_cmd(args): return c[args.command] -class _DummyInterface(object): - ''' Audio interface mock, to skip shared library loading. ''' +class _DummyContextManager(object): + def __enter__(self): pass @@ -103,19 +103,14 @@ class _DummyInterface(object): pass -def _main(): - fmt = ('Audio OFDM MODEM: {0:.1f} kb/s ({1:d}-QAM x {2:d} carriers) ' - 'Fs={3:.1f} kHz') - description = fmt.format(config.modem_bps / 1e3, len(config.symbols), - config.Nfreq, config.Fs / 1e3) - interface = audio.Interface(config=config) +def wrap(cls, stream, enable): + return cls(stream) if enable else stream + +def create_parser(description, interface): p = argparse.ArgumentParser(description=description) subparsers = p.add_subparsers() - def wrap(cls, stream, enable): - return cls(stream) if enable else stream - # Modulator sender = subparsers.add_parser( 'send', help='modulate binary data into audio signal.') @@ -182,6 +177,17 @@ def _main(): if argcomplete: argcomplete.autocomplete(p) + return p + + +def _main(): + fmt = ('Audio OFDM MODEM: {0:.1f} kb/s ({1:d}-QAM x {2:d} carriers) ' + 'Fs={3:.1f} kHz') + description = fmt.format(config.modem_bps / 1e3, len(config.symbols), + config.Nfreq, config.Fs / 1e3) + interface = audio.Interface(config=config) + p = create_parser(description, interface) + args = p.parse_args() if args.verbose == 0: level, fmt = 'INFO', '%(message)s' @@ -200,11 +206,11 @@ def _main(): args.pylab = None if getattr(args, 'plot', False): - import pylab + import pylab # pylint: disable=import-error args.pylab = pylab if args.audio_library == '-': - interface = _DummyInterface() + interface = _DummyContextManager() else: interface.load(args.audio_library) diff --git a/setup.py b/setup.py index 9cd3eda..37fed24 100644 --- a/setup.py +++ b/setup.py @@ -42,5 +42,5 @@ setup( 'Topic :: System :: Networking', 'Topic :: Communications', ], - scripts=['amodem-cli'], + entry_points={'console_scripts': ['amodem = amodem.__main__:_main']}, )