Skip to content

Commit

Permalink
Add back getZopeVersion() (#412)
Browse files Browse the repository at this point in the history
* fix issue #411

* rename `dict` to `version_dict`

* `getZopeVersion`: Tests and `CHANGES.txt` entry

* Update CHANGES.rst (reference syntax)

Co-Authored-By: d-maurer <d-maurer@users.noreply.github.com>

* `self._assert(isinstance(...))` --> `self.assertIsInstance`
  • Loading branch information
d-maurer authored Jan 24, 2019
1 parent 20d2968 commit fc34748
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ https://github.com/zopefoundation/Zope/blob/4.0a6/CHANGES.rst
Fixes
+++++

- Recreate ``App.version_txt.getZopeVersion``
(`#411 <https://github.com/zopefoundation/Zope/issues/411>`_)

- Restore the `View` ZMI tab on folders and their subclasses
(`#449 <https://github.com/zopefoundation/Zope/issues/449>`_)

Expand Down
32 changes: 32 additions & 0 deletions src/App/tests/test_getZopeVersion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
##############################################################################
#
# Copyright (c) 2004 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Tests for the recreated `getZopeVersion`."""

import unittest

from pkg_resources import get_distribution
from App.version_txt import getZopeVersion

class Test(unittest.TestCase):
def test_major(self):
self.assertEqual(
getZopeVersion().major,
int(get_distribution("Zope").version.split(".")[0])
)

def test_types(self):
zv = getZopeVersion()
for i in (0, 1, 2, 4):
self.assertIsInstance(zv[i], int, str(i))
self.assertIsInstance(zv[3], str, '3')
34 changes: 33 additions & 1 deletion src/App/version_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,54 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
import collections
import re
import sys

import pkg_resources

_version_string = None
_zope_version = None

ZopeVersion = collections.namedtuple(
"ZopeVersion",
["major", "minor", "micro", "status", "release"]
)


def _prep_version_data():
global _version_string
global _version_string, _zope_version
if _version_string is None:
v = sys.version_info
pyver = "python %d.%d.%d, %s" % (v[0], v[1], v[2], sys.platform)
dist = pkg_resources.get_distribution('Zope')
_version_string = "%s, %s" % (dist.version, pyver)

expr = re.compile(
r'(?P<major>[0-9]+)\.(?P<minor>[0-9]+)(\.(?P<micro>[0-9]+))?'
'(?P<status>[A-Za-z]+)?(?P<release>[0-9]+)?')
version_dict = expr.match(dist.version).groupdict()
_zope_version = ZopeVersion(
int(version_dict.get('major') or -1),
int(version_dict.get('minor') or -1),
int(version_dict.get('micro') or -1),
version_dict.get('status') or '',
int(version_dict.get('release') or -1),
)




def version_txt():
_prep_version_data()
return '(%s)' % _version_string

def getZopeVersion():
"""return information about the Zope version as a named tuple.
Format of zope_version tuple:
(major <int>, minor <int>, micro <int>, status <string>, release <int>)
If unreleased, integers may be -1.
"""
_prep_version_data()
return _zope_version

0 comments on commit fc34748

Please sign in to comment.