From 9dda2b3560416ea232a0303d32809c5f2c8b1025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 26 Jun 2018 19:11:40 +0200 Subject: [PATCH] Remove support for Python 2.7 issue7497 review53261002 --- .drone.yml | 6 ------ CHANGELOG | 1 + INSTALL | 2 +- account.py | 10 +++++----- fiscalyear.py | 5 ++--- move.py | 12 ++++++------ move_template.py | 2 +- party.py | 9 +++------ period.py | 4 ++-- setup.py | 24 +++++++----------------- tax.py | 6 +++--- tests/scenario_move_cancel.rst | 2 +- tests/scenario_move_template.rst | 2 +- tox.ini | 6 +++--- 14 files changed, 36 insertions(+), 55 deletions(-) diff --git a/.drone.yml b/.drone.yml index e0bc2f7026..5da6083eb7 100644 --- a/.drone.yml +++ b/.drone.yml @@ -25,12 +25,6 @@ services: matrix: include: - - IMAGE: python:2.7 - TOXENV: py27 - DATABASE: sqlite - - IMAGE: python:2.7 - TOXENV: py27 - DATABASE: postgresql - IMAGE: python:3.4 TOXENV: py34 DATABASE: sqlite diff --git a/CHANGELOG b/CHANGELOG index 577d40ab4e..eb14c62ce5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Remove support for Python 2.7 * Remove journal type Version 4.8.0 - 2018-04-23 diff --git a/INSTALL b/INSTALL index fdba6fe894..9224ea480f 100644 --- a/INSTALL +++ b/INSTALL @@ -4,7 +4,7 @@ Installing trytond_account Prerequisites ------------- - * Python 2.7 or later (http://www.python.org/) + * Python 3.4 or later (http://www.python.org/) * python-dateutil (http://labix.org/python-dateutil) * python-sql (http://code.google.com/p/python-sql/) * simpleeval (https://github.com/danthedeckie/simpleeval) diff --git a/account.py b/account.py index 26289333e6..248c0a0fb6 100644 --- a/account.py +++ b/account.py @@ -262,7 +262,7 @@ class Type(sequence_ordered(), tree(separator='\\'), ModelSQL, ModelView): if not current.get('comparison'): return dict.fromkeys([t.id for t in types], None) new = {} - for key, value in current.iteritems(): + for key, value in current.items(): if key.endswith('_cmp'): new[key[:-4]] = value with transaction.set_context(new): @@ -1302,7 +1302,7 @@ class GeneralLedgerAccount(DeactivableMixin, ModelSQL, ModelView): Account = pool.get('account.account') account = Account.__table__() columns = [] - for fname, field in cls._fields.iteritems(): + for fname, field in cls._fields.items(): if not hasattr(field, 'set'): columns.append(Column(account, fname).as_(fname)) return account.select(*columns, @@ -1574,7 +1574,7 @@ class GeneralLedgerLine(ModelSQL, ModelView): move = Move.__table__() account = Account.__table__() columns = [] - for fname, field in cls._fields.iteritems(): + for fname, field in cls._fields.items(): if hasattr(field, 'set'): continue field_line = getattr(Line, fname, None) @@ -1985,9 +1985,9 @@ class AgedBalance(ModelSQL, ModelView): # Ensure None are before 0 to get the next index pointing to the next # value and not a None value term_values = sorted( - terms.values(), key=lambda x: ((x is not None), x or 0)) + list(terms.values()), key=lambda x: ((x is not None), x or 0)) - for name, value in terms.iteritems(): + for name, value in terms.items(): if value is None or factor is None or date is None: columns.append(Literal(None).as_(name)) continue diff --git a/fiscalyear.py b/fiscalyear.py index f9725b877d..ede8bee3b8 100644 --- a/fiscalyear.py +++ b/fiscalyear.py @@ -1,6 +1,5 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from __future__ import division from dateutil.relativedelta import relativedelta from trytond.model import ModelView, ModelSQL, Workflow, fields @@ -302,8 +301,8 @@ class FiscalYear(Workflow, ModelSQL, ModelView): accounts = Account.search([ ('company', '=', fiscalyear.company.id), ]) - deferrals += filter(None, (fiscalyear.get_deferral(a) - for a in accounts)) + deferrals += [_f for _f in (fiscalyear.get_deferral(a) + for a in accounts) if _f] Deferral.save(deferrals) @classmethod diff --git a/move.py b/move.py index 897cf989fe..cf0aa6fdd9 100644 --- a/move.py +++ b/move.py @@ -238,7 +238,7 @@ class Move(ModelSQL, ModelView): all_moves = [] args = [] for moves, values in zip(actions, actions): - keys = values.keys() + keys = list(values.keys()) for key in cls._check_modify_exclude: if key in keys: keys.remove(key) @@ -974,7 +974,7 @@ class Line(ModelSQL, ModelView): fiscalyear_id = fiscalyears[0].id else: fiscalyear_id = -1 - fiscalyear_ids = map(int, fiscalyears) + fiscalyear_ids = list(map(int, fiscalyears)) where &= period.fiscalyear == fiscalyear_id where &= move.date <= date elif fiscalyear_id or period_ids or from_date or to_date: @@ -994,7 +994,7 @@ class Line(ModelSQL, ModelView): ('state', '=', 'open'), ('company', '=', company), ]) - fiscalyear_ids = map(int, fiscalyears) + fiscalyear_ids = list(map(int, fiscalyears)) # Use LEFT JOIN to allow database optimization # if no joined table is used in the where clause. @@ -1625,7 +1625,7 @@ class Reconcile(Wizard): for lines in grouped_slice(self._all_lines(), chunk): lines = list(lines) best = None - for n in xrange(len(lines), 1, -1): + for n in range(len(lines), 1, -1): for comb_lines in combinations(lines, n): if requested and not requested.intersection(comb_lines): continue @@ -1638,7 +1638,7 @@ class Reconcile(Wizard): if best: default.extend(best) if not default and requested: - default = map(int, requested) + default = list(map(int, requested)) return default def transition_reconcile(self): @@ -1733,7 +1733,7 @@ class CancelMoves(Wizard): for line in move.lines + cancel_move.lines: if line.account.reconcile: to_reconcile[line.account].append(line) - for lines in to_reconcile.itervalues(): + for lines in to_reconcile.values(): Line.reconcile(lines) return 'end' diff --git a/move_template.py b/move_template.py index a211f09c1f..d004c90d4e 100644 --- a/move_template.py +++ b/move_template.py @@ -138,7 +138,7 @@ class MoveTemplateKeyword(sequence_ordered(), ModelSQL, ModelView): ]) keywords = {k.name: k for k in template.keywords} - for k, v in values.iteritems(): + for k, v in values.items(): keyword = keywords[k] func = getattr(keyword, '_format_%s' % keyword.type_, None) if func: diff --git a/party.py b/party.py index 5bd5ae6a62..0183897740 100644 --- a/party.py +++ b/party.py @@ -22,8 +22,7 @@ account_names = [ 'customer_tax_rule', 'supplier_tax_rule'] -class Party(CompanyMultiValueMixin): - __metaclass__ = PoolMeta +class Party(CompanyMultiValueMixin, metaclass=PoolMeta): __name__ = 'party.party' accounts = fields.One2Many('party.party.account', 'party', "Accounts") account_payable = fields.MultiValue(fields.Many2One( @@ -300,8 +299,7 @@ class PartyAccount(ModelSQL, CompanyValueMixin): parent='party', fields=fields) -class PartyReplace: - __metaclass__ = PoolMeta +class PartyReplace(metaclass=PoolMeta): __name__ = 'party.replace' @classmethod @@ -311,8 +309,7 @@ class PartyReplace: ] -class PartyErase: - __metaclass__ = PoolMeta +class PartyErase(metaclass=PoolMeta): __name__ = 'party.erase' @classmethod diff --git a/period.py b/period.py index 9138ab686d..13aa64b1b8 100644 --- a/period.py +++ b/period.py @@ -272,14 +272,14 @@ class Period(Workflow, ModelSQL, ModelView): actions = iter(args) args = [] for periods, values in zip(actions, actions): - for key, value in values.iteritems(): + for key, value in values.items(): if key in ('start_date', 'end_date', 'fiscalyear'): def modified(period): if key in ['start_date', 'end_date']: return getattr(period, key) != value else: return period.fiscalyear .id != value - cls._check(filter(modified, periods)) + cls._check(list(filter(modified, periods))) break if values.get('state') == 'open': for period in periods: diff --git a/setup.py b/setup.py index 8fcd71dd01..7947ca1342 100644 --- a/setup.py +++ b/setup.py @@ -1,15 +1,12 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -from setuptools import setup -import re -import os import io -try: - from configparser import ConfigParser -except ImportError: - from ConfigParser import ConfigParser +import os +import re +from configparser import ConfigParser +from setuptools import setup def read(fname): @@ -27,6 +24,7 @@ def get_require_version(name): major_version, minor_version + 1) return require + config = ConfigParser() config.readfp(open('tryton.cfg')) info = dict(config.items('tryton')) @@ -102,7 +100,6 @@ setup(name=name, 'Natural Language :: Slovenian', 'Natural Language :: Spanish', 'Operating System :: OS Independent', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', @@ -112,6 +109,7 @@ setup(name=name, 'Topic :: Office/Business :: Financial :: Accounting', ], license='GPL-3', + python_requires='>=3.4', install_requires=requires, dependency_links=dependency_links, zip_safe=False, @@ -122,12 +120,4 @@ setup(name=name, test_suite='tests', test_loader='trytond.test_loader:Loader', tests_require=tests_require, - use_2to3=True, - convert_2to3_doctests=[ - 'tests/scenario_account_reconciliation.rst', - 'tests/scenario_move_cancel.rst', - 'tests/scenario_move_template.rst', - 'tests/scenario_reports.rst', - 'tests/scenario_renew_fiscalyear.rst', - ], ) diff --git a/tax.py b/tax.py index 9f20ad625b..65f744b6a3 100644 --- a/tax.py +++ b/tax.py @@ -197,7 +197,7 @@ class TaxCode(DeactivableMixin, tree(), ModelSQL, ModelView): parents[code.id] = code.parent.id if code.parent else None ids = set(map(int, childs)) - leafs = ids - set(parents.itervalues()) + leafs = ids - set(parents.values()) while leafs: for code in leafs: ids.remove(code) @@ -817,7 +817,7 @@ class Tax(sequence_ordered(), ModelSQL, ModelView, DeactivableMixin): move_line = MoveLine.__table__() tax_line = TaxLine.__table__() - tax_ids = map(int, taxes) + tax_ids = list(map(int, taxes)) result = {} for name in names: result[name] = dict.fromkeys(tax_ids, Decimal(0)) @@ -1140,7 +1140,7 @@ class TaxableMixin(object): def _round_taxes(self, taxes): if not self.currency: return - for taxline in taxes.itervalues(): + for taxline in taxes.values(): taxline['amount'] = self.currency.round(taxline['amount']) def _get_taxes(self): diff --git a/tests/scenario_move_cancel.rst b/tests/scenario_move_cancel.rst index 504662b4a3..4a101285a6 100644 --- a/tests/scenario_move_cancel.rst +++ b/tests/scenario_move_cancel.rst @@ -91,7 +91,7 @@ Cancel Move:: >>> cancel_move.origin == move True >>> cancel_move.description - u'Cancel' + 'Cancel' >>> revenue.reload() >>> revenue.credit Decimal('0.00') diff --git a/tests/scenario_move_template.rst b/tests/scenario_move_template.rst index 4f44d6b993..36c9700ec1 100644 --- a/tests/scenario_move_template.rst +++ b/tests/scenario_move_template.rst @@ -116,7 +116,7 @@ Check the Move:: >>> sorted((l.debit, l.credit) for l in move.lines) [(Decimal('0'), Decimal('12.24')), (Decimal('1.11'), Decimal('0')), (Decimal('11.13'), Decimal('0'))] >>> move.description - u'Supplier - Test' + 'Supplier - Test' >>> with config.set_context(periods=period_ids): ... base_code = TaxCode(base_code.id) ... base_code.amount diff --git a/tox.ini b/tox.ini index 2082ab4f4d..adbcbf8431 100644 --- a/tox.ini +++ b/tox.ini @@ -1,11 +1,11 @@ [tox] -envlist = {py27,py34,py35,py36}-{sqlite,postgresql},pypy-{sqlite,postgresql} +envlist = {py34,py35,py36}-{sqlite,postgresql},pypy3-{sqlite,postgresql} [testenv] commands = {envpython} setup.py test deps = - {py27,py34,py35,py36}-postgresql: psycopg2 >= 2.5 - pypy-postgresql: psycopg2cffi >= 2.5 + {py34,py35,py36}-postgresql: psycopg2 >= 2.5 + pypy3-postgresql: psycopg2cffi >= 2.5 sqlite: sqlitebck setenv = sqlite: TRYTOND_DATABASE_URI={env:SQLITE_URI:sqlite://}