-
-
Notifications
You must be signed in to change notification settings - Fork 649
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
Add future lib and port src/base #6067
Changes from 5 commits
31167f9
06b0db0
0c0e8f7
ce2216b
77ae991
7f07f94
8bc62a4
70d2547
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
unicode_literals, with_statement) | ||
|
||
import pprint | ||
from builtins import object | ||
|
||
import pystache | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
import hashlib | ||
import json | ||
from builtins import object | ||
|
||
|
||
def hash_all(strs, digest=None): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
import os | ||
import pkgutil | ||
from builtins import object | ||
|
||
import pystache | ||
import six | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
import functools | ||
import threading | ||
from builtins import object | ||
|
||
|
||
class Storage(threading.local): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,13 @@ | |
unicode_literals, with_statement) | ||
|
||
import re | ||
from itertools import izip_longest | ||
from builtins import map, object, str | ||
from functools import total_ordering | ||
|
||
from future.moves.itertools import zip_longest | ||
|
||
|
||
@total_ordering | ||
class Revision(object): | ||
"""Represents a software revision that is comparable to another revision describing the same | ||
software. | ||
|
@@ -74,7 +78,7 @@ def lenient(cls, rev): | |
""" | ||
rev = re.sub(r'(\d)([a-zA-Z])', r'\1.\2', rev) | ||
rev = re.sub(r'([a-zA-Z])(\d)', r'\1.\2', rev) | ||
return cls(*map(cls._parse_atom, re.split(r'[.+_\-]', rev))) | ||
return cls(*list(map(cls._parse_atom, re.split(r'[.+_\-]', rev)))) | ||
|
||
def __init__(self, *components): | ||
self._components = components | ||
|
@@ -87,21 +91,24 @@ def components(self): | |
""" | ||
return list(self._components) | ||
|
||
def __cmp__(self, other): | ||
for ours, theirs in izip_longest(self._components, other._components, fillvalue=0): | ||
difference = cmp(ours, theirs) | ||
if difference != 0: | ||
return difference | ||
return 0 | ||
def _is_valid_operand(self, other): | ||
return hasattr(other, '_components') | ||
|
||
def __repr__(self): | ||
return '{}({})'.format(self.__class__.__name__, ', '.join(map(repr, self._components))) | ||
|
||
def __eq__(self, other): | ||
return hasattr(other, '_components') and tuple(self._components) == tuple(other._components) | ||
|
||
def __ne__(self, other): | ||
return not self.__eq__(other) | ||
if not self._is_valid_operand(other): | ||
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. This slightly changes the behavior from before. When comparing to non-Revisions, this returns 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. Is there any python3 compat reason to mix in this behavior change? As an example of future conversion PRs, it would be good to stick to pure semantic-preserving automated conversion if possible. 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. The reason I made the change is for the The only Py3 change we need is replacing 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. I'd prefer it if just to keep semantics changes out of the conversion PRs. Especially since 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. More on 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. I reverted But am keeping 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. OK. I think I can buy the 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.
I was mistaken there. The semantic shift is subtle to non-existant depending on how 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. Okay I reverted everything back to identical semantics from before (just more explicit). I think it's a good policy to avoid any changes in these PRs because they get buried. Instead, will add notes in form |
||
return False # TODO: typically this should return NotImplemented. Returning False to avoid changing prior API. | ||
return tuple(self._components) == tuple(other._components) | ||
|
||
def __lt__(self, other): | ||
if not self._is_valid_operand(other): | ||
return NotImplemented | ||
for ours, theirs in zip_longest(self._components, other._components, fillvalue=0): | ||
if ours != theirs: | ||
return ours < theirs | ||
return False | ||
|
||
def __hash__(self): | ||
return hash(self._components) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,12 @@ | |
import multiprocessing | ||
import signal | ||
import sys | ||
import thread | ||
import threading | ||
from builtins import next, object | ||
from multiprocessing.pool import ThreadPool | ||
|
||
from future.moves import _thread | ||
|
||
from pants.reporting.report import Report | ||
|
||
|
||
|
@@ -103,7 +105,7 @@ def error(e): | |
|
||
# We filter out Nones defensively. There shouldn't be any, but if a bug causes one, | ||
# Pants might hang indefinitely without this filtering. | ||
work_iter = iter(filter(None, work_chain)) | ||
work_iter = iter([_f for _f in work_chain if _f]) | ||
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. This could be just 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. I'll fix it. If we don't change it now, it will probably never get changed and might be confusing to later devs why we're using this roundabout approach. I do agree with you that we should be more rigorous though with keeping 100% semantic parity (as possible). But for small things like removing extraneous |
||
|
||
def submit_next(): | ||
try: | ||
|
@@ -149,7 +151,7 @@ def _do_work(self, func, args_tuple, workunit_name, workunit_parent, on_failure= | |
except KeyboardInterrupt: | ||
# If a worker thread intercepts a KeyboardInterrupt, we want to propagate it to the main | ||
# thread. | ||
thread.interrupt_main() | ||
_thread.interrupt_main() | ||
raise | ||
except Exception as e: | ||
if on_failure: | ||
|
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.
This implements all 6 comparison dunders, given
__eq__
and__lt__
.There is a slight performance penalty. If
Revision
is used a lot, I can manually add the other comparisons.