Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 18
Add Python 3 support#106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Add Python 3 support #106
Changes from all commits
9f49f004f11236c46df67c79d4fc9cfd9378beaaee70d679b6812ea159cb2a66eb7f8eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| language: python | ||
| python: | ||
| - "2.7" | ||
| #- "3.4" | ||
| - "3.4" | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Come on, even Ubuntu is on 3.5 by now! MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I added 3.5. Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no need to ask for more than we need. MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. smartdispatch can also be used on our own computer (e.g. use the useful expansion of folded argument to generate a commands file :-P) and I have a virtual env with Python 3.5. Also, testing on Python 3.5 came for free with Travis, why not use take advantage of it? Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh! You test it on both, nevermind I thought you removed 3.4. My bad | ||
| - "3.5" | ||
| install: | ||
| - pip install coveralls | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -35,7 +35,7 @@ def unfold(self, match): | ||
| start = int(groups[0]) | ||
| end = int(groups[1]) | ||
| step = 1 if groups[2] is None else int(groups[2]) | ||
| return map(str, range(start, end, step)) | ||
| return [str(i) for i in range(start, end, step)] | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Were we really using map everywhere for no reasons ? MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes and no. In Python 3, map returns a generator instead of a list. What we want here is a list, so we are better off using list comprehension instead. | ||
| argument_templates = build_argument_templates_dictionnary() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| from __future__ import print_function | ||
| import re | ||
| import binascii | ||
| import hashlib | ||
| import unicodedata | ||
| import json | ||
| @@ -15,7 +18,7 @@ def print_boxed(string): | ||
| out = u"\u250c" + box_line + u"\u2510\n" | ||
| out += '\n'.join([u"\u2502 {} \u2502".format(line.ljust(max_len)) for line in splitted_string]) | ||
| out += u"\n\u2514" + box_line + u"\u2518" | ||
| printout | ||
| print(out) | ||
| def yes_no_prompt(query, default=None): | ||
| @@ -35,13 +38,13 @@ def yes_no_prompt(query, default=None): | ||
| def chunks(sequence, n): | ||
| """ Yield successive n-sized chunks from sequence. """ | ||
| for i in xrange(0, len(sequence), n): | ||
| for i in range(0, len(sequence), n): | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably use the
| ||
| yield sequence[i:i + n] | ||
| def generate_uid_from_string(value): | ||
| """ Create unique identifier from a string. """ | ||
| return hashlib.sha256(value).hexdigest() | ||
| return hashlib.sha256(value.encode()).hexdigest() | ||
| def slugify(value): | ||
| @@ -54,15 +57,23 @@ def slugify(value): | ||
| --------- | ||
| https://github.com/django/django/blob/1.7c3/django/utils/text.py#L436 | ||
| """ | ||
| value = unicodedata.normalize('NFKD', unicode(value, "UTF-8")).encode('ascii', 'ignore').decode('ascii') | ||
| # Convert `value` to Unicode so we can slugify it using the unicodedata module. | ||
| try: | ||
| value = unicode(value, "UTF-8") | ||
| except NameError: | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is probably a cleaner way to manage this. Maybe with six ?
| ||
| pass # In Python 3, all strings are already stored as Unicode. | ||
| # Replace all compatibility characters with their equivalents. | ||
| value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii') | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That looks like a hack. Maybe a comment? MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure I'll add one. I'm following the "It's easier to ask forgiveness than permission" principle here, it is not really a hack. | ||
| value = re.sub('[^\w\s-]', '', value).strip().lower() | ||
| return str(re.sub('[-\s]+', '_', value)) | ||
| def encode_escaped_characters(text, escaping_character="\\"): | ||
| """ Escape the escaped character using its hex representation """ | ||
| def hexify(match): | ||
| return "\\x{0}".format(match.group()[-1].encode("hex")) | ||
| # Reference: http://stackoverflow.com/questions/18298251/python-hex-values-to-convert-to-a-string-integer | ||
| return "\\x" + binascii.hexlify(match.group()[-1].encode()).decode() | ||
| return re.sub(r"\\.", hexify, text) | ||
| @@ -73,7 +84,7 @@ def decode_escaped_characters(text): | ||
| return '' | ||
| def unhexify(match): | ||
| return match.group()[2:].decode("hex") | ||
| return binascii.unhexlify(match.group()[2:]).decode() | ||
| return re.sub(r"\\x..", unhexify, text) | ||
| @@ -92,6 +103,8 @@ def detect_cluster(): | ||
| # Get server status | ||
| try: | ||
| output = Popen(["qstat", "-B"], stdout=PIPE).communicate()[0] | ||
| if isinstance(output, bytes): | ||
| output = output.decode("utf-8") | ||
| except OSError: | ||
| # If qstat is not available we assume that the cluster is unknown. | ||
| return None | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| #!/usr/bin/env python2 | ||
| #!/usr/bin/env python | ||
| # -*- coding: utf-8 -*- | ||
| import os | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wh should add unit test in python 3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already done :-), check below.