Skip to content

Commit

Permalink
Merge pull request #2 from zopefoundation/tomgross-python3
Browse files Browse the repository at this point in the history
Python 3 compatibility
  • Loading branch information
tseaver committed Feb 1, 2016
2 parents 36ff0d0 + 7ddbe83 commit 6ac8506
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 121 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
bin
build
/develop-eggs/
/eggs
dist
lib
parts
/src/zope.testrunner
.eggs
.tox
.coverage
.installed.cfg
.mr.developer.cfg
coverage.xml
nosetests.xml
htmlcov

*.dll
*.pyc
Expand Down
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ language: python
sudo: false
python:
- 2.7
- 3.4
- 3.5
install:
- python bootstrap.py
- python bootstrap-buildout.py
- bin/buildout
script:
- bin/test -v1
- bin/nosetests --with-coverage --cover-package=zLOG --cover-min-percentage=100%
notifications:
email: false
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ Unreleased

- Add coverage testing.

- Add Python 3 compatibility.

- Declare currently-supported Python versions (2.6, 2.7), and test them
via ``tox``.

- Normalize package structure (``README.rst``, ``CHANGES.rst``). Synthesize
package description from README.rst and CHANGES.rst.

- Use nose for testing instead of zope.testrunner and test
for 100% test coverage

2.12.0 (2012-08-30)
-------------------
Expand Down
51 changes: 36 additions & 15 deletions bootstrap.py → bootstrap-buildout.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

from optparse import OptionParser

tmpeggs = tempfile.mkdtemp()
__version__ = '2015-07-01'
# See zc.buildout's changelog if this version is up to date.

tmpeggs = tempfile.mkdtemp(prefix='bootstrap-')

usage = '''\
[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
Expand All @@ -40,8 +43,9 @@
'''

parser = OptionParser(usage=usage)
parser.add_option("-v", "--version", help="use a specific zc.buildout version")

parser.add_option("--version",
action="store_true", default=False,
help=("Return bootstrap.py version."))
parser.add_option("-t", "--accept-buildout-test-releases",
dest='accept_buildout_test_releases',
action="store_true", default=False,
Expand All @@ -59,25 +63,33 @@
parser.add_option("--allow-site-packages",
action="store_true", default=False,
help=("Let bootstrap.py use existing site packages"))
parser.add_option("--buildout-version",
help="Use a specific zc.buildout version")
parser.add_option("--setuptools-version",
help="use a specific setuptools version")

help="Use a specific setuptools version")
parser.add_option("--setuptools-to-dir",
help=("Allow for re-use of existing directory of "
"setuptools versions"))

options, args = parser.parse_args()
if options.version:
print("bootstrap.py version %s" % __version__)
sys.exit(0)


######################################################################
# load/install setuptools

try:
if options.allow_site_packages:
import setuptools
import pkg_resources
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen

ez = {}
exec(urlopen('https://bootstrap.pypa.io/ez_setup.py').read(), ez)
if os.path.exists('ez_setup.py'):
exec(open('ez_setup.py').read(), ez)
else:
exec(urlopen('https://bootstrap.pypa.io/ez_setup.py').read(), ez)

if not options.allow_site_packages:
# ez_setup imports site, which adds site packages
Expand All @@ -88,12 +100,19 @@
# We can't remove these reliably
if hasattr(site, 'getsitepackages'):
for sitepackage_path in site.getsitepackages():
sys.path[:] = [x for x in sys.path if sitepackage_path not in x]
# Strip all site-packages directories from sys.path that
# are not sys.prefix; this is because on Windows
# sys.prefix is a site-package directory.
if sitepackage_path != sys.prefix:
sys.path[:] = [x for x in sys.path
if sitepackage_path not in x]

setup_args = dict(to_dir=tmpeggs, download_delay=0)

if options.setuptools_version is not None:
setup_args['version'] = options.setuptools_version
if options.setuptools_to_dir is not None:
setup_args['to_dir'] = options.setuptools_to_dir

ez['use_setuptools'](**setup_args)
import setuptools
Expand All @@ -110,7 +129,12 @@

