diff --git a/powerline/__init__.py b/powerline/__init__.py index 7f8932dd..af0600a4 100644 --- a/powerline/__init__.py +++ b/powerline/__init__.py @@ -279,12 +279,14 @@ class Powerline(object): colorschemes, render module (``powerline.renders.{ext}``). :param str renderer_module: Overrides renderer module (defaults to ``ext``). Should be the name of - the package imported like this: ``powerline.renders.{render_module}``. + the package imported like this: ``powerline.renderers.{render_module}``. If this parameter contains a dot, ``powerline.renderers.`` is not prepended. There is also a special case for renderers defined in toplevel modules: ``foo.`` (note: dot at the end) tries to get renderer from module ``foo`` (because ``foo`` (without dot) tries to get renderer - from module ``powerline.renderers.foo``). + from module ``powerline.renderers.foo``). When ``.foo`` (with leading + dot) variant is used ``renderer_module`` will be + ``powerline.renderers.{ext}{renderer_module}``. :param bool run_once: Determines whether .renderer.render() method will be run only once during python session. @@ -307,15 +309,20 @@ class Powerline(object): shutdown_event=None, config_loader=None): self.ext = ext - self.renderer_module = renderer_module or ext self.run_once = run_once self.logger = logger self.use_daemon_threads = use_daemon_threads - if '.' not in self.renderer_module: - self.renderer_module = 'powerline.renderers.' + self.renderer_module - elif self.renderer_module[-1] == '.': - self.renderer_module = self.renderer_module[:-1] + if not renderer_module: + self.renderer_module = 'powerline.renderers.' + ext + elif '.' not in renderer_module: + self.renderer_module = 'powerline.renderers.' + renderer_module + elif renderer_module.startswith('.'): + self.renderer_module = 'powerline.renderers.' + ext + renderer_module + elif renderer_module.endswith('.'): + self.renderer_module = renderer_module[:-1] + else: + self.renderer_module = renderer_module self.find_config_files = generate_config_finder(self.get_config_paths) diff --git a/powerline/bindings/bash/powerline.sh b/powerline/bindings/bash/powerline.sh index e44d9da2..1a5ab763 100644 --- a/powerline/bindings/bash/powerline.sh +++ b/powerline/bindings/bash/powerline.sh @@ -53,7 +53,7 @@ _powerline_prompt() { # Arguments: side, last_exit_code, jobnum $POWERLINE_COMMAND shell $1 \ --width="${COLUMNS:-$(_powerline_columns_fallback)}" \ - -r bash_prompt \ + -r.bash \ --last_exit_code=$2 \ --jobnum=$3 \ --renderer_arg="client_id=$$" @@ -64,7 +64,7 @@ _powerline_set_prompt() { local jobnum="$(jobs -p|wc -l)" PS1="$(_powerline_prompt aboveleft $last_exit_code $jobnum)" if test -n "$POWERLINE_SHELL_CONTINUATION$POWERLINE_BASH_CONTINUATION" ; then - PS2="$(_powerline_local_prompt left -rbash_prompt $last_exit_code $jobnum continuation)" + PS2="$(_powerline_local_prompt left -r.bash $last_exit_code $jobnum continuation)" fi if test -n "$POWERLINE_SHELL_SELECT$POWERLINE_BASH_SELECT" ; then PS3="$(_powerline_local_prompt left '' $last_exit_code $jobnum select)" @@ -79,7 +79,7 @@ _powerline_setup_prompt() { fi test "x$PROMPT_COMMAND" != "x${PROMPT_COMMAND%_powerline_set_prompt*}" || PROMPT_COMMAND=$'_powerline_set_prompt\n'"${PROMPT_COMMAND}" - PS2="$(_powerline_local_prompt left -rbash_prompt 0 0 continuation)" + PS2="$(_powerline_local_prompt left -r.bash 0 0 continuation)" PS3="$(_powerline_local_prompt left '' 0 0 select)" } diff --git a/powerline/bindings/shell/powerline.sh b/powerline/bindings/shell/powerline.sh index 3fc2b434..8940c028 100644 --- a/powerline/bindings/shell/powerline.sh +++ b/powerline/bindings/shell/powerline.sh @@ -122,8 +122,8 @@ _powerline_tmux_set_columns() { _powerline_set_renderer_arg() { case "$1" in - bb|ash) _POWERLINE_RENDERER_ARG="-rbash_prompt" ;; - mksh|ksh) _POWERLINE_RENDERER_ARG="-rksh_prompt" ;; + bb|ash) _POWERLINE_RENDERER_ARG="-r .bash" ;; + mksh|ksh) _POWERLINE_RENDERER_ARG="-r .ksh" ;; bash|dash) _POWERLINE_RENDERER_ARG= ;; esac } diff --git a/powerline/bindings/tcsh/powerline.tcsh b/powerline/bindings/tcsh/powerline.tcsh index 48155466..ac93341b 100644 --- a/powerline/bindings/tcsh/powerline.tcsh +++ b/powerline/bindings/tcsh/powerline.tcsh @@ -27,8 +27,8 @@ if ( { $POWERLINE_CONFIG shell --shell=tcsh uses prompt } ) then alias _powerline_above '$POWERLINE_COMMAND shell above --renderer_arg=client_id=$$ --last_exit_code=$POWERLINE_STATUS --width=$POWERLINE_COLUMNS' endif - alias _powerline_set_prompt 'set prompt="`$POWERLINE_COMMAND shell left -r tcsh_prompt --renderer_arg=client_id=$$ --last_exit_code=$POWERLINE_STATUS --width=$POWERLINE_COLUMNS`"' - alias _powerline_set_rprompt 'set rprompt="`$POWERLINE_COMMAND shell right -r tcsh_prompt --renderer_arg=client_id=$$ --last_exit_code=$POWERLINE_STATUS --width=$POWERLINE_COLUMNS` "' + alias _powerline_set_prompt 'set prompt="`$POWERLINE_COMMAND shell left -r .tcsh --renderer_arg=client_id=$$ --last_exit_code=$POWERLINE_STATUS --width=$POWERLINE_COLUMNS`"' + alias _powerline_set_rprompt 'set rprompt="`$POWERLINE_COMMAND shell right -r .tcsh --renderer_arg=client_id=$$ --last_exit_code=$POWERLINE_STATUS --width=$POWERLINE_COLUMNS` "' alias _powerline_set_columns 'set POWERLINE_COLUMNS=`stty size|cut -d" " -f2` ; set POWERLINE_COLUMNS=`expr $POWERLINE_COLUMNS - 2`' alias precmd 'set POWERLINE_STATUS=$? ; '"`alias precmd`"' ; _powerline_set_columns ; _powerline_above ; _powerline_set_prompt ; _powerline_set_rprompt' diff --git a/powerline/bindings/zsh/__init__.py b/powerline/bindings/zsh/__init__.py index 444490b5..b6ccde1a 100644 --- a/powerline/bindings/zsh/__init__.py +++ b/powerline/bindings/zsh/__init__.py @@ -26,7 +26,7 @@ def get_var_config(var): class Args(object): __slots__ = ('last_pipe_status', 'last_exit_code') ext = ['shell'] - renderer_module = 'zsh_prompt' + renderer_module = '.zsh' @property def config(self): diff --git a/powerline/bindings/zsh/powerline.zsh b/powerline/bindings/zsh/powerline.zsh index 0bc2c50e..8a7078f1 100644 --- a/powerline/bindings/zsh/powerline.zsh +++ b/powerline/bindings/zsh/powerline.zsh @@ -129,7 +129,7 @@ _powerline_setup_prompt() { POWERLINE_COMMAND=( "$($POWERLINE_CONFIG shell command)" ) fi - local add_args='-r zsh_prompt' + local add_args='-r .zsh' add_args+=' --last_exit_code=$?' add_args+=' --last_pipe_status="$pipestatus"' add_args+=' --renderer_arg="client_id=$$"' diff --git a/powerline/ipython.py b/powerline/ipython.py index 5fc66b34..bc244d6d 100644 --- a/powerline/ipython.py +++ b/powerline/ipython.py @@ -26,7 +26,7 @@ class IpythonPowerline(Powerline): def __init__(self, is_prompt, old_widths): super(IpythonPowerline, self).__init__( 'ipython', - renderer_module=('ipython_prompt' if is_prompt else 'ipython'), + renderer_module=('.prompt' if is_prompt else None), use_daemon_threads=True ) self.old_widths = old_widths diff --git a/powerline/lint/__init__.py b/powerline/lint/__init__.py index a1749790..891a7d8f 100644 --- a/powerline/lint/__init__.py +++ b/powerline/lint/__init__.py @@ -432,7 +432,7 @@ def check_matcher_func(ext, match_name, data, context, echoerr): match_function = match_name with WithPath(import_paths): try: - func = getattr(__import__(match_module, fromlist=[match_function]), unicode(match_function)) + func = getattr(__import__(str(match_module), fromlist=[str(match_function)]), str(match_function)) except ImportError: echoerr(context='Error while loading matcher functions', problem='failed to load module {0}'.format(match_module), @@ -823,7 +823,7 @@ def check_key_compatibility(segment, data, context, echoerr): def check_segment_module(module, data, context, echoerr): with WithPath(data['import_paths']): try: - __import__(unicode(module)) + __import__(str(module)) except ImportError as e: if echoerr.logger.level >= logging.DEBUG: echoerr.logger.exception(e) @@ -875,7 +875,7 @@ def import_segment(name, data, context, echoerr, module=None): with WithPath(data['import_paths']): try: - func = getattr(__import__(unicode(module), fromlist=[unicode(name)]), unicode(name)) + func = getattr(__import__(str(module), fromlist=[str(name)]), str(name)) except ImportError: echoerr(context='Error while checking segments (key {key})'.format(key=context_key(context)), problem='failed to import module {0}'.format(module), diff --git a/powerline/renderers/ipython.py b/powerline/renderers/ipython/__init__.py similarity index 100% rename from powerline/renderers/ipython.py rename to powerline/renderers/ipython/__init__.py diff --git a/powerline/renderers/ipython_prompt.py b/powerline/renderers/ipython/prompt.py similarity index 100% rename from powerline/renderers/ipython_prompt.py rename to powerline/renderers/ipython/prompt.py diff --git a/powerline/renderers/shell.py b/powerline/renderers/shell/__init__.py similarity index 100% rename from powerline/renderers/shell.py rename to powerline/renderers/shell/__init__.py diff --git a/powerline/renderers/bash_prompt.py b/powerline/renderers/shell/bash.py similarity index 100% rename from powerline/renderers/bash_prompt.py rename to powerline/renderers/shell/bash.py diff --git a/powerline/renderers/ksh_prompt.py b/powerline/renderers/shell/ksh.py similarity index 100% rename from powerline/renderers/ksh_prompt.py rename to powerline/renderers/shell/ksh.py diff --git a/powerline/renderers/tcsh_prompt.py b/powerline/renderers/shell/tcsh.py similarity index 87% rename from powerline/renderers/tcsh_prompt.py rename to powerline/renderers/shell/tcsh.py index adbb91c9..261b081a 100644 --- a/powerline/renderers/tcsh_prompt.py +++ b/powerline/renderers/shell/tcsh.py @@ -2,7 +2,7 @@ from __future__ import absolute_import, unicode_literals -from powerline.renderers.zsh_prompt import ZshPromptRenderer +from powerline.renderers.shell.zsh import ZshPromptRenderer class TcshPromptRenderer(ZshPromptRenderer): diff --git a/powerline/renderers/zsh_prompt.py b/powerline/renderers/shell/zsh.py similarity index 100% rename from powerline/renderers/zsh_prompt.py rename to powerline/renderers/shell/zsh.py diff --git a/powerline/shell.py b/powerline/shell.py index 513a6974..25d07258 100644 --- a/powerline/shell.py +++ b/powerline/shell.py @@ -50,7 +50,7 @@ def get_argparser(parser=None, *args, **kwargs): p.add_argument('ext', nargs=1, help='Extension: application for which powerline command is launched (usually `shell\' or `tmux\')') p.add_argument('side', nargs='?', choices=('left', 'right', 'above', 'aboveleft'), help='Side: `left\' and `right\' represent left and right side respectively, `above\' emits lines that are supposed to be printed just above the prompt and `aboveleft\' is like concatenating `above\' with `left\' with the exception that only one Python instance is used in this case.') p.add_argument('-r', '--renderer_module', metavar='MODULE', type=str, - help='Renderer module. Usually something like `bash_prompt\' or `zsh_prompt\', is supposed to be set only in shell-specific bindings file.') + help='Renderer module. Usually something like `.bash\' or `.zsh\', is supposed to be set only in shell-specific bindings file.') p.add_argument('-w', '--width', type=int, help='Maximum prompt with. Triggers truncation of some segments') p.add_argument('--last_exit_code', metavar='INT', type=int, help='Last exit code') p.add_argument('--last_pipe_status', metavar='LIST', default='', type=lambda s: [int(status) for status in s.split()], help='Like above, but is supposed to contain space-separated array of statuses, representing exit statuses of commands in one pipe.') diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index f1ff683a..5af43eee 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -42,7 +42,7 @@ class TestParser(TestCase): (['shell', '--config_path'], 'expected one argument'), (['shell', '--renderer_arg'], 'expected one argument'), (['shell', '--jobnum'], 'expected one argument'), - (['-r', 'zsh_prompt'], 'too few arguments|the following arguments are required: ext'), + (['-r', '.zsh'], 'too few arguments|the following arguments are required: ext'), (['shell', '--last_exit_code', 'i'], 'invalid int value'), (['shell', '--last_pipe_status', '1 i'], 'invalid value'), ]: @@ -57,12 +57,12 @@ class TestParser(TestCase): err = StrIO() with replace_attr(sys, 'stdout', out, 'stderr', err): for argv, expargs in [ - (['shell'], {'ext': ['shell']}), - (['shell', '-r', 'zsh_prompt'], {'ext': ['shell'], 'renderer_module': 'zsh_prompt'}), + (['shell'], {'ext': ['shell']}), + (['shell', '-r', '.zsh'], {'ext': ['shell'], 'renderer_module': '.zsh'}), ([ 'shell', 'left', - '-r', 'zsh_prompt', + '-r', '.zsh', '--last_exit_code', '10', '--last_pipe_status', '10 20 30', '--jobnum=10', @@ -76,7 +76,7 @@ class TestParser(TestCase): ], { 'ext': ['shell'], 'side': 'left', - 'renderer_module': 'zsh_prompt', + 'renderer_module': '.zsh', 'last_exit_code': 10, 'last_pipe_status': [10, 20, 30], 'jobnum': 10, diff --git a/tests/test_provided_config_files.py b/tests/test_provided_config_files.py index 45cffcf6..da160ab1 100644 --- a/tests/test_provided_config_files.py +++ b/tests/test_provided_config_files.py @@ -86,7 +86,7 @@ class TestConfig(TestCase): def test_zsh(self): from powerline.shell import ShellPowerline - args = Args(last_pipe_status=[1, 0], jobnum=0, ext=['shell'], renderer_module='zsh_prompt') + args = Args(last_pipe_status=[1, 0], jobnum=0, ext=['shell'], renderer_module='.zsh') segment_info = {'args': args} with ShellPowerline(args, run_once=False) as powerline: powerline.render(segment_info=segment_info) @@ -102,7 +102,7 @@ class TestConfig(TestCase): def test_bash(self): from powerline.shell import ShellPowerline - args = Args(last_exit_code=1, jobnum=0, ext=['shell'], renderer_module='bash_prompt', config={'ext': {'shell': {'theme': 'default_leftonly'}}}) + args = Args(last_exit_code=1, jobnum=0, ext=['shell'], renderer_module='.bash', config={'ext': {'shell': {'theme': 'default_leftonly'}}}) with ShellPowerline(args, run_once=False) as powerline: powerline.render(segment_info={'args': args}) with ShellPowerline(args, run_once=False) as powerline: