Skip to content

Commit

Permalink
Merge pull request #531 from knabar/maint-python2-cleanup
Browse files Browse the repository at this point in the history
Removal of python-future compatibility code
  • Loading branch information
knabar authored Mar 1, 2024
2 parents f8fe73c + 60ce356 commit 4d8d25e
Show file tree
Hide file tree
Showing 29 changed files with 117 additions and 293 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ jobs:
- '3.9'
- '3.10'
- '3.11'
- '3.12'
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: python -mpip install --upgrade wheel pytest tox
run: python -mpip install --upgrade wheel pytest tox setuptools
- name: Get tox target
id: toxtarget
run: |
Expand Down
30 changes: 0 additions & 30 deletions Dockerfile

This file was deleted.

11 changes: 2 additions & 9 deletions omero/plugins/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"""

import traceback
from future.utils import bytes_to_native_str
from datetime import datetime
from omero.cli import DiagnosticsControl
from omero.cli import CLI
Expand All @@ -21,11 +20,7 @@
from functools import wraps
from omero_ext.argparse import SUPPRESS

try:
from omero_ext.path import path
except ImportError:
# Python 2
from path import path
from omero_ext.path import path
from pkg_resources import resource_string

from omero.install.windows_warning import windows_warning, WINDOWS_WARNING
Expand Down Expand Up @@ -348,9 +343,7 @@ def config(self, args, settings):
self.ctx.die(679, "Web template configuration requires" "wsgi or wsgi-tcp.")

template_file = "%s.conf.template" % server
c = bytes_to_native_str(
resource_string("omeroweb", "templates/" + template_file)
)
c = resource_string("omeroweb", "templates/" + template_file).decode("utf-8")
self.ctx.out(c % d)

def syncmedia(self, args):
Expand Down
5 changes: 1 addition & 4 deletions omeroweb/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import re
import logging

from future.utils import with_metaclass

from omero import client_wrapper
from omeroweb.version import omeroweb_version as omero_version

Expand All @@ -40,8 +38,7 @@ def __iter__(cls):
return iter(cls._registry.values())


# with_metaclass to support python2 and python3
class ServerBase(with_metaclass(IterRegistry)):
class ServerBase(metaclass=IterRegistry):
_next_id = 1

def __init__(self, host, port, server=None):
Expand Down
11 changes: 4 additions & 7 deletions omeroweb/custom_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#

import warnings
from past.builtins import basestring
from django import forms
from django.utils.encoding import smart_str

Expand Down Expand Up @@ -62,12 +61,10 @@ def full_clean(self):
initial = self.initial.get(name, field.initial)
value = field.clean(value, initial)
elif isinstance(field, CharField):
if (
value is not None
and isinstance(value, basestring)
and len(value) > 0
):
value = str(smart_str(value))
if value is not None and isinstance(value, str) and len(value) > 0:
value = str(
smart_str(value)
) # TODO: This is probably a noop now
else:
value = field.clean(value)
else:
Expand Down
16 changes: 3 additions & 13 deletions omeroweb/feedback/sendfeedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,9 @@
import logging
from urllib.parse import urlencode

try:
# python2
from urllib2 import urlopen, Request, HTTPError, URLError
except ImportError:
# python3
from urllib.request import urlopen, Request
from urllib.error import HTTPError, URLError
try:
# python2
from urlparse import urljoin
except ImportError:
# python3
from urllib.parse import urljoin
from urllib.request import urlopen, Request
from urllib.error import HTTPError, URLError
from urllib.parse import urljoin

from omeroweb.version import omeroweb_version as omero_version

Expand Down
2 changes: 1 addition & 1 deletion omeroweb/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
# exceptions.
try:
import django
except ImportError:
Expand Down
19 changes: 3 additions & 16 deletions omeroweb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import json
import random
import string
from builtins import str as text
import portalocker

from omero.util.concurrency import get_event
Expand Down Expand Up @@ -1259,18 +1258,6 @@ def check_worker_class(c):
return str(c)


def check_threading(t):
t = int(t)
if t > 1:
try:
import concurrent.futures # NOQA
except ImportError:
raise ImportError(
"You are using sync workers with " "multiple threads. Install futures"
)
return t


# DEVELOPMENT_SETTINGS_MAPPINGS - WARNING: For each setting developer MUST open
# a ticket that needs to be resolved before a release either by moving the
# setting to CUSTOM_SETTINGS_MAPPINGS or by removing the setting at all.
Expand Down Expand Up @@ -1298,7 +1285,7 @@ def check_threading(t):
"omero.web.wsgi_threads": [
"WSGI_THREADS",
1,
check_threading,
int,
(
"(SYNC WORKERS only) The number of worker threads for handling "
"requests. Check Gunicorn Documentation "
Expand Down Expand Up @@ -1770,8 +1757,8 @@ def report_settings(module):
# Load server list and freeze
def load_server_list():
for s in SERVER_LIST: # from CUSTOM_SETTINGS_MAPPINGS # noqa
server = (len(s) > 2) and text(s[2]) or None
Server(host=text(s[0]), port=int(s[1]), server=server)
server = (len(s) > 2) and str(s[2]) or None
Server(host=str(s[0]), port=int(s[1]), server=server)
Server.freeze()


Expand Down
4 changes: 0 additions & 4 deletions omeroweb/testlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
"""
Library for Web integration tests
"""
from __future__ import print_function

from future import standard_library
import json
import warnings

Expand All @@ -32,7 +29,6 @@

from omero.testlib import ITest

standard_library.install_aliases() # noqa
from urllib.parse import urlencode # noqa


Expand Down
3 changes: 1 addition & 2 deletions omeroweb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from django.utils.http import urlencode
from django.urls import reverse
from django.urls import NoReverseMatch
from past.builtins import basestring


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -95,7 +94,7 @@ def reverse_with_params(*args, **kwargs):
except NoReverseMatch:
return url
if qs:
if not isinstance(qs, basestring):
if not isinstance(qs, str):
qs = urlencode(qs)
url += "?" + qs
return url
Expand Down
24 changes: 11 additions & 13 deletions omeroweb/webadmin/custom_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
from django.utils.encoding import smart_str
from django.core.validators import validate_email, EMPTY_VALUES

from past.builtins import long


##################################################################
# Fields
Expand Down Expand Up @@ -101,7 +99,7 @@ def to_python(self, value):
return None
res = False
for q in self.queryset:
if long(value) == q.id:
if int(value) == q.id:
res = True
if not res:
raise ValidationError(self.error_messages["invalid_choice"])
Expand Down Expand Up @@ -167,10 +165,10 @@ def to_python(self, value):
exps = self.queryset
for experimenter in exps:
if hasattr(experimenter.id, "val"):
if long(value) == experimenter.id.val:
if int(value) == experimenter.id.val:
res = True
else:
if long(value) == experimenter.id:
if int(value) == experimenter.id:
res = True
if not res:
raise ValidationError(self.error_messages["invalid_choice"])
Expand Down Expand Up @@ -221,17 +219,17 @@ def to_python(self, value):
final_values = []
for val in value:
try:
long(val)
int(val)
except Exception:
raise ValidationError(self.error_messages["invalid_choice"])
else:
res = False
for q in self.queryset:
if hasattr(q.id, "val"):
if long(val) == q.id.val:
if int(val) == q.id.val:
res = True
else:
if long(val) == q.id:
if int(val) == q.id:
res = True
if not res:
raise ValidationError(self.error_messages["invalid_choice"])
Expand Down Expand Up @@ -354,9 +352,9 @@ def checkValue(q, value):
if not hasattr(q, "id"):
return False
if hasattr(q.id, "val"):
if long(value) == q.id.val:
if int(value) == q.id.val:
return True
if long(value) == q.id:
if int(value) == q.id:
return True

for q in self.queryset:
Expand Down Expand Up @@ -421,17 +419,17 @@ def to_python(self, value):
final_values = []
for val in value:
try:
long(val)
int(val)
except Exception:
raise ValidationError(self.error_messages["invalid_choice"])
else:
res = False
for q in self.queryset:
if hasattr(q.id, "val"):
if long(val) == q.id.val:
if int(val) == q.id.val:
res = True
else:
if long(val) == q.id:
if int(val) == q.id:
res = True
if not res:
raise ValidationError(self.error_messages["invalid_choice"])
Expand Down
5 changes: 1 addition & 4 deletions omeroweb/webadmin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@

import logging

try:
from collections import OrderedDict # Python 2.7+ only
except Exception:
pass
from collections import OrderedDict

from django import forms
from django.forms.widgets import Textarea
Expand Down
9 changes: 4 additions & 5 deletions omeroweb/webclient/controller/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import datetime
import time

from past.builtins import long
from django.conf import settings

from omeroweb.webclient.controller import BaseController
Expand Down Expand Up @@ -172,8 +171,8 @@ def calendar_items(self, month, monthrange):
("%i-%s-%i 23:59:59" % (self.year, mn, monthrange)), "%Y-%m-%d %H:%M:%S"
)

start = long(time.mktime(d1.timetuple()) + 1e-6 * d1.microsecond) * 1000
end = long(time.mktime(d2.timetuple()) + 1e-6 * d2.microsecond) * 1000
start = int(time.mktime(d1.timetuple()) + 1e-6 * d1.microsecond) * 1000
end = int(time.mktime(d2.timetuple()) + 1e-6 * d2.microsecond) * 1000
all_logs = self.conn.getEventsByPeriod(start, end, self.eid)

items = dict()
Expand Down Expand Up @@ -218,8 +217,8 @@ def get_items(self, page=None):
("%i-%s-%s 23:59:59" % (self.year, mn, dy)), "%Y-%m-%d %H:%M:%S"
)

start = long(time.mktime(d1.timetuple()) + 1e-6 * d1.microsecond) * 1000
end = long(time.mktime(d2.timetuple()) + 1e-6 * d2.microsecond) * 1000
start = int(time.mktime(d1.timetuple()) + 1e-6 * d1.microsecond) * 1000
end = int(time.mktime(d2.timetuple()) + 1e-6 * d2.microsecond) * 1000

self.day_items = list()
self.day_items_size = 0
Expand Down
5 changes: 2 additions & 3 deletions omeroweb/webclient/controller/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
# Version: 1.0
#

from past.builtins import long
import time
import omero
import logging
Expand Down Expand Up @@ -89,11 +88,11 @@ def search(

created = [
rtime(
long(time.mktime(d1.timetuple()) + 1e-6 * d1.microsecond)
int(time.mktime(d1.timetuple()) + 1e-6 * d1.microsecond)
* 1000
),
rtime(
long(time.mktime(d2.timetuple()) + 1e-6 * d2.microsecond)
int(time.mktime(d2.timetuple()) + 1e-6 * d2.microsecond)
* 1000
),
]
Expand Down
Loading

0 comments on commit 4d8d25e

Please sign in to comment.