Skip to content

Commit

Permalink
Drop Python 2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
benmwebb committed Aug 12, 2020
1 parent 234053a commit 2ccf0d4
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 55 deletions.
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
language: python
dist: bionic
python:
- 2.7
- 3.6
- 3.7
- 3.8
matrix:
include:
- dist: trusty
python: 2.6
addons:
apt:
packages:
Expand Down
7 changes: 3 additions & 4 deletions doc/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ used in other environments with some modification.
Prerequisites
-------------

* Python. The backend of the framework, which takes care of running jobs,
is implemented in Python. It requires Python 2.6 or later (it should
also work with Python 3).
* Python 3. The backend of the framework, which takes care of running jobs,
is implemented in Python. (It does not work with Python 2.)

* `Flask <http://flask.pocoo.org/>`_. The frontend, which handles user
submission of jobs and the display of results, is implemented in Python,
submission of jobs and the display of results, is implemented in Python 3,
and uses the Flask microframework.

* SGE. The framework expects to be run on a machine that is a submit host to a Sun GridEngine compute cluster
Expand Down
43 changes: 15 additions & 28 deletions python/saliweb/backend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import subprocess
import re
import fcntl
Expand All @@ -8,37 +7,25 @@
import datetime
import shutil
import time
try:
import configparser
except ImportError: # python 2.6
import ConfigParser as configparser
import configparser
import traceback
import select
import signal
import socket
import logging
import threading
try:
import urllib.request as urllib2 # python 3
except ImportError:
import urllib2 # python 2
try:
import urlparse # python 2
except ImportError:
import urllib.parse as urlparse # python 3
import urllib.request
import urllib.parse
import saliweb.web_service
import saliweb.backend.events
import saliweb.backend.sge
from saliweb.backend.events import _JobThread
try:
from email.MIMEText import MIMEText # python 2
except ImportError:
from email.mime.text import MIMEText # python 3
from email.mime.text import MIMEText


# Version check; we need 2.4 for subprocess, decorators, generator expressions
if sys.version_info[0:2] < (2, 4):
raise ImportError("This module requires Python 2.4 or later")
# Version check
if sys.version_info[0:2] < (3, 6):
raise ImportError("This module requires Python 3.6 or later")


class InvalidStateError(Exception):
Expand Down Expand Up @@ -222,19 +209,19 @@ class Config(object):
_mailer = '/usr/sbin/sendmail'

def __init__(self, fh):
config = configparser.SafeConfigParser()
config = configparser.ConfigParser()
if not hasattr(fh, 'read'):
self._config_dir = os.path.dirname(os.path.abspath(fh))
with open(fh) as fp:
config.readfp(fp, fh)
config.read_file(fp, fh)
else:
self._config_dir = None
config.readfp(fh)
config.read_file(fh)
self.populate(config)

def populate(self, config):
"""Populate data structures using the passed `config`, which is a
:class:`configparser.SafeConfigParser` object.
:class:`configparser.ConfigParser` object.
This can be overridden in subclasses to read additional
service-specific information from the configuration file."""
self._populate_database(config)
Expand Down Expand Up @@ -305,9 +292,9 @@ def _populate_limits(self, config):

def _read_db_auth(self, end='back'):
filename = self.database[end + 'end_config']
config = configparser.SafeConfigParser()
config = configparser.ConfigParser()
with open(filename) as fh:
config.readfp(fh, filename)
config.read_file(fh, filename)
for key in ('user', 'passwd'):
self.database[key] = config.get(end + 'end_db', key)

Expand Down Expand Up @@ -1883,13 +1870,13 @@ def __init__(self, url):

def get_filename(self):
"""Return the name of the file corresponding to this result."""
return os.path.basename(urlparse.urlparse(self.url)[2])
return os.path.basename(urllib.parse.urlparse(self.url)[2])

def download(self, fh=None):
"""Download the result file. If `fh` is given, it should be a Python
file-like object, to which the file is written. Otherwise, the file
is written into the job directory with the same name."""
fin = urllib2.urlopen(self.url)
fin = urllib.request.urlopen(self.url)
if fh is None:
outfh = open(self.get_filename(), 'w')
else:
Expand Down
1 change: 0 additions & 1 deletion python/saliweb/backend/delete_all_jobs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import saliweb.backend
import sys

Expand Down
1 change: 0 additions & 1 deletion python/saliweb/backend/deljob.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import saliweb.backend
from optparse import OptionParser
import sys
Expand Down
1 change: 0 additions & 1 deletion python/saliweb/backend/failjob.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import saliweb.backend
from optparse import OptionParser
import sys
Expand Down
1 change: 0 additions & 1 deletion python/saliweb/backend/list_jobs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import saliweb.backend
from optparse import OptionParser
import sys
Expand Down
1 change: 0 additions & 1 deletion python/saliweb/backend/resubmit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
from optparse import OptionParser
import sys

Expand Down
1 change: 0 additions & 1 deletion python/saliweb/backend/service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
from optparse import OptionParser
import saliweb.backend
import sys
Expand Down
1 change: 0 additions & 1 deletion python/saliweb/build/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""

from __future__ import print_function
try:
import MySQLdb
except ImportError as detail:
Expand Down
11 changes: 4 additions & 7 deletions python/saliweb/frontend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import flask
from flask import url_for, Markup
import datetime
try:
import configparser
except ImportError:
import ConfigParser as configparser
import configparser
import os
import sys
import re
Expand Down Expand Up @@ -173,10 +170,10 @@ def _read_config(app, fname):
# Set defaults for all web services
app.config.from_object(saliweb.frontend.config)

config = configparser.SafeConfigParser()
config = configparser.ConfigParser()

with open(fname) as fh:
config.readfp(fh, fname)
config.read_file(fh, fname)

for section in config.sections():
prefix = '' if section == 'general' else section.upper() + '_'
Expand All @@ -187,7 +184,7 @@ def _read_config(app, fname):
frontend_db = config.get('database', 'frontend_config')
fname = os.path.join(config_dir, frontend_db)
with open(fname) as fh:
config.readfp(fh, fname)
config.read_file(fh, fname)
for name in ('user', 'passwd'):
value = config.get('frontend_db', name)
app.config["DATABASE_" + name.upper()] = value
Expand Down
1 change: 0 additions & 1 deletion python/saliweb/make_web_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
from optparse import OptionParser
import string
import random
Expand Down
1 change: 0 additions & 1 deletion python/saliweb/test/run-tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import unittest
import sys
import os
Expand Down
2 changes: 0 additions & 2 deletions python/saliweb/web_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
command line interface to the services.
"""

from __future__ import print_function

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
Expand Down

0 comments on commit 2ccf0d4

Please sign in to comment.