From 6c5f4f9d70c66d0697d83262cfda14eee15d491a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 26 Jun 2018 19:11:48 +0200 Subject: [PATCH] Remove support for Python 2.7 issue7497 review53261002 --- .drone.yml | 6 ------ CHANGELOG | 2 ++ INSTALL | 2 +- address.py | 6 +++--- contact_mechanism.py | 2 +- party.py | 8 ++++---- setup.py | 21 +++++++-------------- tests/scenario_party_erase.rst | 2 +- tests/test_party.py | 10 +++++----- tox.ini | 6 +++--- 10 files changed, 27 insertions(+), 38 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 182f290981..16277430e1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Remove support for Python 2.7 + Version 4.8.0 - 2018-04-23 * Bug fixes (see mercurial logs for details) * Add Erase Party wizard diff --git a/INSTALL b/INSTALL index 69e9703025..9beb6c3650 100644 --- a/INSTALL +++ b/INSTALL @@ -4,7 +4,7 @@ Installing trytond_party Prerequisites ------------- - * Python 2.7 or later (http://www.python.org/) + * Python 3.4 or later (http://www.python.org/) * trytond (http://www.tryton.org/) * trytond_country (http://www.tryton.org/) * python-stdnum (http://arthurdejong.org/python-stdnum/) diff --git a/address.py b/address.py index edce573fe4..9bf3f48401 100644 --- a/address.py +++ b/address.py @@ -148,7 +148,7 @@ class Address(DeactivableMixin, sequence_ordered(), ModelSQL, ModelView): if context.get('address_with_party', False): substitutions['party_name'] = (self.party.full_name if getattr(self, 'party', None) else '') - for key, value in substitutions.items(): + for key, value in list(substitutions.items()): substitutions[key.upper()] = value.upper() return substitutions @@ -276,7 +276,7 @@ ${COUNTRY}""" try: Template(self.format_).substitute( **address._get_address_substitutions()) - except Exception, exception: + except Exception as exception: self.raise_user_error('invalid_format', { 'format': self.format_, 'exception': exception, @@ -303,7 +303,7 @@ ${COUNTRY}""" language = None pattern.setdefault('language', language.id if language else None) - key = tuple(sorted(pattern.iteritems())) + key = tuple(sorted(pattern.items())) format_ = cls._get_format_cache.get(key) if format_ is not None: return format_ diff --git a/contact_mechanism.py b/contact_mechanism.py index 32b7efe72e..c177484da6 100644 --- a/contact_mechanism.py +++ b/contact_mechanism.py @@ -271,6 +271,6 @@ class ContactMechanism( "Returns the selection list of usage" usages = [(None, "")] if _fields: - for name, desc in cls.fields_get(_fields).iteritems(): + for name, desc in cls.fields_get(_fields).items(): usages.append((name, desc['string'])) return usages diff --git a/party.py b/party.py index 4ee291e5cb..47f698ceef 100644 --- a/party.py +++ b/party.py @@ -240,7 +240,7 @@ class Party(DeactivableMixin, ModelSQL, ModelView, MultiValueMixin): """ default_mechanism = None if types: - if isinstance(types, basestring): + if isinstance(types, str): types = {types} mechanisms = [m for m in self.contact_mechanisms if m.type in types] @@ -431,7 +431,7 @@ class CheckVIES(Wizard): parties_failed.append(party.id) else: parties_succeed.append(party.id) - except Exception, e: + except Exception as e: if hasattr(e, 'faultstring') \ and hasattr(e.faultstring, 'find'): if e.faultstring.find('INVALID_INPUT'): @@ -604,7 +604,7 @@ class PartyErase(Wizard): table = table.join(right, condition=condition) else: table = right - for k, sub_tables in tables.iteritems(): + for k, sub_tables in tables.items(): if k is None: continue table = convert_from(table, sub_tables) @@ -615,7 +615,7 @@ class PartyErase(Wizard): with Transaction().set_context(active_test=False): while replacing: replacing = Party.search([ - ('replaced_by', 'in', map(int, replacing)), + ('replaced_by', 'in', list(map(int, replacing))), ]) parties += replacing for party in parties: diff --git a/setup.py b/setup.py index d69b0383e8..10855f37d9 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')) @@ -103,7 +101,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', ], license='GPL-3', + python_requires='>=3.4', install_requires=requires, extras_require={ 'VIES': ['python-stdnum[VIES]'], @@ -127,9 +125,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_party_replace.rst', - 'tests/scenario_party_erase.rst', - ], ) diff --git a/tests/scenario_party_erase.rst b/tests/scenario_party_erase.rst index 2e0ab81871..0d17e9c642 100644 --- a/tests/scenario_party_erase.rst +++ b/tests/scenario_party_erase.rst @@ -55,7 +55,7 @@ Check fields have been erased:: >>> party.name >>> identifier.reload() >>> identifier.code - u'****' + '****' >>> address.reload() >>> address.street >>> address.city diff --git a/tests/test_party.py b/tests/test_party.py index 3771655571..33981a1588 100644 --- a/tests/test_party.py +++ b/tests/test_party.py @@ -28,7 +28,7 @@ class PartyTestCase(ModuleTestCase): category1, = Category.create([{ 'name': 'Category 1', }]) - self.assert_(category1.id) + self.assertTrue(category1.id) @with_transaction() def test_category_recursion(self): @@ -42,7 +42,7 @@ class PartyTestCase(ModuleTestCase): 'name': 'Category 2', 'parent': category1.id, }]) - self.assert_(category2.id) + self.assertTrue(category2.id) self.assertRaises(Exception, Category.write, [category1], { 'parent': category2.id, @@ -56,7 +56,7 @@ class PartyTestCase(ModuleTestCase): party1, = Party.create([{ 'name': 'Party 1', }]) - self.assert_(party1.id) + self.assertTrue(party1.id) @with_transaction() def test_party_code(self): @@ -92,7 +92,7 @@ class PartyTestCase(ModuleTestCase): 'street': 'St sample, 15', 'city': 'City', }]) - self.assert_(address.id) + self.assertTrue(address.id) self.assertMultiLineEqual(address.full_address, "St sample, 15\n" "City") @@ -219,7 +219,7 @@ class PartyTestCase(ModuleTestCase): pool = Pool() Party = pool.get('party.party') party2, = Party.create([{}]) - self.assert_(party2.id) + self.assertTrue(party2.id) code = party2.code self.assertEqual(party2.rec_name, '[' + code + ']') 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://}