Merge pull request #1488 from normanjaeckel/OpenSlidesVersion

Updated setup.py and openslides module init, esp. version string.
This commit is contained in:
Norman Jäckel 2015-02-25 13:37:13 +01:00
commit 1fe84195e1
6 changed files with 25 additions and 118 deletions

View File

@ -1,45 +1,3 @@
VERSION = (2, 0, 0, 'alpha', 1) # During development it is the next release __author__ = 'OpenSlides Team <support@openslides.org>'
RELEASE = False __description__ = 'Presentation and assembly system'
__version__ = '2.0a1-dev'
def get_version(version=None, release=None):
"""
Derives a PEP386-compliant version number from VERSION. Adds '-dev',
if it is not a release commit.
"""
if version is None:
version = VERSION
if release is None:
release = RELEASE
assert len(version) == 5
assert version[3] in ('alpha', 'beta', 'rc', 'final')
# Now build the two parts of the version number:
# main = X.Y[.Z]
# sub = {a|b|c}N for alpha, beta and rc releases
# Add '-dev', if it is not a release commit
main_parts = 2 if version[2] == 0 else 3
main = '.'.join(str(x) for x in version[:main_parts])
if version[3] != 'final':
mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'c'}
sub = mapping[version[3]] + str(version[4])
else:
sub = ''
if not release:
sub += '-dev'
return main + sub
def get_git_commit_id():
"""
Catches the commit id of the git head.
"""
try:
git_head = open('.git/HEAD', 'r').read().rstrip()
if git_head[:5] == 'ref: ':
# The file is a reference. We have to follow it to get the commit id
git_commit_id = open('.git/%s' % git_head[5:], 'r').read().rstrip()
else:
git_commit_id = git_head
return git_commit_id
except IOError:
return 'unknown'

View File

