Skip to content

Commit

Permalink
Misc: Remove conditions on Python version
Browse files Browse the repository at this point in the history
Issue #2201
  • Loading branch information
nijel committed Feb 20, 2020
1 parent 8adafb7 commit 119245d
Show file tree
Hide file tree
Showing 17 changed files with 11 additions and 85 deletions.
3 changes: 1 addition & 2 deletions weblate/formats/models.py
Expand Up @@ -19,7 +19,6 @@
#


import six
from appconf import AppConf
from django.utils.functional import cached_property

Expand Down Expand Up @@ -50,7 +49,7 @@ def load_data(self):
fileformat.get_class()
except (AttributeError, ImportError) as error:
result.pop(fileformat.format_id)
if fileformat.format_id != 'rc' or not six.PY3:
if fileformat.format_id != 'rc':
self.errors[fileformat.format_id] = str(error)

return result
Expand Down
3 changes: 0 additions & 3 deletions weblate/formats/tests/test_formats.py
Expand Up @@ -24,7 +24,6 @@
from io import BytesIO
from unittest import SkipTest, TestCase

import six
import translate.__version__
from django.utils.encoding import force_text
from translate.storage.po import pofile
Expand Down Expand Up @@ -561,8 +560,6 @@ class PoXliffFormatTest2(PoXliffFormatTest):
FIND_MATCH = 'Ahoj světe!\n'

def test_save(self, edit=False):
if six.PY2:
raise SkipTest('Known to be broken on Python 2')
super(PoXliffFormatTest2, self).test_save(edit)


Expand Down
4 changes: 1 addition & 3 deletions weblate/formats/ttkit.py
Expand Up @@ -1174,9 +1174,7 @@ def extension():
@classmethod
def get_class(cls):
"""Return class for handling this module."""
if six.PY3:
raise ImportError('Windows RC file format unsupported on Python 3')
return importlib.import_module('translate.storage.rc').rcfile
raise ImportError('Windows RC file format unsupported on Python 3')


class SubtitleUnit(MonolingualIDUnit):
Expand Down
7 changes: 2 additions & 5 deletions weblate/lang/tests.py
Expand Up @@ -28,7 +28,7 @@
from django.urls import reverse
from django.utils.encoding import force_text
from django.utils.translation import activate
from six import PY2, StringIO, with_metaclass
from six import StringIO, with_metaclass

from weblate.lang import data
from weblate.lang.models import Language, Plural, get_plural_type
Expand Down Expand Up @@ -228,10 +228,7 @@ def test_setuplang_noupdate(self):
def check_list(self, **kwargs):
output = StringIO()
call_command('list_languages', 'cs', stdout=output, **kwargs)
if PY2:
self.assertIn(b'Czech', output.getvalue())
else:
self.assertIn('Czech', output.getvalue())
self.assertIn('Czech', output.getvalue())

def test_list_languages(self):
self.check_list()
Expand Down
5 changes: 1 addition & 4 deletions weblate/machinery/saptranslationhub.py
Expand Up @@ -21,7 +21,6 @@
import base64
import json

import six
from django.conf import settings
from six.moves.urllib.request import Request, urlopen

Expand Down Expand Up @@ -90,9 +89,7 @@ def download_translations(self, source, language, text, unit, user):

# create the request
translation_url = settings.MT_SAP_BASE_URL + 'translate'
request = Request(
translation_url if six.PY3 else translation_url.encode("utf-8")
)
request = Request(translation_url)
request.add_header('User-Agent', USER_AGENT.encode('utf-8'))
request.add_header('Referer', get_site_url().encode('utf-8'))
request.add_header('Content-Type', 'application/json; charset=utf-8')
Expand Down
3 changes: 1 addition & 2 deletions weblate/trans/tests/test_selenium.py
Expand Up @@ -25,7 +25,7 @@
from contextlib import contextmanager
from datetime import timedelta
from io import BytesIO
from unittest import SkipTest, skipIf
from unittest import SkipTest

import six
import social_django.utils
Expand Down Expand Up @@ -1048,7 +1048,6 @@ def test_fonts(self):

