From 8c04454ecd99a92dc5fcc1d3a66ed4cccc28ee5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Wed, 18 Feb 2015 16:44:26 +0100 Subject: [PATCH] Updated setup.py and openslides module init, esp. version string. Removed git commit id grabbing during development. --- openslides/__init__.py | 48 +++--------------------------------- openslides/__main__.py | 4 +-- openslides/core/views.py | 12 +++------ setup.py | 31 +++++++++++------------ tests/old/core/test_views.py | 4 +-- tests/old/test_init.py | 44 --------------------------------- 6 files changed, 25 insertions(+), 118 deletions(-) delete mode 100644 tests/old/test_init.py diff --git a/openslides/__init__.py b/openslides/__init__.py index 1e30421a1..dd4a6b58e 100644 --- a/openslides/__init__.py +++ b/openslides/__init__.py @@ -1,45 +1,3 @@ -VERSION = (2, 0, 0, 'alpha', 1) # During development it is the next release -RELEASE = False - - -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' +__author__ = 'OpenSlides Team ' +__description__ = 'Presentation and assembly system' +__version__ = '2.0a1-dev' diff --git a/openslides/__main__.py b/openslides/__main__.py index 4a485ea50..6df560eed 100644 --- a/openslides/__main__.py +++ b/openslides/__main__.py @@ -5,7 +5,7 @@ import sys 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 ( get_default_settings_path, setup_django_settings_module, @@ -61,7 +61,7 @@ def get_parser(): parser.add_argument( '--version', action='version', - version=get_version(), + version=openslides_version, help='Show version number and exit.') # Init subparsers diff --git a/openslides/core/views.py b/openslides/core/views.py index 6ccac1472..53e1b589e 100644 --- a/openslides/core/views.py +++ b/openslides/core/views.py @@ -11,8 +11,7 @@ from django.utils.translation import ugettext as _ from haystack.views import SearchView as _SearchView from django.http import HttpResponse -from openslides import get_version as get_openslides_version -from openslides import get_git_commit_id, RELEASE +from openslides import __version__ as openslides_version from openslides.config.api import config from openslides.utils import views as utils_views 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. """ 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', - 'description': description, - 'version': get_openslides_version()}] + 'description': '', + 'version': openslides_version}] # Versions of plugins. for plugin in settings.INSTALLED_PLUGINS: context['modules'].append({'verbose_name': get_plugin_verbose_name(plugin), diff --git a/setup.py b/setup.py index cf2b84e8a..1bc0bd312 100644 --- a/setup.py +++ b/setup.py @@ -1,39 +1,38 @@ #!/usr/bin/env python -import re -import sys - -from setuptools import setup, find_packages - -from openslides import get_version +from setuptools import find_packages, setup +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: long_description = readme.read() - with open('requirements_production.txt') as requirements_production: install_requires = requirements_production.readlines() - setup( name='openslides', - version=get_version(), - author='OpenSlides-Team', + author=openslides_author, author_email='support@openslides.org', - url='http://openslides.org', - description='Presentation and assembly system', + description=openslides_description, + license='MIT', long_description=long_description, + url='http://openslides.org', + version=openslides_version, + 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', 'Framework :: Django', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', - 'Programming Language :: Python :: 3', - ], - license='MIT', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', ], packages=find_packages(exclude=['tests', 'tests.*']), include_package_data=True, install_requires=install_requires, diff --git a/tests/old/core/test_views.py b/tests/old/core/test_views.py index cc1253772..95c7180bb 100644 --- a/tests/old/core/test_views.py +++ b/tests/old/core/test_views.py @@ -2,7 +2,7 @@ from unittest.mock import MagicMock, patch 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.config.api import config from openslides.core import views @@ -73,7 +73,7 @@ class VersionViewTest(TestCase): def test_get(self): 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') def test_with_missing_plugin(self, mock_settings): diff --git a/tests/old/test_init.py b/tests/old/test_init.py deleted file mode 100644 index dd669323d..000000000 --- a/tests/old/test_init.py +++ /dev/null @@ -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')