Skip to content

Commit

Permalink
Remove support for python 2.7
Browse files Browse the repository at this point in the history
It's long since not supported, so it's time. Remove the python2.7 bits, and add
python 3.10 to the azure config.

Also cleaned up some pylint-related bits that were just in place for 2.7 support.
  • Loading branch information
wwade committed Oct 10, 2021
1 parent 6f8cd80 commit 3e10378
Show file tree
Hide file tree
Showing 9 changed files with 437 additions and 604 deletions.
537 changes: 0 additions & 537 deletions Pipfile-2.7.lock

This file was deleted.

391 changes: 391 additions & 0 deletions Pipfile-3.10.lock

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions ci/azure/azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ jobs:
vmImage: ubuntu-20.04
strategy:
matrix:
Python27:
python.version: '2.7'
Python37:
python.version: '3.7'
Python38:
python.version: '3.8'
Python39:
python.version: '3.9'
Python310:
python.version: '3.10'
steps:
- template: steps.yaml

Expand All @@ -25,9 +25,7 @@ jobs:
vmImage: 'macOS-10.15'
strategy:
matrix:
Python37:
python.version: '3.7'
Python39:
python.version: '3.9'
Python10:
python.version: '3.10'
steps:
- template: steps.yaml
18 changes: 2 additions & 16 deletions jobrunner/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
pidDebug,
safeSleep,
sprint,
stackDetails,
utcNow,
)

Expand Down Expand Up @@ -246,27 +245,14 @@ def __init__(self, config, plugins):
def setDbCaching(self, enabled):
pass

def debugPrint(self, msg):
if "lock" not in self.config.debugLevel:
return
fnDetails = stackDetails(depth=2)
if fnDetails.funcname == 'lock' or fnDetails.funcname == 'unlock':
fnDetails = stackDetails(depth=3)
if fnDetails.funcname == '_locked':
fnDetails = stackDetails(depth=4)
pidDebug(msg, "from",
fnDetails.filename, fnDetails.funcname, fnDetails.lineno)

def isLocked(self):
raise NotImplementedError

def lock(self):
LOGLOCK.debug("lock DB")
self.debugPrint("< LOCK DB")

def unlock(self):
LOGLOCK.debug("unlock DB")
self.debugPrint("< UNLOCK DB")

def prune(self, exceptNum=None):
allJobs = []
Expand Down Expand Up @@ -486,8 +472,8 @@ def getJobMatch(self, key, thisWs, skipReminders=False):
self.inactive, None, filterWs=thisWs)
try:
return jobList[-1]
except IndexError:
raise NoMatchingJobError("Job database is empty")
except IndexError as err:
raise NoMatchingJobError("Job database is empty") from err
elif key in self.active.db:
# Exact match, try active first
return self.active[key]
Expand Down
2 changes: 1 addition & 1 deletion jobrunner/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def __eq__(self, other):
def __lt__(self, other):
return self.__cmp__(other) < 0

def __cmp__(self, other): # pylint: disable=cmp-method
def __cmp__(self, other):
if not isinstance(other, type(self)):
return -1
if self._stop is None:
Expand Down
68 changes: 35 additions & 33 deletions jobrunner/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import errno
import hashlib
import os
from os.path import expanduser
from subprocess import PIPE, CalledProcessError, Popen, check_call, check_output
import sys
import tempfile
Expand Down Expand Up @@ -210,6 +211,7 @@ def impl_main(args=None):

if options.mail:
# Collect output files as attachments from dep jobs
# pylint: disable=consider-using-with
tmp = tempfile.NamedTemporaryFile(prefix='jobInfo-')
options.input = tmp.name
mailSize = 0
Expand Down Expand Up @@ -267,30 +269,30 @@ def waitForDep(depWait, options, jobs):

def monitorForkedJob(job, jobs):
monitorCmd = ["tail", "-n+0", "-f", job.logfile]
monitor = Popen(monitorCmd, stdout=sys.stdout, stderr=sys.stdout)
try:
active = True
rc = 0
while active:
LOG.debug("monitoring, sleep 0.5")
with lockedSection(jobs):
active = job.key in jobs.active.db
rc = None
if not active:
rc = jobs.inactive[job.key].rc
time.sleep(0.5)
LOG.debug('active %s, rc %r', active, rc)
return rc
except KeyboardInterrupt:
LOG.debug('KeyboardInterrupt')
sprint("\n(Stop monitoring): {}".format(job))
except BaseException:
LOG.info('exception', exc_info=1)
raise
finally:
LOG.debug('terminate monitor subprocess')
monitor.terminate()
monitor.kill()
with Popen(monitorCmd, stdout=sys.stdout, stderr=sys.stdout) as monitor:
try:
active = True
rc = 0
while active:
LOG.debug("monitoring, sleep 0.5")
with lockedSection(jobs):
active = job.key in jobs.active.db
rc = None
if not active:
rc = jobs.inactive[job.key].rc
time.sleep(0.5)
LOG.debug('active %s, rc %r', active, rc)
return rc
except KeyboardInterrupt:
LOG.debug('KeyboardInterrupt')
sprint("\n(Stop monitoring): {}".format(job))
except BaseException:
LOG.info('exception', exc_info=1)
raise
finally:
LOG.debug('terminate monitor subprocess')
monitor.terminate()
monitor.kill()
monitor.wait()
return 0