self.screenshot("font-group-list.png")

@skipIf(six.PY2, "borgbackup does not support Python 2")
def test_backup(self):
self.create_temp()
try:
Expand Down
7 changes: 0 additions & 7 deletions weblate/trans/util.py
Expand Up @@ -23,7 +23,6 @@
import os
import sys

import six
from django.apps import apps
from django.core.cache import cache
from django.db.utils import OperationalError, ProgrammingError
Expand Down Expand Up @@ -204,10 +203,6 @@ def get_clean_env(extra=None):
venv_path = os.path.join(sys.exec_prefix, "bin")
if venv_path not in environ['PATH']:
environ['PATH'] = '{}:{}'.format(venv_path, environ['PATH'])
# Python 2 on Windows doesn't handle Unicode objects in environment
# even if they can be converted to ASCII string, let's fix it here
if six.PY2 and sys.platform == 'win32':
return {str(key): str(val) for key, val in environ.items()}
return environ


Expand Down Expand Up @@ -270,8 +265,6 @@ def path_separator(path):

def sort_unicode(choices, key):
"""Unicode aware sorting if available."""
if six.PY2:
return sorted(choices, key=lambda tup: locale.strxfrm(key(tup).encode('utf-8')))
return sorted(choices, key=lambda tup: locale.strxfrm(key(tup)))


Expand Down
12 changes: 2 additions & 10 deletions weblate/trans/views/api.py
Expand Up @@ -21,7 +21,6 @@

import csv

import six
from django.http import HttpResponse, JsonResponse

from weblate.trans.stats import get_project_stats
Expand Down Expand Up @@ -92,14 +91,7 @@ def export_response(request, filename, fields, data):
writer = csv.DictWriter(response, fields)

writer.writeheader()
if six.PY2:
for row in data:
for item in row:
if isinstance(row[item], six.text_type):
row[item] = row[item].encode('utf-8')
writer.writerow(row)
else:
for row in data:
writer.writerow(row)
for row in data:
writer.writerow(row)
return response
return JsonResponse(data=data, safe=False, json_dumps_params={'indent': 2})
8 changes: 2 additions & 6 deletions weblate/trans/views/changes.py
Expand Up @@ -18,7 +18,8 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import six
import csv

from django.contrib.auth.decorators import login_required
from django.core.exceptions import PermissionDenied
from django.db.models import Q
Expand All @@ -39,11 +40,6 @@
from weblate.utils.site import get_site_url
from weblate.utils.views import get_project_translation

if six.PY2:
from backports import csv
else:
import csv


class ChangesView(ListView):
"""Browser for changes."""
Expand Down
2 changes: 0 additions & 2 deletions weblate/utils/apps.py
Expand Up @@ -29,7 +29,6 @@
check_errors,
check_mail_connection,
check_perms,
check_python,
check_settings,
check_site,
check_templates,
Expand All @@ -56,7 +55,6 @@ def ready(self):
register(check_site, deploy=True)
register(check_perms, deploy=True)
register(check_errors, deploy=True)
register(check_python, deploy=True)
register(check_version)

monkey_patch_translate()
Expand Down
15 changes: 0 additions & 15 deletions weblate/utils/checks.py
Expand Up @@ -346,18 +346,3 @@ def check_errors(app_configs=None, **kwargs):
id='weblate.I021',
)
]


def check_python(app_configs=None, **kwargs):
"""Early warning for users needing to migrate to Python 3."""
if six.PY3:
return []
return [
Error(
'Please upgrade your installation to Python 3. '
'Python 2 support will be dropped in Weblate 4.0 '
'currently sheduled on April 2020.',
hint=get_doc_url('admin/upgrade', 'py3'),
id='weblate.W023',
)
]
4 changes: 1 addition & 3 deletions weblate/utils/requirements.py
Expand Up @@ -23,7 +23,6 @@
import sys

import pkg_resources
import six
from django.core.exceptions import ImproperlyConfigured

import weblate
Expand Down Expand Up @@ -73,9 +72,8 @@
"Cython",
"misaka",
"GitPython",
"borgbackup",
]
if six.PY3:
REQUIRES.append("borgbackup")

