From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 6B6D013877A for ; Tue, 19 Aug 2014 08:16:54 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 09451E0940; Tue, 19 Aug 2014 08:16:53 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 7039FE093D for ; Tue, 19 Aug 2014 08:16:52 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 682BB340077 for ; Tue, 19 Aug 2014 08:16:51 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id A10133BBD for ; Tue, 19 Aug 2014 07:01:05 +0000 (UTC) From: "Michał Górny" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Michał Górny" Message-ID: <1407788926.cbfba17290bbc14514538acbb954efeb61f82d8f.mgorny@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/util/_eventloop/, pym/portage/, pym/_emerge/, pym/portage/_sets/, ... X-VCS-Repository: proj/portage X-VCS-Files: bin/quickpkg pym/_emerge/Scheduler.py pym/_emerge/actions.py pym/_emerge/depgraph.py pym/_emerge/sync/old_tree_timestamp.py pym/portage/_emirrordist/FetchTask.py pym/portage/_sets/dbapi.py pym/portage/cache/sqlite.py pym/portage/dbapi/vartree.py pym/portage/localization.py pym/portage/output.py pym/portage/util/_eventloop/EventLoop.py pym/portage/util/_eventloop/PollSelectAdapter.py X-VCS-Directories: pym/portage/util/_eventloop/ pym/portage/ pym/_emerge/ pym/portage/_sets/ pym/portage/dbapi/ pym/portage/cache/ bin/ pym/portage/_emirrordist/ pym/_emerge/sync/ X-VCS-Committer: mgorny X-VCS-Committer-Name: Michał Górny X-VCS-Revision: cbfba17290bbc14514538acbb954efeb61f82d8f X-VCS-Branch: master Date: Tue, 19 Aug 2014 07:01:05 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 0f10a853-8753-47eb-93aa-02e632ee48bb X-Archives-Hash: 28744a3dc58489fabded8433d90a15d9 Message-ID: <20140819070105.234hSDcjRxlqLwq0qWHZPE32DCloBFu-lO1FqzPi0rY@z> commit: cbfba17290bbc14514538acbb954efeb61f82d8f Author: Michał Górny gentoo org> AuthorDate: Wed Aug 6 17:17:54 2014 +0000 Commit: Michał Górny gentoo org> CommitDate: Mon Aug 11 20:28:46 2014 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=cbfba172 Enable consistent __future__ behavior for division In Python 2, the division ('/') operator defaults to integer (truncating) division when given integer argument. In Python 3, it performs floating-point division unconditionally instead. To overcome this difference and get a consistent behavior, integers were converted to floats explicitly in a few places. Instead, use a simpler 'from __future__ import division' statement that enables floating-point division globally in Python 2. Use it in all relevant files to get a consistent behavior, and use '//' appropriately whenever integer division is desired. Reviewed-by: Arfrever Frehtes Taifersar Arahesis Apache.Org> Acked-by: Alexander Berntsen gentoo.org> Acked-by: Brian Dolbec gentoo.org> --- bin/quickpkg | 4 ++-- pym/_emerge/Scheduler.py | 2 +- pym/_emerge/actions.py | 10 +++++----- pym/_emerge/depgraph.py | 4 ++-- pym/_emerge/sync/old_tree_timestamp.py | 12 +++++++----- pym/portage/_emirrordist/FetchTask.py | 6 ++++-- pym/portage/_sets/dbapi.py | 4 +++- pym/portage/cache/sqlite.py | 4 ++-- pym/portage/dbapi/vartree.py | 4 ++-- pym/portage/localization.py | 2 ++ pym/portage/output.py | 6 ++++-- pym/portage/util/_eventloop/EventLoop.py | 8 +++++--- pym/portage/util/_eventloop/PollSelectAdapter.py | 6 ++++-- 13 files changed, 43 insertions(+), 29 deletions(-) diff --git a/bin/quickpkg b/bin/quickpkg index 90277ad..035131e 100755 --- a/bin/quickpkg +++ b/bin/quickpkg @@ -2,7 +2,7 @@ # Copyright 1999-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -from __future__ import print_function +from __future__ import division, print_function import errno import math @@ -264,7 +264,7 @@ def quickpkg_main(options, args, eout): size_str = "0" else: power_of_2 = math.log(size, 2) - power_of_2 = 10*int(power_of_2/10) + power_of_2 = 10*(power_of_2//10) unit = units.get(power_of_2) if unit: size = float(size)/(2**power_of_2) diff --git a/pym/_emerge/Scheduler.py b/pym/_emerge/Scheduler.py index dd268f7..d6db311 100644 --- a/pym/_emerge/Scheduler.py +++ b/pym/_emerge/Scheduler.py @@ -1,7 +1,7 @@ # Copyright 1999-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -from __future__ import print_function, unicode_literals +from __future__ import division, print_function, unicode_literals from collections import deque import gc diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py index b935139..e482744 100644 --- a/pym/_emerge/actions.py +++ b/pym/_emerge/actions.py @@ -1,7 +1,7 @@ # Copyright 1999-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -from __future__ import print_function, unicode_literals +from __future__ import division, print_function, unicode_literals import errno import logging @@ -1499,14 +1499,14 @@ def action_info(settings, trees, myopts, myfiles): vm_info = get_vm_info() if "ram.total" in vm_info: - line = "%-9s %10d total" % ("KiB Mem:", vm_info["ram.total"] / 1024) + line = "%-9s %10d total" % ("KiB Mem:", vm_info["ram.total"] // 1024) if "ram.free" in vm_info: - line += ",%10d free" % (vm_info["ram.free"] / 1024,) + line += ",%10d free" % (vm_info["ram.free"] // 1024,) append(line) if "swap.total" in vm_info: - line = "%-9s %10d total" % ("KiB Swap:", vm_info["swap.total"] / 1024) + line = "%-9s %10d total" % ("KiB Swap:", vm_info["swap.total"] // 1024) if "swap.free" in vm_info: - line += ",%10d free" % (vm_info["swap.free"] / 1024,) + line += ",%10d free" % (vm_info["swap.free"] // 1024,) append(line) lastSync = portage.grabfile(os.path.join( diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py index acb1db1..a10297a 100644 --- a/pym/_emerge/depgraph.py +++ b/pym/_emerge/depgraph.py @@ -1,7 +1,7 @@ # Copyright 1999-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -from __future__ import print_function, unicode_literals +from __future__ import division, print_function, unicode_literals import collections import errno @@ -8446,7 +8446,7 @@ def _backtrack_depgraph(settings, trees, myopts, myparams, myaction, myfiles, sp debug = "--debug" in myopts mydepgraph = None max_retries = myopts.get('--backtrack', 10) - max_depth = max(1, (max_retries + 1) / 2) + max_depth = max(1, (max_retries + 1) // 2) allow_backtracking = max_retries > 0 backtracker = Backtracker(max_depth) backtracked = 0 diff --git a/pym/_emerge/sync/old_tree_timestamp.py b/pym/_emerge/sync/old_tree_timestamp.py index 9b35aed..aa23a27 100644 --- a/pym/_emerge/sync/old_tree_timestamp.py +++ b/pym/_emerge/sync/old_tree_timestamp.py @@ -1,6 +1,8 @@ -# Copyright 2010 Gentoo Foundation +# Copyright 2010-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 +from __future__ import division + import locale import logging import time @@ -27,16 +29,16 @@ def whenago(seconds): out = [] if sec > 60: - mins = sec / 60 + mins = sec // 60 sec = sec % 60 if mins > 60: - hrs = mins / 60 + hrs = mins // 60 mins = mins % 60 if hrs > 24: - days = hrs / 24 + days = hrs // 24 hrs = hrs % 24 if days > 365: - years = days / 365 + years = days // 365 days = days % 365 if years: diff --git a/pym/portage/_emirrordist/FetchTask.py b/pym/portage/_emirrordist/FetchTask.py index 66c41c1..307c5bd 100644 --- a/pym/portage/_emirrordist/FetchTask.py +++ b/pym/portage/_emirrordist/FetchTask.py @@ -1,6 +1,8 @@ -# Copyright 2013 Gentoo Foundation +# Copyright 2013-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 +from __future__ import division + import collections import errno import logging @@ -242,7 +244,7 @@ class FetchTask(CompositeTask): remaining_tries = self.config.options.tries - len(self._tried_uris) if remaining_tries > 0: - if remaining_tries <= self.config.options.tries / 2: + if remaining_tries <= self.config.options.tries // 2: while self._primaryuri_stack: uri = self._primaryuri_stack.pop() if uri not in self._tried_uris: diff --git a/pym/portage/_sets/dbapi.py b/pym/portage/_sets/dbapi.py index 384fb3a..817bcd7 100644 --- a/pym/portage/_sets/dbapi.py +++ b/pym/portage/_sets/dbapi.py @@ -1,6 +1,8 @@ -# Copyright 2007-2012 Gentoo Foundation +# Copyright 2007-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 +from __future__ import division + import time from portage import os diff --git a/pym/portage/cache/sqlite.py b/pym/portage/cache/sqlite.py index 42a2399..310ac94 100644 --- a/pym/portage/cache/sqlite.py +++ b/pym/portage/cache/sqlite.py @@ -1,7 +1,7 @@ # Copyright 1999-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -from __future__ import unicode_literals +from __future__ import division, unicode_literals import re import sys @@ -174,7 +174,7 @@ class database(fs_template.FsBased): cursor.execute("PRAGMA page_size") page_size=int(cursor.fetchone()[0]) # number of pages, sqlite default is 2000 - cache_size = cache_bytes / page_size + cache_size = cache_bytes // page_size cursor.execute("PRAGMA cache_size = %d" % cache_size) cursor.execute("PRAGMA cache_size") actual_cache_size = int(cursor.fetchone()[0]) diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index 2086d4c..5b947dd 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -1,7 +1,7 @@ # Copyright 1998-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -from __future__ import unicode_literals +from __future__ import division, unicode_literals __all__ = [ "vardbapi", "vartree", "dblink"] + \ @@ -1043,7 +1043,7 @@ class vardbapi(dbapi): from md5 import new as _new_hash _hash_bits = 16 - _hex_chars = int(_hash_bits / 4) + _hex_chars = _hash_bits // 4 def __init__(self, vardb): self._vardb = vardb diff --git a/pym/portage/localization.py b/pym/portage/localization.py index 7d30b59..2db4b7a 100644 --- a/pym/portage/localization.py +++ b/pym/portage/localization.py @@ -2,6 +2,8 @@ # Copyright 2004-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 +from __future__ import division + import locale import math diff --git a/pym/portage/output.py b/pym/portage/output.py index cd660ac..7846627 100644 --- a/pym/portage/output.py +++ b/pym/portage/output.py @@ -1,6 +1,8 @@ # Copyright 1998-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 +from __future__ import division + __docformat__ = "epytext" import errno @@ -778,14 +780,14 @@ class TermProgressBar(ProgressBar): "<=>" + ((max_bar_width - bar_width) * " ") + "]") return image else: - percentage = int(100 * float(curval) / maxval) + percentage = 100 * curval // maxval max_bar_width = bar_space - 1 _percent = ("%d%% " % percentage).rjust(percentage_str_width) image = "%s%s" % (self._desc, _percent) if cols < min_columns: return image - offset = float(curval) / maxval + offset = curval / maxval bar_width = int(offset * max_bar_width) image = image + "[" + (bar_width * "=") + \ ">" + ((max_bar_width - bar_width) * " ") + "]" diff --git a/pym/portage/util/_eventloop/EventLoop.py b/pym/portage/util/_eventloop/EventLoop.py index 9ffcc74..8095400 100644 --- a/pym/portage/util/_eventloop/EventLoop.py +++ b/pym/portage/util/_eventloop/EventLoop.py @@ -1,6 +1,8 @@ -# Copyright 1999-2013 Gentoo Foundation +# Copyright 1999-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 +from __future__ import division + import errno import logging import os @@ -211,7 +213,7 @@ class EventLoop(object): if timeout is None: wait_timeout = None else: - wait_timeout = float(timeout) / 1000 + wait_timeout = timeout / 1000 # NOTE: In order to avoid a possible infinite wait when # wait_timeout is None, the previous _run_timeouts() # call must have returned False *with* _thread_condition @@ -657,6 +659,6 @@ class _epoll_adapter(object): if timeout is None or timeout < 0: timeout = -1 elif timeout != 0: - timeout = float(timeout) / 1000 + timeout = timeout / 1000 return self._epoll_obj.poll(timeout) diff --git a/pym/portage/util/_eventloop/PollSelectAdapter.py b/pym/portage/util/_eventloop/PollSelectAdapter.py index 244788c..32b404b 100644 --- a/pym/portage/util/_eventloop/PollSelectAdapter.py +++ b/pym/portage/util/_eventloop/PollSelectAdapter.py @@ -1,6 +1,8 @@ -# Copyright 1999-2012 Gentoo Foundation +# Copyright 1999-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 +from __future__ import division + from .PollConstants import PollConstants import select @@ -64,7 +66,7 @@ class PollSelectAdapter(object): if timeout is not None and timeout < 0: timeout = None if timeout is not None: - select_args.append(float(timeout) / 1000) + select_args.append(timeout / 1000) select_events = select.select(*select_args) poll_events = []