Rev 6606: Fix pep8 in bash_completion plugin. in file:///home/vila/src/bzr/experimental/py3/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Tue Sep 1 16:36:53 UTC 2015
At file:///home/vila/src/bzr/experimental/py3/
------------------------------------------------------------
revno: 6606
revision-id: v.ladeuil+lp at free.fr-20150901163653-efyv84me0ayu25a9
parent: v.ladeuil+lp at free.fr-20150901160925-seiin8rwdk07joqs
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: pep8
timestamp: Tue 2015-09-01 18:36:53 +0200
message:
Fix pep8 in bash_completion plugin.
-------------- next part --------------
=== modified file 'bzrlib/plugins/bash_completion/__init__.py'
--- a/bzrlib/plugins/bash_completion/__init__.py 2011-12-18 12:46:49 +0000
+++ b/bzrlib/plugins/bash_completion/__init__.py 2015-09-01 16:36:53 +0000
@@ -21,12 +21,14 @@
This plugin provides a command called bash-completion that generates a
bash completion function for bzr. See its documentation for details.
"""
-
-from bzrlib import commands, version_info
-
+import bzrlib
+from bzrlib import commands
+
+# Since we are a built-in plugin we share the bzrlib version
+version_info = bzrlib.version_info
bzr_plugin_name = 'bash_completion'
-bzr_commands = [ 'bash-completion' ]
+bzr_commands = ['bash-completion']
commands.plugin_cmds.register_lazy('cmd_bash_completion', [],
'bzrlib.plugins.bash_completion.bashcomp')
@@ -37,5 +39,5 @@
'tests',
]
basic_tests.addTest(loader.loadTestsFromModuleNames(
- ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
+ ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
return basic_tests
=== modified file 'bzrlib/plugins/bash_completion/bashcomp.py'
--- a/bzrlib/plugins/bash_completion/bashcomp.py 2011-12-20 17:56:21 +0000
+++ b/bzrlib/plugins/bash_completion/bashcomp.py 2015-09-01 16:36:53 +0000
@@ -40,7 +40,7 @@
self.debug = debug
def script(self):
- return ("""\
+ return """\
# Programmable completion for the Bazaar-NG bzr command under bash.
# Known to work with bash 2.05a as well as bash 4.1.2, and probably
# all versions in between as well.
@@ -57,110 +57,109 @@
shopt -s progcomp
%(function)s
complete -F %(function_name)s -o default bzr
-""" % {
- "function_name": self.function_name,
- "function": self.function(),
- "bzr_version": self.bzr_version(),
- })
+""" % dict(function_name=self.function_name, function=self.function(),
+ bzr_version=self.bzr_version())
def function(self):
- return ("""\
+ return """\
%(function_name)s ()
{
- local cur cmds cmdIdx cmd cmdOpts fixedWords i globalOpts
- local curOpt optEnums
- local IFS=$' \\n'
-
- COMPREPLY=()
- cur=${COMP_WORDS[COMP_CWORD]}
-
- cmds='%(cmds)s'
- globalOpts=( %(global_options)s )
-
- # do ordinary expansion if we are anywhere after a -- argument
- for ((i = 1; i < COMP_CWORD; ++i)); do
- [[ ${COMP_WORDS[i]} == "--" ]] && return 0
- done
-
- # find the command; it's the first word not starting in -
- cmd=
- for ((cmdIdx = 1; cmdIdx < ${#COMP_WORDS[@]}; ++cmdIdx)); do
- if [[ ${COMP_WORDS[cmdIdx]} != -* ]]; then
- cmd=${COMP_WORDS[cmdIdx]}
- break
- fi
- done
-
- # complete command name if we are not already past the command
- if [[ $COMP_CWORD -le cmdIdx ]]; then
- COMPREPLY=( $( compgen -W "$cmds ${globalOpts[*]}" -- $cur ) )
- return 0
- fi
-
- # find the option for which we want to complete a value
- curOpt=
- if [[ $cur != -* ]] && [[ $COMP_CWORD -gt 1 ]]; then
- curOpt=${COMP_WORDS[COMP_CWORD - 1]}
- if [[ $curOpt == = ]]; then
- curOpt=${COMP_WORDS[COMP_CWORD - 2]}
- elif [[ $cur == : ]]; then
- cur=
- curOpt="$curOpt:"
- elif [[ $curOpt == : ]]; then
- curOpt=${COMP_WORDS[COMP_CWORD - 2]}:
- fi
- fi
+ local cur cmds cmdIdx cmd cmdOpts fixedWords i globalOpts
+ local curOpt optEnums
+ local IFS=$' \\n'
+
+ COMPREPLY=()
+ cur=${COMP_WORDS[COMP_CWORD]}
+
+ cmds='%(cmds)s'
+ globalOpts=( %(global_options)s )
+
+ # do ordinary expansion if we are anywhere after a -- argument
+ for ((i = 1; i < COMP_CWORD; ++i)); do
+ [[ ${COMP_WORDS[i]} == "--" ]] && return 0
+ done
+
+ # find the command; it's the first word not starting in -
+ cmd=
+ for ((cmdIdx = 1; cmdIdx < ${#COMP_WORDS[@]}; ++cmdIdx)); do
+ if [[ ${COMP_WORDS[cmdIdx]} != -* ]]; then
+ cmd=${COMP_WORDS[cmdIdx]}
+ break
+ fi
+ done
+
+ # complete command name if we are not already past the command
+ if [[ $COMP_CWORD -le cmdIdx ]]; then
+ COMPREPLY=( $( compgen -W "$cmds ${globalOpts[*]}" -- $cur ) )
+ return 0
+ fi
+
+ # find the option for which we want to complete a value
+ curOpt=
+ if [[ $cur != -* ]] && [[ $COMP_CWORD -gt 1 ]]; then
+ curOpt=${COMP_WORDS[COMP_CWORD - 1]}
+ if [[ $curOpt == = ]]; then
+ curOpt=${COMP_WORDS[COMP_CWORD - 2]}
+ elif [[ $cur == : ]]; then
+ cur=
+ curOpt="$curOpt:"
+ elif [[ $curOpt == : ]]; then
+ curOpt=${COMP_WORDS[COMP_CWORD - 2]}:
+ fi
+ fi
%(debug)s
- cmdOpts=( )
- optEnums=( )
- fixedWords=( )
- case $cmd in
+ cmdOpts=( )
+ optEnums=( )
+ fixedWords=( )
+ case $cmd in
%(cases)s\
- *)
- cmdOpts=(--help -h)
- ;;
- esac
-
- IFS=$'\\n'
- if [[ ${#fixedWords[@]} -eq 0 ]] && [[ ${#optEnums[@]} -eq 0 ]] && [[ $cur != -* ]]; then
- case $curOpt in
- tag:|*..tag:)
- fixedWords=( $(bzr tags 2>/dev/null | sed 's/ *[^ ]*$//; s/ /\\\\\\\\ /g;') )
- ;;
- esac
- case $cur in
- [\\"\\']tag:*)
- fixedWords=( $(bzr tags 2>/dev/null | sed 's/ *[^ ]*$//; s/^/tag:/') )
- ;;
- [\\"\\']*..tag:*)
- fixedWords=( $(bzr tags 2>/dev/null | sed 's/ *[^ ]*$//') )
- fixedWords=( $(for i in "${fixedWords[@]}"; do echo "${cur%%..tag:*}..tag:${i}"; done) )
- ;;
- esac
- elif [[ $cur == = ]] && [[ ${#optEnums[@]} -gt 0 ]]; then
- # complete directly after "--option=", list all enum values
- COMPREPLY=( "${optEnums[@]}" )
- return 0
- else
- fixedWords=( "${cmdOpts[@]}"
- "${globalOpts[@]}"
- "${optEnums[@]}"
- "${fixedWords[@]}" )
- fi
-
- if [[ ${#fixedWords[@]} -gt 0 ]]; then
- COMPREPLY=( $( compgen -W "${fixedWords[*]}" -- $cur ) )
- fi
-
- return 0
+ *)
+ cmdOpts=(--help -h)
+ ;;
+ esac
+
+ IFS=$'\\n'
+ if [[ ${#fixedWords[@]} -eq 0 ]] && [[ ${#optEnums[@]} -eq 0 ]] \
+ && [[ $cur != -* ]]; then
+ case $curOpt in
+ tag:|*..tag:)
+ fixedWords=( $(bzr tags 2>/dev/null | \
+ sed 's/ *[^ ]*$//; s/ /\\\\\\\\ /g;') )
+ ;;
+ esac
+ case $cur in
+ [\\"\\']tag:*)
+ fixedWords=( $(bzr tags 2>/dev/null | \
+ sed 's/ *[^ ]*$//; s/^/tag:/') )
+ ;;
+ [\\"\\']*..tag:*)
+ fixedWords=( $(bzr tags 2>/dev/null | sed 's/ *[^ ]*$//'))
+ fixedWords=( $(for i in "${fixedWords[@]}";\
+ do echo "${cur%%..tag:*}..tag:${i}"; done) )
+ ;;
+ esac
+ elif [[ $cur == = ]] && [[ ${#optEnums[@]} -gt 0 ]]; then
+ # complete directly after "--option=", list all enum values
+ COMPREPLY=( "${optEnums[@]}" )
+ return 0
+ else
+ fixedWords=( "${cmdOpts[@]}"
+ "${globalOpts[@]}"
+ "${optEnums[@]}"
+ "${fixedWords[@]}" )
+ fi
+
+ if [[ ${#fixedWords[@]} -gt 0 ]]; then
+ COMPREPLY=( $( compgen -W "${fixedWords[*]}" -- $cur ) )
+ fi
+
+ return 0
}
-""" % {
- "cmds": self.command_names(),
- "function_name": self.function_name,
- "cases": self.command_cases(),
- "global_options": self.global_options(),
- "debug": self.debug_output(),
- })
+""" % dict(cmds=self.command_names(),
+ function_name=self.function_name,
+ cases=self.command_cases(),
+ global_options=self.global_options(),
+ debug=self.debug_output())
# Help Emacs terminate strings: "
def command_names(self):
@@ -171,16 +170,16 @@
return ''
else:
return (r"""
- # Debugging code enabled using the --debug command line switch.
- # Will dump some variables to the top portion of the terminal.
- echo -ne '\e[s\e[H'
- for (( i=0; i < ${#COMP_WORDS[@]}; ++i)); do
- echo "\$COMP_WORDS[$i]='${COMP_WORDS[i]}'"$'\e[K'
- done
- for i in COMP_CWORD COMP_LINE COMP_POINT COMP_TYPE COMP_KEY cur curOpt; do
- echo "\$${i}=\"${!i}\""$'\e[K'
- done
- echo -ne '---\e[K\e[u'
+# Debugging code enabled using the --debug command line switch.
+# Will dump some variables to the top portion of the terminal.
+echo -ne '\e[s\e[H'
+for (( i=0; i < ${#COMP_WORDS[@]}; ++i)); do
+ echo "\$COMP_WORDS[$i]='${COMP_WORDS[i]}'"$'\e[K'
+done
+for i in COMP_CWORD COMP_LINE COMP_POINT COMP_TYPE COMP_KEY cur curOpt; do
+ echo "\$${i}=\"${!i}\""$'\e[K'
+done
+echo -ne '---\e[K\e[u'
""")
def bzr_version(self):
@@ -189,8 +188,8 @@
bzr_version += "."
else:
bzr_version += " and the following plugins:"
- for name, plugin in sorted(self.data.plugins.iteritems()):
- bzr_version += "\n# %s" % plugin
+ for name, p in sorted(self.data.plugins.iteritems()):
+ bzr_version += "\n# %s" % p
return bzr_version
def global_options(self):
@@ -314,7 +313,8 @@
self.data.global_options.add(short)
def aliases(self):
- for alias, expansion in config.GlobalConfig().get_aliases().iteritems():
+ for (alias,
+ expansion) in config.GlobalConfig().get_aliases().iteritems():
for token in cmdline.split(expansion):
if not token.startswith("-"):
self.user_aliases.setdefault(token, set()).add(alias)
@@ -331,7 +331,7 @@
plugin_name = cmd.plugin_name()
if plugin_name is not None:
if (self.selected_plugins is not None and
- plugin not in self.selected_plugins):
+ plugin not in self.selected_plugins):
return None
plugin_data = self.data.plugins.get(plugin_name)
if plugin_data is None:
@@ -345,19 +345,21 @@
# but will choose completely new names or add options to existing
# ones while maintaining the actual command name unchanged.
cmd_data.aliases.extend(cmd.aliases)
- cmd_data.aliases.extend(sorted([useralias
- for cmdalias in cmd_data.aliases
- if cmdalias in self.user_aliases
- for useralias in self.user_aliases[cmdalias]
- if useralias not in cmd_data.aliases]))
+ cmd_data.aliases.extend(
+ sorted([useralias
+ for cmdalias in cmd_data.aliases
+ if cmdalias in self.user_aliases
+ for useralias in self.user_aliases[cmdalias]
+ if useralias not in cmd_data.aliases]))
opts = cmd.options()
for optname, opt in sorted(opts.iteritems()):
cmd_data.options.extend(self.option(opt))
if 'help' == name or 'help' in cmd.aliases:
- cmd_data.fixed_words = ('($cmds %s)' %
- " ".join(sorted(help_topics.topic_registry.keys())))
+ cmd_data.fixed_words = (
+ '($cmds %s)' % " ".join(sorted(
+ help_topics.topic_registry.keys())))
return cmd_data
@@ -388,9 +390,10 @@
def wrap_parser(self, optswitches, parser):
orig_add_option_group = parser.add_option_group
+
def tweaked_add_option_group(*opts, **attrs):
return self.wrap_container(optswitches,
- orig_add_option_group(*opts, **attrs))
+ orig_add_option_group(*opts, **attrs))
parser.add_option_group = tweaked_add_option_group
return self.wrap_container(optswitches, parser)
@@ -398,7 +401,8 @@
def bash_completion_function(out, function_name="_bzr", function_only=False,
debug=False,
no_plugins=False, selected_plugins=None):
- dc = DataCollector(no_plugins=no_plugins, selected_plugins=selected_plugins)
+ dc = DataCollector(no_plugins=no_plugins,
+ selected_plugins=selected_plugins)
data = dc.collect()
cg = BashCodeGen(data, function_name=function_name, debug=debug)
if function_only:
@@ -414,22 +418,26 @@
This command generates a shell function which can be used by bash to
automatically complete the currently typed command when the user presses
the completion key (usually tab).
-
+
Commonly used like this:
eval "`bzr bash-completion`"
"""
takes_options = [
- option.Option("function-name", short_name="f", type=str, argname="name",
- help="Name of the generated function (default: _bzr)"),
- option.Option("function-only", short_name="o", type=None,
- help="Generate only the shell function, don't enable it"),
- option.Option("debug", type=None, hidden=True,
- help="Enable shell code useful for debugging"),
- option.ListOption("plugin", type=str, argname="name",
- # param_name="selected_plugins", # doesn't work, bug #387117
- help="Enable completions for the selected plugin"
- + " (default: all plugins)"),
+ option.Option(
+ "function-name", short_name="f", type=str, argname="name",
+ help="Name of the generated function (default: _bzr)"),
+ option.Option(
+ "function-only", short_name="o", type=None,
+ help="Generate only the shell function, don't enable it"),
+ option.Option(
+ "debug", type=None, hidden=True,
+ help="Enable shell code useful for debugging"),
+ option.ListOption(
+ "plugin", type=str, argname="name",
+ # param_name="selected_plugins", # doesn't work, bug #387117
+ help=("Enable completions for the selected plugin"
+ " (default: all plugins)"))
]
def run(self, **kwargs):
=== modified file 'bzrlib/plugins/bash_completion/tests/__init__.py'
--- a/bzrlib/plugins/bash_completion/tests/__init__.py 2010-04-29 20:51:13 +0000
+++ b/bzrlib/plugins/bash_completion/tests/__init__.py 2015-09-01 16:36:53 +0000
@@ -14,10 +14,12 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
def load_tests(basic_tests, module, loader):
testmod_names = [
'test_bashcomp',
]
- basic_tests.addTest(loader.loadTestsFromModuleNames(
+ basic_tests.addTest(
+ loader.loadTestsFromModuleNames(
["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
return basic_tests
More information about the bazaar-commits
mailing list