Permalink
Browse files

Fix scripts to be cross-2-3-compatible, since 2to3 won't convert them

  • Loading branch information...
1 parent cd3a299 commit 0734377a223716a915aecc231e5afa2400e57569 @kislyuk committed Feb 3, 2013
View
@@ -121,7 +121,7 @@ organization and complete their names, then prints the member description:
def github_org_members(prefix, parsed_args, **kwargs):
resource = "https://api.github.com/orgs/{org}/members".format(org=parsed_args.organization)
- return (member['login'] for member in requests.get(resource).json if member['login'].startswith(prefix))
+ return (member['login'] for member in requests.get(resource).json() if member['login'].startswith(prefix))
parser = argparse.ArgumentParser()
parser.add_argument("--organization", help="GitHub organization")
@@ -130,7 +130,7 @@ organization and complete their names, then prints the member description:
argcomplete.autocomplete(parser)
args = parser.parse_args()
- pprint.pprint(requests.get("https://api.github.com/users/" + args.member).json)
+ pprint.pprint(requests.get("https://api.github.com/users/" + args.member).json())
`Try it <https://raw.github.com/kislyuk/argcomplete/master/docs/examples/describe_github_user.py>`_ like this::
@@ -8,7 +8,9 @@
Activate the generic bash-completion script for the argcomplete module.
'''
+from __future__ import print_function
import os, sys, argparse, argcomplete, shutil
+
parser = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
@@ -26,10 +28,10 @@ if not os.path.exists(args.dest) and args.dest != '-':
activator = os.path.join(os.path.dirname(argcomplete.__file__), 'bash_completion.d', 'python-argcomplete.sh')
if args.dest == '-':
- print open(activator).read()
+ print(open(activator).read())
else:
dest = os.path.join(args.dest, "python-argcomplete.sh")
- print "Installing bash completion script", dest
+ print("Installing bash completion script", dest)
try:
shutil.copy(activator, dest)
except Exception as e:
@@ -15,7 +15,7 @@ parser.add_argument("wrapper_script", help="Wrapper script to examine")
args = parser.parse_args()
with open(args.wrapper_script) as fh:
- line1, lines = fh.read(1024).split("\n", 2)[:2]
+ line1, lines = fh.read(1024).split("\n", 1)[:2]
assert(line1.startswith('#') and 'py' in line1)
for line in lines.split("\n", 10):
if line.startswith("# EASY-INSTALL-SCRIPT"):
@@ -14,6 +14,9 @@ Example:
$ eval "$(register-python-argcomplete my-favorite-script.py)"
'''
+from __future__ import print_function
+import os, sys, argparse
+
shellcode = '''
_python_argcomplete() {
local IFS='\013'
@@ -29,16 +32,13 @@ _python_argcomplete() {
complete -o nospace -o default -F _python_argcomplete "%s"
'''
-import sys, argparse
parser = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("executable")
-from argcomplete import autocomplete
-autocomplete(parser)
if len(sys.argv)==1:
parser.print_help()
sys.exit(1)
args = parser.parse_args()
-print shellcode % args.executable
+print(shellcode % args.executable)

0 comments on commit 0734377

Please sign in to comment.