Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removal of python-future compatibility code #531

Merged
merged 23 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
30907df
Remove all imports of print_function compatibility method
knabar Feb 6, 2024
bfbe350
Replace all instances of isbytes and bytes_to_native_str
knabar Feb 6, 2024
2d9b411
Replace all usages of past.builtins.basestring
knabar Feb 6, 2024
f25db1a
Remove usage of past.builtins.long and "import long"
knabar Feb 6, 2024
6a71b74
Remove usage of future.standard_library.install_aliases
knabar Feb 6, 2024
8fa11fa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 6, 2024
d9f88d2
Cleanup miscellaneous Python 2 codepaths
knabar Feb 7, 2024
e8f8ca5
Remove all unnecessary builtins imports
knabar Feb 7, 2024
913b76b
Remove future dependency
knabar Feb 7, 2024
5671f8e
Clean up outdated Docker infrastructure
knabar Feb 7, 2024
7db0f55
Remove Python version check
knabar Feb 7, 2024
0c4bc24
Remove more Python 2 compatibility code
knabar Feb 7, 2024
bb3a7f1
Fix flake8
knabar Feb 7, 2024
43a887f
Update build matrix by adding 3.12 and removing 3.8
knabar Feb 7, 2024
d4368c0
Fix flake8
knabar Feb 7, 2024
2edac67
Temporarily point at omero-py GitHub branch with Python 3.12 changes
sbesson Feb 8, 2024
5112ea7
Add Python 3.8 back to build matrix
knabar Feb 8, 2024
ad3ac72
Clean up thread check
knabar Feb 8, 2024
52c84a6
Temporarily require omero-py development branch
knabar Feb 8, 2024
538c256
Set omero-py version
knabar Feb 23, 2024
03ca53e
Remove custom omero-py version from tox
knabar Feb 23, 2024
7ddf814
Fix missing build matrix entry
knabar Feb 27, 2024
60ce356
Remove comment
knabar Feb 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if isinstance(value, str) then we don't need to do anything - can pass here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably left it in because I wasn't sure that smart_str would not do something

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also worth noting this is a deprecated form (scheduled for removal in a future version) so I would not spend extensive time fixing it.

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
sbesson marked this conversation as resolved.
Show resolved Hide resolved
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
Loading