Expand Down Expand Up @@ -366,11 +368,11 @@ def addNonExecOptions(op):
op.add_argument("--dot", action='store_true',
help='Show dependency graph for active jobs')
op.add_argument("--png", action='store_true',
help='Create dependency graph svg for active jobs in '
'~%s/output/job.svg' % os.getenv('USER'))
help='Create dependency graph svg for active jobs in ' +
expanduser('~/output/job.svg'))
op.add_argument("--svg", action='store_true',
help='Create dependency graph png for active jobs in '
'~%s/output/job.svg' % os.getenv('USER'))
help='Create dependency graph png for active jobs in ' +
expanduser('~/output/job.svg'))
op.add_argument("-L", "--list-inactive", action="store_true",
help="List inactive jobs")
op.add_argument("-W", "--watch", action="store_true",
Expand Down Expand Up @@ -456,11 +458,11 @@ def handleNonExecOptions(options, jobs):
if options.dot:
sprint(dot)
else:
fName = '~%s/output/job.svg' % os.getenv('USER')
fName = expanduser('~/output/job.svg')
ofile = os.path.expanduser(fName)
cmd = ['dot', '-Tsvg', '-o', ofile]
proc = Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE)
stdout, stderr = proc.communicate(input=dot.encode('utf-8'))
with Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE) as proc:
stdout, stderr = proc.communicate(input=dot.encode('utf-8'))
if stdout.strip() or stderr.strip():
raise ExitCode(stdout + stderr)
sprint('Saved output to', fName)
Expand Down Expand Up @@ -576,10 +578,10 @@ def handleNonExecWriteOptions(options, jobs):
elif options.watch:
try:
jobs.watchActivity()
except KeyboardInterrupt:
except KeyboardInterrupt as err:
sprint("")
sprint("Exit on user interrupt")
raise ExitCode(1)
raise ExitCode(1) from err
return True
else:
return False
Expand Down
10 changes: 2 additions & 8 deletions jobrunner/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import datetime
import errno
import fcntl
import inspect
import logging
import os
import signal
Expand Down Expand Up @@ -175,16 +174,11 @@ def pidDebug(*args):
FnDetails = collections.namedtuple('FnDetails', 'filename, lineno, funcname')


def stackDetails(depth=0):
caller = inspect.stack()[depth + 1]
return FnDetails(caller[1], caller[2], caller[3])


def workspaceIdentity():
return MOD_STATE.plugins.workspaceIdentity()


def getAllowed():
def _getAllowed():
allowed = (list(range(ord('a'), ord('z') + 1)) +
list(range(ord('A'), ord('Z') + 1)) +
list(range(ord('0'), ord('9') + 1)) +
Expand All @@ -194,7 +188,7 @@ def getAllowed():


def keyEscape(inp):
allowed = getAllowed()
allowed = _getAllowed()
ret = ""
for char in inp:
if char in allowed:
Expand Down
3 changes: 1 addition & 2 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ disable=invalid-name,

useless-object-inheritance,
super-with-arguments,
consider-using-with, # because python2 pylint version
raise-missing-from, # because python2 pylint version
redundant-u-string-prefix,
consider-using-f-string,


# Enable the message, report, category or checker with the given id(s). You can
Expand Down
2 changes: 1 addition & 1 deletion test-docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
VerInfo = namedtuple("VerInfo", ("version", "lock", "default"))

VERSIONS = (
VerInfo("2.7", "Pipfile-2.7.lock", False),
VerInfo("3.8", "Pipfile-3.8.lock", False),
VerInfo("3.9", "Pipfile-3.9.lock", False),
VerInfo("3.10", "Pipfile-3.10.lock", False),
VerInfo("3.7", "Pipfile.lock", True),
)

Expand Down

0 comments on commit 3e10378

Please sign in to comment.