ws = pkg_resources.working_set

setuptools_path = ws.find(
pkg_resources.Requirement.parse('setuptools')).location

# Fix sys.path here as easy_install.pth added before PYTHONPATH
cmd = [sys.executable, '-c',
'import sys; sys.path[0:0] = [%r]; ' % setuptools_path +
'from setuptools.command.easy_install import main; main()',
'-mZqNxd', tmpeggs]

Expand All @@ -123,11 +147,8 @@
if find_links:
cmd.extend(['-f', find_links])

setuptools_path = ws.find(
pkg_resources.Requirement.parse('setuptools')).location

requirement = 'zc.buildout'
version = options.version
version = options.buildout_version
if version is None and not options.accept_buildout_test_releases:
# Figure out the most recent final version of zc.buildout.
import setuptools.package_index
Expand Down Expand Up @@ -167,7 +188,7 @@ def _final_version(parsed_version):
cmd.append(requirement)

import subprocess
if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=setuptools_path)) != 0:
if subprocess.call(cmd) != 0:
raise Exception(
"Failed to execute command:\n%s" % repr(cmd)[1:-1])

Expand Down
8 changes: 5 additions & 3 deletions buildout.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[buildout]
develop = .
parts = test
find-links = http://download.zope.org/distribution/

[test]
recipe = zc.recipe.testrunner
eggs = zLOG
recipe = zc.recipe.egg
eggs =
Nose
coverage
zLOG
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
"License :: OSI Approved :: Zope Public License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: Implementation :: CPython",
"Framework :: Zope2",
"Topic :: Software Development :: Libraries :: Python Modules",
Expand Down
28 changes: 13 additions & 15 deletions src/zLOG/EventLogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
This uses Vinay Sajip's PEP 282 logging module.
"""

__version__='$Revision$'[11:-2]

import logging
import time

Expand All @@ -32,6 +30,18 @@
logging.addLevelName("BLATHER", CUSTOM_BLATHER)
logging.addLevelName("TRACE", CUSTOM_TRACE)

try: # pragma: no cover
# Python 3
Exception.with_traceback

def fmt_raise(error):
raise error[0](error[1]).with_traceback(error[2])

except AttributeError: # pragma: no cover
# Python 2
def fmt_raise(error):
return error[0], error[1], error[2]


def log_write(subsystem, severity, summary, detail, error):
level = (zlog_to_pep282_severity_cache_get(severity) or
Expand All @@ -42,19 +52,7 @@ def log_write(subsystem, severity, summary, detail, error):
msg = "%s\n%s" % (msg, detail)

logger = logging.getLogger(subsystem)


# Since the logging module of Python does not allow to pass a
# traceback triple, we need to fake the exception. (See also
# Collector #1234).

if isinstance(error, tuple):
try:
raise error[0], error[1], error[2]
except:
pass

logger.log(level, msg, exc_info=(error is not None))
logger.log(level, msg, exc_info=error)


def severity_string(severity, mapping={
Expand Down
5 changes: 3 additions & 2 deletions src/zLOG/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
"""

from EventLogger import log_write, log_time, severity_string
from zLOG.EventLogger import log_write, log_time, severity_string
from zLOG.EventLogger import fmt_raise
from traceback import format_exception

# Standard severities
Expand Down Expand Up @@ -134,7 +135,7 @@ def LOG(subsystem, severity, summary, detail='', error=None, reraise=None):
"""
log_write(subsystem, severity, summary, detail, error)
if reraise and error:
raise error[0], error[1], error[2]
raise fmt_raise(error)

_subsystems = []
def register_subsystem(subsystem):
Expand Down
7 changes: 0 additions & 7 deletions src/zLOG/tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,3 @@ def test_log_record(self):
# in the text that gets logged:
record.msg.index("summary")
record.msg.index("detail")


def test_suite():
return unittest.makeSuite(LoggingIntegrationTestCase)

if __name__ == "__main__":
unittest.main(defaultTest="test_suite")

0 comments on commit 6ac8506

Please sign in to comment.