From 4e0b5d7040a52274f8a4b0d866c7f22f4cd0951f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 19 Mar 2015 21:24:15 +0100 Subject: [PATCH] Remove execfile from setup.py issue4654 review6171003 --- bin/tryton | 6 +++--- setup.py | 30 +++++++++++++++++------------- tryton/__init__.py | 4 +--- tryton/common/common.py | 4 ++-- tryton/config.py | 10 +++++----- tryton/gui/window/about.py | 6 +++--- tryton/gui/window/dblogin.py | 4 ++-- tryton/translate.py | 5 ++--- tryton/version.py | 6 ------ 9 files changed, 35 insertions(+), 40 deletions(-) delete mode 100644 tryton/version.py diff --git a/bin/tryton b/bin/tryton index 3b75928b66..58ecd1ee63 100755 --- a/bin/tryton +++ b/bin/tryton @@ -42,7 +42,7 @@ os.environ['UBUNTU_MENUPROXY'] = '0' # overlay-scrollbar breaks treeview height os.environ['LIBOVERLAY_SCROLLBAR'] = '0' -import tryton +from tryton import client if '--profile' in sys.argv: import profile import pstats @@ -51,7 +51,7 @@ if '--profile' in sys.argv: sys.argv.remove('--profile') statfile = tempfile.mkstemp(".stat", "tryton-")[1] - profile.run('tryton.client.TrytonClient().run()', statfile) + profile.run('client.TrytonClient().run()', statfile) s = pstats.Stats(statfile) s.sort_stats('cumulative').print_stats() s.sort_stats('call').print_stats() @@ -63,4 +63,4 @@ if '--profile' in sys.argv: os.remove(statfile) else: - tryton.client.TrytonClient().run() + client.TrytonClient().run() diff --git a/setup.py b/setup.py index 40e9480da3..929554449f 100644 --- a/setup.py +++ b/setup.py @@ -121,27 +121,31 @@ elif sys.platform == 'darwin': }, } -PACKAGE, VERSION, LICENSE, WEBSITE = None, None, None, None -execfile(os.path.join('tryton', 'version.py')) -major_version, minor_version, _ = VERSION.split('.', 2) +def get_version(): + init = read(os.path.join('tryton', '__init__.py')) + return re.search('__version__ = "([0-9.]*)"', init).group(1) + +version = get_version() +major_version, minor_version, _ = version.split('.', 2) major_version = int(major_version) minor_version = int(minor_version) +name = 'tryton' download_url = 'http://downloads.tryton.org/%s.%s/' % ( major_version, minor_version) if minor_version % 2: - VERSION = '%s.%s.dev0' % (major_version, minor_version) + version = '%s.%s.dev0' % (major_version, minor_version) download_url = 'hg+http://hg.tryton.org/%s#egg=%s-%s' % ( - PACKAGE, PACKAGE, VERSION) + name, name, version) -dist = setup(name=PACKAGE, - version=VERSION, +dist = setup(name=name, + version=version, description='Tryton client', long_description=read('README'), author='Tryton', author_email='issue_tracker@tryton.org', - url=WEBSITE, + url='http://www.tryton.org/', download_url=download_url, keywords='business application ERP', packages=find_packages(), @@ -170,7 +174,7 @@ dist = setup(name=PACKAGE, 'Topic :: Office/Business', ], platforms='any', - license=LICENSE, + license='GPL-3', install_requires=[ # "pygtk >= 2.6", "python-dateutil", @@ -264,10 +268,10 @@ if os.name == 'nt': makensis = find_makensis() if makensis: from subprocess import Popen - Popen([makensis, "/DVERSION=" + VERSION, + Popen([makensis, "/DVERSION=" + version, str(os.path.join(os.path.dirname(__file__), 'setup.nsi'))]).wait() - Popen([makensis, "/DVERSION=" + VERSION, + Popen([makensis, "/DVERSION=" + version, str(os.path.join(os.path.dirname(__file__), 'setup-single.nsi'))]).wait() else: @@ -412,9 +416,9 @@ elif sys.platform == 'darwin': shutil.copytree(os.path.join(os.path.dirname(__file__), 'doc'), doc_dist_dir) - dmg_file = os.path.join(os.path.dirname(__file__), 'tryton-' + VERSION + dmg_file = os.path.join(os.path.dirname(__file__), 'tryton-' + version + '.dmg') if os.path.isfile(dmg_file): os.remove(dmg_file) Popen(['hdiutil', 'create', dmg_file, '-volname', 'Tryton Client ' - + VERSION, '-fs', 'HFS+', '-srcfolder', dist_dir]).wait() + + version, '-fs', 'HFS+', '-srcfolder', dist_dir]).wait() diff --git a/tryton/__init__.py b/tryton/__init__.py index 9182eca204..fec536314e 100644 --- a/tryton/__init__.py +++ b/tryton/__init__.py @@ -1,5 +1,3 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. -import client - -__all__ = ['client'] +__version__ = "3.5.0" diff --git a/tryton/common/common.py b/tryton/common/common.py index f9cddba5cb..11df7756eb 100644 --- a/tryton/common/common.py +++ b/tryton/common/common.py @@ -28,7 +28,7 @@ import threading import tryton.rpc as rpc import locale import socket -from tryton.version import VERSION +from tryton import __version__ import thread import urllib from string import Template @@ -231,7 +231,7 @@ def test_server_version(host, port): version = rpc.server_version(host, port) if not version: return False - return version.split('.')[:2] == VERSION.split('.')[:2] + return version.split('.')[:2] == __version__.split('.')[:2] def refresh_dblist(host, port): diff --git a/tryton/config.py b/tryton/config.py index c9068108d0..a58bce9814 100644 --- a/tryton/config.py +++ b/tryton/config.py @@ -5,7 +5,6 @@ import ConfigParser import optparse import os import gettext -from version import VERSION import logging import sys import locale @@ -13,6 +12,7 @@ import gtk import site from tryton.exceptions import TrytonError +from tryton import __version__ _ = gettext.gettext @@ -26,9 +26,9 @@ def get_home_dir(): def get_config_dir(): if os.name == 'nt': return os.path.join(os.environ['APPDATA'], '.config', 'tryton', - VERSION.rsplit('.', 1)[0]) + __version__.rsplit('.', 1)[0]) return os.path.join(os.environ['HOME'], '.config', 'tryton', - VERSION.rsplit('.', 1)[0]) + __version__.rsplit('.', 1)[0]) if not os.path.isdir(get_config_dir()): os.makedirs(get_config_dir(), 0700) @@ -37,7 +37,7 @@ class ConfigManager(object): "Config manager" def __init__(self): - short_version = '.'.join(VERSION.split('.', 2)[:2]) + short_version = '.'.join(__version__.split('.', 2)[:2]) demo_server = 'demo%s.tryton.org' % short_version demo_database = 'demo%s' % short_version self.defaults = { @@ -76,7 +76,7 @@ class ConfigManager(object): self.arguments = [] def parse(self): - parser = optparse.OptionParser(version=("Tryton %s" % VERSION), + parser = optparse.OptionParser(version=("Tryton %s" % __version__), usage="Usage: %prog [options] [url]") parser.add_option("-c", "--config", dest="config", help=_("specify alternate config file")) diff --git a/tryton/gui/window/about.py b/tryton/gui/window/about.py index e85c72adc3..0f4cec5b09 100644 --- a/tryton/gui/window/about.py +++ b/tryton/gui/window/about.py @@ -5,8 +5,8 @@ import gtk import gettext import webbrowser from tryton.config import TRYTON_ICON -from tryton.version import VERSION, WEBSITE from tryton.common import get_toplevel_window +from tryton import __version__ COPYRIGHT = '''\ Copyright (C) 2010-2011 Nicolas Évrard. @@ -719,10 +719,10 @@ class About(object): self.win = gtk.AboutDialog() self.win.set_transient_for(parent) self.win.set_name('Tryton') - self.win.set_version(VERSION) + self.win.set_version(__version__) self.win.set_copyright(COPYRIGHT) self.win.set_license(LICENSE) - self.win.set_website(WEBSITE) + self.win.set_website('http://www.tryton.org/') self.win.set_authors(AUTHORS) self.win.set_logo(TRYTON_ICON) diff --git a/tryton/gui/window/dblogin.py b/tryton/gui/window/dblogin.py index 647e4b40d5..f181bba54a 100644 --- a/tryton/gui/window/dblogin.py +++ b/tryton/gui/window/dblogin.py @@ -7,7 +7,7 @@ import gobject import os import gettext -from tryton.version import VERSION +from tryton import __version__ import tryton.common as common from tryton.config import CONFIG, TRYTON_ICON, PIXMAPS_DIR, get_config_dir import tryton.rpc as rpc @@ -460,7 +460,7 @@ class DBLogin(object): self.profile_cfg = os.path.join(get_config_dir(), 'profiles.cfg') self.profiles = ConfigParser.SafeConfigParser({'port': '8000'}) if not os.path.exists(self.profile_cfg): - short_version = '.'.join(VERSION.split('.', 2)[:2]) + short_version = '.'.join(__version__.split('.', 2)[:2]) name = 'demo%s.tryton.org' % short_version self.profiles.add_section(name) self.profiles.set(name, 'host', name) diff --git a/tryton/translate.py b/tryton/translate.py index c43913843f..8b8d8def2a 100644 --- a/tryton/translate.py +++ b/tryton/translate.py @@ -4,7 +4,6 @@ import os import locale import gettext -from version import PACKAGE from tryton.config import CURRENT_DIR import logging import gtk @@ -182,8 +181,8 @@ def setlang(lang=None, locale_dict=None): _('Unable to set locale %s') % lang2 + '.' + encoding) if os.path.isdir(locale_dir): - gettext.bindtextdomain(PACKAGE, locale_dir) - gettext.textdomain(PACKAGE) + gettext.bindtextdomain('tryton', locale_dir) + gettext.textdomain('tryton') if locale_dict: conv = locale.localeconv() diff --git a/tryton/version.py b/tryton/version.py deleted file mode 100644 index 4eaee0eb4d..0000000000 --- a/tryton/version.py +++ /dev/null @@ -1,6 +0,0 @@ -# This file is part of Tryton. The COPYRIGHT file at the top level of -# this repository contains the full copyright notices and license terms. -PACKAGE = "tryton" -VERSION = "3.5.0" -LICENSE = "GPL-3" -WEBSITE = "http://www.tryton.org/"