@ -5,7 +5,7 @@ import sys
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line
from openslides import get_version from openslides import __version__ as openslides_version
from openslides.utils.main import ( from openslides.utils.main import (
get_default_settings_path, get_default_settings_path,
setup_django_settings_module, setup_django_settings_module,
@ -61,7 +61,7 @@ def get_parser():
parser.add_argument( parser.add_argument(
'--version', '--version',
action='version', action='version',
version=get_version(), version=openslides_version,
help='Show version number and exit.') help='Show version number and exit.')
# Init subparsers # Init subparsers

View File

@ -11,8 +11,7 @@ from django.utils.translation import ugettext as _
from haystack.views import SearchView as _SearchView from haystack.views import SearchView as _SearchView
from django.http import HttpResponse from django.http import HttpResponse
from openslides import get_version as get_openslides_version from openslides import __version__ as openslides_version
from openslides import get_git_commit_id, RELEASE
from openslides.config.api import config from openslides.config.api import config
from openslides.utils import views as utils_views from openslides.utils import views as utils_views
from openslides.utils.plugins import get_plugin_description, get_plugin_verbose_name, get_plugin_version from openslides.utils.plugins import get_plugin_description, get_plugin_verbose_name, get_plugin_version
@ -115,14 +114,9 @@ class VersionView(utils_views.TemplateView):
Adds version strings to the context. Adds version strings to the context.
""" """
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
# OpenSlides version. During development the git commit id is added.
if RELEASE:
description = ''
else:
description = 'Commit %s' % get_git_commit_id()
context['modules'] = [{'verbose_name': 'OpenSlides', context['modules'] = [{'verbose_name': 'OpenSlides',
'description': description, 'description': '',
'version': get_openslides_version()}] 'version': openslides_version}]
# Versions of plugins. # Versions of plugins.
for plugin in settings.INSTALLED_PLUGINS: for plugin in settings.INSTALLED_PLUGINS:
context['modules'].append({'verbose_name': get_plugin_verbose_name(plugin), context['modules'].append({'verbose_name': get_plugin_verbose_name(plugin),

View File

@ -1,39 +1,38 @@
#!/usr/bin/env python #!/usr/bin/env python
import re from setuptools import find_packages, setup
import sys
from setuptools import setup, find_packages
from openslides import get_version
from openslides import __author__ as openslides_author
from openslides import __description__ as openslides_description
from openslides import __version__ as openslides_version
with open('README.rst') as readme: with open('README.rst') as readme:
long_description = readme.read() long_description = readme.read()
with open('requirements_production.txt') as requirements_production: with open('requirements_production.txt') as requirements_production:
install_requires = requirements_production.readlines() install_requires = requirements_production.readlines()
setup( setup(
name='openslides', name='openslides',
version=get_version(), author=openslides_author,
author='OpenSlides-Team',
author_email='support@openslides.org', author_email='support@openslides.org',
url='http://openslides.org', description=openslides_description,
description='Presentation and assembly system', license='MIT',
long_description=long_description, long_description=long_description,
url='http://openslides.org',
version=openslides_version,
classifiers=[ classifiers=[
# http://pypi.python.org/pypi?%3Aaction=list_classifiers # http://pypi.python.org/pypi?%3Aaction=list_classifiers
'Development Status :: 5 - Production/Stable', 'Development Status :: 3 - Alpha',
# 'Development Status :: 4 - Beta',
# 'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment', 'Environment :: Web Environment',
'Framework :: Django', 'Framework :: Django',
'License :: OSI Approved :: MIT License', 'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent', 'Operating System :: OS Independent',
'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3',
], 'Programming Language :: Python :: 3.4', ],
license='MIT',
packages=find_packages(exclude=['tests', 'tests.*']), packages=find_packages(exclude=['tests', 'tests.*']),
include_package_data=True, include_package_data=True,
install_requires=install_requires, install_requires=install_requires,

View File

@ -2,7 +2,7 @@ from unittest.mock import MagicMock, patch
from django.test.client import Client, RequestFactory from django.test.client import Client, RequestFactory
from openslides import get_version from openslides import __version__ as openslides_version
from openslides.agenda.models import Item from openslides.agenda.models import Item
from openslides.config.api import config from openslides.config.api import config
from openslides.core import views from openslides.core import views
@ -73,7 +73,7 @@ class VersionViewTest(TestCase):
def test_get(self): def test_get(self):
response = self.client.get('/version/') response = self.client.get('/version/')
self.assertContains(response, get_version(), status_code=200) self.assertContains(response, openslides_version, status_code=200)
@patch('openslides.core.views.settings') @patch('openslides.core.views.settings')
def test_with_missing_plugin(self, mock_settings): def test_with_missing_plugin(self, mock_settings):

View File

@ -1,44 +0,0 @@
from io import StringIO
from unittest.mock import MagicMock, patch
from openslides import get_git_commit_id, get_version
from openslides.utils.test import TestCase
class InitTest(TestCase):
def test_get_version(self):
"""
Tests the method during development process and for releases.
"""
self.assertEqual(get_version(version=(1, 3, 0, 'beta', 2), release=False), '1.3b2-dev')
self.assertEqual(get_version(version=(1, 0, 0, 'final', 0), release=False), '1.0-dev')
self.assertEqual(get_version(version=(2, 5, 3, 'alpha', 0), release=False), '2.5.3a0-dev')
self.assertEqual(get_version(version=(1, 3, 0, 'beta', 2), release=True), '1.3b2')
self.assertEqual(get_version(version=(1, 0, 0, 'final', 0), release=True), '1.0')
self.assertEqual(get_version(version=(2, 5, 3, 'alpha', 0), release=True), '2.5.3a0')
self.assertEqual(get_version(version=(2, 5, 3, 'final', 0), release=True), '2.5.3')
@patch('builtins.open', MagicMock(side_effect=IOError))
def test_get_commit_id_unknown(self):
"""
Tests unknown git commit id.
"""
self.assertEqual(get_git_commit_id(), 'unknown')
@patch('builtins.open')
def test_get_commit_id_without_ref(self, mock):
"""
Tests reading the content of the git_commit_id file.
"""
mock.return_value = StringIO('test_id_ahyuGo7yefai7Nai')
self.assertEqual(get_git_commit_id(), 'test_id_ahyuGo7yefai7Nai')
@patch('builtins.open')
def test_get_git_commit_id_general(self, mock):
"""
Tests reading the content of a git reference (e.g. tags or branches).
"""
mock.side_effect = (StringIO('ref: asdfgqwertfdfhiwer'), StringIO('TestOpenSlides-3.1415'))
git_commit_id = get_git_commit_id()
if not git_commit_id == 'unknown':
self.assertEqual(git_commit_id, 'TestOpenSlides-3.1415')