Python 3 Fixes: Replace missing builtins

There are a few different missing builtins in python3 that we're using.
This shows up when running tox pep8 under python3 which is needed for
the streamer work.

Change-Id: I1b2ef0b7bdcd1a85895576682455745fe06e880b
This commit is contained in:
Monty Taylor 2016-06-02 07:39:49 +03:00 committed by Morgan Fainberg
parent e77bf87fd4
commit 74fa3865ac
5 changed files with 15 additions and 5 deletions

View File

@ -27,6 +27,7 @@ import random
import re
import select
import shutil
from six.moves import reload_module
import socket
import string
import subprocess
@ -916,8 +917,8 @@ class ZuulTestCase(BaseTestCase):
os.environ['STATSD_PORT'] = str(self.statsd.port)
self.statsd.start()
# the statsd client object is configured in the statsd module import
reload(statsd)
reload(zuul.scheduler)
reload_module(statsd)
reload_module(zuul.scheduler)
self.gearman_server = FakeGearmanServer()

View File

@ -18,6 +18,8 @@ commands =
python setup.py testr --slowest --testr-args='{posargs}'
[testenv:pep8]
# streamer is python3 only, so we need to run flake8 in python3
basepython = python3
commands = flake8 {posargs}
[testenv:cover]

View File

@ -17,6 +17,7 @@ import inspect
import json
import logging
import os
import six
import time
import threading
from uuid import uuid4
@ -231,7 +232,7 @@ class Gearman(object):
s_config = {}
s_config.update((k, v.format(item=item, job=job,
change=item.change))
if isinstance(v, basestring)
if isinstance(v, six.string_types)
else (k, v)
for k, v in s.items())

View File

@ -110,7 +110,11 @@ class Pipeline(object):
return job_tree
def getProjects(self):
return sorted(self.job_trees.keys(), lambda a, b: cmp(a.name, b.name))
# cmp is not in python3, applied idiom from
# http://python-future.org/compatible_idioms.html#cmp
return sorted(
self.job_trees.keys(),
key=lambda p: p.name)
def addQueue(self, queue):
self.queues.append(queue)

View File

@ -411,7 +411,9 @@ class Scheduler(threading.Thread):
base = os.path.dirname(os.path.realpath(config_path))
fn = os.path.join(base, fn)
fn = os.path.expanduser(fn)
execfile(fn, config_env)
with open(fn) as _f:
code = compile(_f.read(), fn, 'exec')
six.exec_(code, config_env)
for conf_pipeline in data.get('pipelines', []):
pipeline = Pipeline(conf_pipeline['name'])