OPTIONAL = [
"psycopg2",
Expand Down
4 changes: 0 additions & 4 deletions weblate/utils/tests/test_backup.py
Expand Up @@ -20,9 +20,7 @@

import json
import os
from unittest import skipIf

import six
from django.conf import settings
from django.test import SimpleTestCase
from django.test.utils import override_settings
Expand All @@ -36,7 +34,6 @@

class BackupTest(SimpleTestCase):
@tempdir_setting("DATA_DIR")
@skipIf(six.PY2, 'override_settings seems to be broken on Python 2')
def test_settings_backup(self):
settings_backup()
filename = data_dir("backups", "settings.py")
Expand All @@ -53,7 +50,6 @@ def test_memory_backup(self):

@tempdir_setting("DATA_DIR")
@tempdir_setting("BACKUP_DIR")
@skipIf(six.PY2, 'borgbackup does not support Python 2')
def test_backup(self):
initialize(settings.BACKUP_DIR, "key")
output = get_paper_key(settings.BACKUP_DIR)
Expand Down
6 changes: 0 additions & 6 deletions weblate/utils/tests/test_search.py
Expand Up @@ -20,9 +20,7 @@


from datetime import datetime
from unittest import SkipTest

import six
from django.db.models import Q
from django.test import SimpleTestCase, TestCase
from pytz import utc
Expand Down Expand Up @@ -51,10 +49,6 @@ def test_long(self):


class QueryParserTest(TestCase):
def setUp(self):
if six.PY2:
raise SkipTest("Test not working on Python 2")

def assert_query(self, string, expected):
result = parse_query(string)
self.assertEqual(result, expected)
Expand Down
3 changes: 0 additions & 3 deletions weblate/vcs/base.py
Expand Up @@ -27,7 +27,6 @@
import subprocess
from distutils.version import LooseVersion

import six
from dateutil import parser
from django.conf import settings
from django.core.cache import cache
Expand Down Expand Up @@ -150,8 +149,6 @@ def _popen(
if not fullcmd:
args = [cls._cmd] + list(args)
text_cmd = ' '.join(args)
if six.PY2:
args = [arg.encode('utf-8') for arg in args]
process = subprocess.Popen(
args,
cwd=cwd,
Expand Down
7 changes: 0 additions & 7 deletions weblate/vcs/mercurial.py
Expand Up @@ -24,7 +24,6 @@
import os.path
import re

import six
from six.moves.configparser import RawConfigParser

from weblate.vcs.base import Repository, RepositoryException
Expand Down Expand Up @@ -85,8 +84,6 @@ def get_config(self, path):
config.read(filename)
if config.has_option(section, option):
result = config.get(section, option)
if six.PY2:
result = result.decode('utf-8')
return result

def set_config(self, path, value):
Expand All @@ -95,10 +92,6 @@ def set_config(self, path, value):
raise RuntimeError('Repository operation without lock held!')
section, option = path.split('.', 1)
filename = os.path.join(self.path, '.hg', 'hgrc')
if six.PY2:
value = value.encode('utf-8')
section = section.encode('utf-8')
option = option.encode('utf-8')
config = RawConfigParser()
config.read(filename)
if not config.has_section(section):
Expand Down
3 changes: 0 additions & 3 deletions weblate/wladmin/tests.py
Expand Up @@ -20,11 +20,9 @@

import json
import os
from unittest import skipIf

import django
import httpretty
import six
from django.conf import settings
from django.core.serializers.json import DjangoJSONEncoder
from django.test.utils import override_settings
Expand Down Expand Up @@ -96,7 +94,6 @@ def test_ssh_add(self):
self.assertIn("github.com", handle.read())

@tempdir_setting("BACKUP_DIR")
@skipIf(six.PY2, "borgbackup does not support Python 2")
def test_backup(self):
def do_post(**payload):
return self.client.post(reverse("manage-backups"), payload, follow=True)
Expand Down

0 comments on commit 119245d

Please sign in to comment.