From f9237e1f297e9eca86fbfc83ca217460a306ce60 Mon Sep 17 00:00:00 2001 From: stefan Date: Mon, 23 Feb 2009 14:30:32 +0000 Subject: [PATCH] Refactor setup.py. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4160 57a73879-2fb5-44c3-a270-3262357dd7e2 --- NEWS.txt | 12 + roundup/dist/command/bdist_rpm.py | 33 +++ roundup/dist/command/build.py | 62 ++++ roundup/dist/command/build_py.py | 23 ++ roundup/dist/command/build_scripts.py | 142 +++++++++ setup.py | 395 +++----------------------- 6 files changed, 316 insertions(+), 351 deletions(-) create mode 100644 NEWS.txt create mode 100644 roundup/dist/command/bdist_rpm.py create mode 100644 roundup/dist/command/build.py create mode 100644 roundup/dist/command/build_py.py create mode 100644 roundup/dist/command/build_scripts.py diff --git a/NEWS.txt b/NEWS.txt new file mode 100644 index 0000000..c41265c --- /dev/null +++ b/NEWS.txt @@ -0,0 +1,12 @@ +NEWS +==== + +This file describes user-visible changes to Roundup. + +Roundup 1.4.6 +============= + +This is a bugfix release: + +- Fix bug introduced in 1.4.5 in RDBMS full-text indexing +- Make URL matching code less matchy diff --git a/roundup/dist/command/bdist_rpm.py b/roundup/dist/command/bdist_rpm.py new file mode 100644 index 0000000..6599064 --- /dev/null +++ b/roundup/dist/command/bdist_rpm.py @@ -0,0 +1,33 @@ +# +# Copyright (C) 2009 Stefan Seefeld +# All rights reserved. +# For license terms see the file COPYING.txt. +# +from distutils.command.bdist_rpm import bdist_rpm as base +from distutils.file_util import write_file +import os + +class bdist_rpm(base): + + def finalize_options(self): + base.finalize_options(self) + if self.install_script: + # install script is overridden. skip default + return + # install script option must be file name. + # create the file in rpm build directory. + install_script = os.path.join(self.rpm_base, "install.sh") + self.mkpath(self.rpm_base) + self.execute(write_file, (install_script, [ + ("%s setup.py install --root=$RPM_BUILD_ROOT " + "--record=ROUNDUP_FILES") % self.python, + # allow any additional extension for man pages + # (rpm may compress them to .gz or .bz2) + # man page here is any file + # with single-character extension + # in man directory + "sed -e 's,\(/man/.*\..\)$,\\1*,' " + "INSTALLED_FILES", + ]), "writing '%s'" % install_script) + self.install_script = install_script + diff --git a/roundup/dist/command/build.py b/roundup/dist/command/build.py new file mode 100644 index 0000000..9337aa8 --- /dev/null +++ b/roundup/dist/command/build.py @@ -0,0 +1,62 @@ +# +# Copyright (C) 2009 Stefan Seefeld +# All rights reserved. +# For license terms see the file COPYING.txt. +# +from roundup import msgfmt +from distutils.command.build import build as base +import os +from glob import glob + +def list_message_files(suffix=".po"): + """Return list of all found message files and their intallation paths""" + _files = glob("locale/*" + suffix) + _list = [] + for _file in _files: + # basename (without extension) is a locale name + _locale = os.path.splitext(os.path.basename(_file))[0] + _list.append((_file, os.path.join( + "share", "locale", _locale, "LC_MESSAGES", "roundup.mo"))) + return _list + +def check_manifest(): + """Check that the files listed in the MANIFEST are present when the + source is unpacked. + """ + try: + f = open('MANIFEST') + except: + print '\n*** SOURCE WARNING: The MANIFEST file is missing!' + return + try: + manifest = [l.strip() for l in f.readlines()] + finally: + f.close() + err = [line for line in manifest if not os.path.exists(line)] + err.sort() + # ignore auto-generated files + if err == ['roundup-admin', 'roundup-demo', 'roundup-gettext', + 'roundup-mailgw', 'roundup-server']: + err = [] + if err: + n = len(manifest) + print '\n*** SOURCE WARNING: There are files missing (%d/%d found)!'%( + n-len(err), n) + print 'Missing:', '\nMissing: '.join(err) + + +class build(base): + + def build_message_files(self): + """For each locale/*.po, build .mo file in target locale directory""" + for (_src, _dst) in list_message_files(): + _build_dst = os.path.join("build", _dst) + self.mkpath(os.path.dirname(_build_dst)) + self.announce("Compiling %s -> %s" % (_src, _build_dst)) + msgfmt.make(_src, _build_dst) + + def run(self): + check_manifest() + self.build_message_files() + base.run(self) + diff --git a/roundup/dist/command/build_py.py b/roundup/dist/command/build_py.py new file mode 100644 index 0000000..a0adbd9 --- /dev/null +++ b/roundup/dist/command/build_py.py @@ -0,0 +1,23 @@ +# +# Copyright (C) 2009 Stefan Seefeld +# All rights reserved. +# For license terms see the file COPYING.txt. +# +from distutils.command.build_py import build_py + +class build_py(build_py): + + def find_modules(self): + # Files listed in py_modules are in the toplevel directory + # of the source distribution. + modules = [] + for module in self.py_modules: + path = module.split('.') + package = '.'.join(path[0:-1]) + module_base = path[-1] + module_file = module_base + '.py' + if self.check_module(module, module_file): + modules.append((package, module_base, module_file)) + return modules + + diff --git a/roundup/dist/command/build_scripts.py b/roundup/dist/command/build_scripts.py new file mode 100644 index 0000000..b548913 --- /dev/null +++ b/roundup/dist/command/build_scripts.py @@ -0,0 +1,142 @@ +# +# Copyright (C) 2009 Stefan Seefeld +# All rights reserved. +# For license terms see the file COPYING.txt. +# +from distutils.command.build_scripts import build_scripts as base +import sys, os, string + +class build_scripts(base): + """ Overload the build_scripts command and create the scripts + from scratch, depending on the target platform. + + You have to define the name of your package in an inherited + class (due to the delayed instantiation of command classes + in distutils, this cannot be passed to __init__). + + The scripts are created in an uniform scheme: they start the + run() function in the module + + .scripts. + + The mangling of script names replaces '-' and '/' characters + with '-' and '.', so that they are valid module paths. + + If the target platform is win32, create .bat files instead of + *nix shell scripts. Target platform is set to "win32" if main + command is 'bdist_wininst' or if the command is 'bdist' and + it has the list of formats (from command line or config file) + and the first item on that list is wininst. Otherwise + target platform is set to current (build) platform. + """ + package_name = 'roundup' + + def initialize_options(self): + base.initialize_options(self) + self.script_preamble = None + self.target_platform = None + self.python_executable = None + + def finalize_options(self): + base.finalize_options(self) + cmdopt=self.distribution.command_options + + # find the target platform + if self.target_platform: + # TODO? allow explicit setting from command line + target = self.target_platform + if cmdopt.has_key("bdist_wininst"): + target = "win32" + elif cmdopt.get("bdist", {}).has_key("formats"): + formats = cmdopt["bdist"]["formats"][1].split(",") + if formats[0] == "wininst": + target = "win32" + else: + target = sys.platform + if len(formats) > 1: + self.warn( + "Scripts are built for %s only (requested formats: %s)" + % (target, ",".join(formats))) + else: + # default to current platform + target = sys.platform + self.target_platfom = target + + # for native builds, use current python executable path; + # for cross-platform builds, use default executable name + if self.python_executable: + # TODO? allow command-line option + pass + if target == sys.platform: + self.python_executable = os.path.normpath(sys.executable) + else: + self.python_executable = "python" + + # for windows builds, add ".bat" extension + if target == "win32": + # *nix-like scripts may be useful also on win32 (cygwin) + # to build both script versions, use: + #self.scripts = list(self.scripts) + [script + ".bat" + # for script in self.scripts] + self.scripts = [script + ".bat" for script in self.scripts] + + # tweak python path for installations outside main python library + if cmdopt.get("install", {}).has_key("prefix"): + prefix = os.path.expanduser(cmdopt['install']['prefix'][1]) + version = '%d.%d'%sys.version_info[:2] + self.script_preamble = """ +import sys +sys.path.insert(1, "%s/lib/python%s/site-packages") +"""%(prefix, version) + else: + self.script_preamble = '' + + def copy_scripts(self): + """ Create each script listed in 'self.scripts' + """ + + to_module = string.maketrans('-/', '_.') + + self.mkpath(self.build_dir) + for script in self.scripts: + outfile = os.path.join(self.build_dir, os.path.basename(script)) + + #if not self.force and not newer(script, outfile): + # self.announce("not copying %s (up-to-date)" % script) + # continue + + if self.dry_run: + self.announce("would create %s" % outfile) + continue + + module = os.path.splitext(os.path.basename(script))[0] + module = string.translate(module, to_module) + script_vars = { + 'python': self.python_executable, + 'package': self.package_name, + 'module': module, + 'prefix': self.script_preamble, + } + + self.announce("creating %s" % outfile) + file = open(outfile, 'w') + + try: + # could just check self.target_platform, + # but looking at the script extension + # makes it possible to build both *nix-like + # and windows-like scripts on win32. + # may be useful for cygwin. + if os.path.splitext(outfile)[1] == ".bat": + file.write('@echo off\n' + 'if NOT "%%_4ver%%" == "" "%(python)s" -c "from %(package)s.scripts.%(module)s import run; run()" %%$\n' + 'if "%%_4ver%%" == "" "%(python)s" -c "from %(package)s.scripts.%(module)s import run; run()" %%*\n' + % script_vars) + else: + file.write('#! %(python)s\n%(prefix)s' + 'from %(package)s.scripts.%(module)s import run\n' + 'run()\n' + % script_vars) + finally: + file.close() + os.chmod(outfile, 0755) diff --git a/setup.py b/setup.py index f9fddac..27d533d 100644 --- a/setup.py +++ b/setup.py @@ -16,19 +16,16 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: setup.py,v 1.105 2008-09-01 01:58:32 richard Exp $ from roundup.dist.command.build_doc import build_doc -from distutils.core import setup, Extension -from distutils.util import get_platform -from distutils.file_util import write_file -from distutils.command.bdist_rpm import bdist_rpm -from distutils.command.build import build -from distutils.command.build_scripts import build_scripts -from distutils.command.build_py import build_py +from roundup.dist.command.build_scripts import build_scripts +from roundup.dist.command.build_py import build_py +from roundup.dist.command.build import build, list_message_files +from roundup.dist.command.bdist_rpm import bdist_rpm +from distutils.core import setup -import sys, os, string +import sys, os from glob import glob # patch distutils if it can't cope with the "classifiers" keyword @@ -37,8 +34,6 @@ if not hasattr(DistributionMetadata, 'classifiers'): DistributionMetadata.classifiers = None DistributionMetadata.download_url = None -from roundup import msgfmt - def include(d, e): """Generate a pair of (directory, file-list) for installation. @@ -48,259 +43,14 @@ def include(d, e): return (d, [f for f in glob('%s/%s'%(d, e)) if os.path.isfile(f)]) -############################################################################# -### Build script files -############################################################################# - -class build_scripts_create(build_scripts): - """ Overload the build_scripts command and create the scripts - from scratch, depending on the target platform. - - You have to define the name of your package in an inherited - class (due to the delayed instantiation of command classes - in distutils, this cannot be passed to __init__). - - The scripts are created in an uniform scheme: they start the - run() function in the module - - .scripts. - - The mangling of script names replaces '-' and '/' characters - with '-' and '.', so that they are valid module paths. - - If the target platform is win32, create .bat files instead of - *nix shell scripts. Target platform is set to "win32" if main - command is 'bdist_wininst' or if the command is 'bdist' and - it has the list of formats (from command line or config file) - and the first item on that list is wininst. Otherwise - target platform is set to current (build) platform. - """ - package_name = None - - def initialize_options(self): - build_scripts.initialize_options(self) - self.script_preamble = None - self.target_platform = None - self.python_executable = None - - def finalize_options(self): - build_scripts.finalize_options(self) - cmdopt=self.distribution.command_options - - # find the target platform - if self.target_platform: - # TODO? allow explicit setting from command line - target = self.target_platform - if cmdopt.has_key("bdist_wininst"): - target = "win32" - elif cmdopt.get("bdist", {}).has_key("formats"): - formats = cmdopt["bdist"]["formats"][1].split(",") - if formats[0] == "wininst": - target = "win32" - else: - target = sys.platform - if len(formats) > 1: - self.warn( - "Scripts are built for %s only (requested formats: %s)" - % (target, ",".join(formats))) - else: - # default to current platform - target = sys.platform - self.target_platfom = target - - # for native builds, use current python executable path; - # for cross-platform builds, use default executable name - if self.python_executable: - # TODO? allow command-line option - pass - if target == sys.platform: - self.python_executable = os.path.normpath(sys.executable) - else: - self.python_executable = "python" - - # for windows builds, add ".bat" extension - if target == "win32": - # *nix-like scripts may be useful also on win32 (cygwin) - # to build both script versions, use: - #self.scripts = list(self.scripts) + [script + ".bat" - # for script in self.scripts] - self.scripts = [script + ".bat" for script in self.scripts] - - # tweak python path for installations outside main python library - if cmdopt.get("install", {}).has_key("prefix"): - prefix = os.path.expanduser(cmdopt['install']['prefix'][1]) - version = '%d.%d'%sys.version_info[:2] - self.script_preamble = ''' -import sys -sys.path.insert(1, "%s/lib/python%s/site-packages") -'''%(prefix, version) - else: - self.script_preamble = '' - - def copy_scripts(self): - """ Create each script listed in 'self.scripts' - """ - if not self.package_name: - raise Exception("You have to inherit build_scripts_create and" - " provide a package name") - - to_module = string.maketrans('-/', '_.') - - self.mkpath(self.build_dir) - for script in self.scripts: - outfile = os.path.join(self.build_dir, os.path.basename(script)) - - #if not self.force and not newer(script, outfile): - # self.announce("not copying %s (up-to-date)" % script) - # continue - - if self.dry_run: - self.announce("would create %s" % outfile) - continue - - module = os.path.splitext(os.path.basename(script))[0] - module = string.translate(module, to_module) - script_vars = { - 'python': self.python_executable, - 'package': self.package_name, - 'module': module, - 'prefix': self.script_preamble, - } - - self.announce("creating %s" % outfile) - file = open(outfile, 'w') - - try: - # could just check self.target_platform, - # but looking at the script extension - # makes it possible to build both *nix-like - # and windows-like scripts on win32. - # may be useful for cygwin. - if os.path.splitext(outfile)[1] == ".bat": - file.write('@echo off\n' - 'if NOT "%%_4ver%%" == "" "%(python)s" -c "from %(package)s.scripts.%(module)s import run; run()" %%$\n' - 'if "%%_4ver%%" == "" "%(python)s" -c "from %(package)s.scripts.%(module)s import run; run()" %%*\n' - % script_vars) - else: - file.write('#! %(python)s\n%(prefix)s' - 'from %(package)s.scripts.%(module)s import run\n' - 'run()\n' - % script_vars) - finally: - file.close() - os.chmod(outfile, 0755) - - -class build_scripts_roundup(build_scripts_create): - package_name = 'roundup' - - def scriptname(path): """ Helper for building a list of script names from a list of module files. """ script = os.path.splitext(os.path.basename(path))[0] - script = string.replace(script, '_', '-') + script = script.replace('_', '-') return script -### Build Roundup - -def list_message_files(suffix=".po"): - """Return list of all found message files and their intallation paths""" - _files = glob("locale/*" + suffix) - _list = [] - for _file in _files: - # basename (without extension) is a locale name - _locale = os.path.splitext(os.path.basename(_file))[0] - _list.append((_file, os.path.join( - "share", "locale", _locale, "LC_MESSAGES", "roundup.mo"))) - return _list - -def check_manifest(): - """Check that the files listed in the MANIFEST are present when the - source is unpacked. - """ - try: - f = open('MANIFEST') - except: - print '\n*** SOURCE WARNING: The MANIFEST file is missing!' - return - try: - manifest = [l.strip() for l in f.readlines()] - finally: - f.close() - err = [line for line in manifest if not os.path.exists(line)] - err.sort() - # ignore auto-generated files - if err == ['roundup-admin', 'roundup-demo', 'roundup-gettext', - 'roundup-mailgw', 'roundup-server']: - err = [] - if err: - n = len(manifest) - print '\n*** SOURCE WARNING: There are files missing (%d/%d found)!'%( - n-len(err), n) - print 'Missing:', '\nMissing: '.join(err) - - -class build_py_roundup(build_py): - - def find_modules(self): - # Files listed in py_modules are in the toplevel directory - # of the source distribution. - modules = [] - for module in self.py_modules: - path = string.split(module, '.') - package = string.join(path[0:-1], '.') - module_base = path[-1] - module_file = module_base + '.py' - if self.check_module(module, module_file): - modules.append((package, module_base, module_file)) - return modules - - -class build_roundup(build): - - def build_message_files(self): - """For each locale/*.po, build .mo file in target locale directory""" - for (_src, _dst) in list_message_files(): - _build_dst = os.path.join("build", _dst) - self.mkpath(os.path.dirname(_build_dst)) - self.announce("Compiling %s -> %s" % (_src, _build_dst)) - msgfmt.make(_src, _build_dst) - - def run(self): - check_manifest() - self.build_message_files() - build.run(self) - -class bdist_rpm_roundup(bdist_rpm): - - def finalize_options(self): - bdist_rpm.finalize_options(self) - if self.install_script: - # install script is overridden. skip default - return - # install script option must be file name. - # create the file in rpm build directory. - install_script = os.path.join(self.rpm_base, "install.sh") - self.mkpath(self.rpm_base) - self.execute(write_file, (install_script, [ - ("%s setup.py install --root=$RPM_BUILD_ROOT " - "--record=ROUNDUP_FILES") % self.python, - # allow any additional extension for man pages - # (rpm may compress them to .gz or .bz2) - # man page here is any file - # with single-character extension - # in man directory - "sed -e 's,\(/man/.*\..\)$,\\1*,' " - "INSTALLED_FILES", - ]), "writing '%s'" % install_script) - self.install_script = install_script - -############################################################################# -### Main setup stuff -############################################################################# - def main(): # build list of scripts from their implementation modules roundup_scripts = map(scriptname, glob('roundup/scripts/[!_]*.py')) @@ -356,100 +106,43 @@ def main(): # perform the setup action from roundup import __version__ - setup_args = { - 'name': "roundup", - 'version': __version__, - 'description': "A simple-to-use and -install issue-tracking system" - " with command-line, web and e-mail interfaces. Highly" - " customisable.", - 'long_description': -'''In this release -=============== - -1.4.6 is a bugfix release: - -- Fix bug introduced in 1.4.5 in RDBMS full-text indexing -- Make URL matching code less matchy - -If you're upgrading from an older version of Roundup you *must* follow -the "Software Upgrade" guidelines given in the maintenance documentation. - -Roundup requires python 2.3 or later for correct operation. - -To give Roundup a try, just download (see below), unpack and run:: - - roundup-demo - -Documentation is available at the website: - http://roundup.sourceforge.net/ -Mailing lists - the place to ask questions: - http://sourceforge.net/mail/?group_id=31577 - -About Roundup -============= - -Roundup is a simple-to-use and -install issue-tracking system with -command-line, web and e-mail interfaces. It is based on the winning design -from Ka-Ping Yee in the Software Carpentry "Track" design competition. - -Note: Ping is not responsible for this project. The contact for this -project is richard@users.sourceforge.net. - -Roundup manages a number of issues (with flexible properties such as -"description", "priority", and so on) and provides the ability to: - -(a) submit new issues, -(b) find and edit existing issues, and -(c) discuss issues with other participants. - -The system will facilitate communication among the participants by managing -discussions and notifying interested parties when issues are edited. One of -the major design goals for Roundup that it be simple to get going. Roundup -is therefore usable "out of the box" with any python 2.3+ installation. It -doesn't even need to be "installed" to be operational, though a -disutils-based install script is provided. - -It comes with two issue tracker templates (a classic bug/feature tracker and -a minimal skeleton) and five database back-ends (anydbm, sqlite, metakit, -mysql and postgresql). -''', - 'author': "Richard Jones", - 'author_email': "richard@users.sourceforge.net", - 'url': 'http://roundup.sourceforge.net/', - 'packages': packagelist, - 'classifiers': [ - 'Development Status :: 5 - Production/Stable', - 'Environment :: Console', - 'Environment :: Web Environment', - 'Intended Audience :: End Users/Desktop', - 'Intended Audience :: Developers', - 'Intended Audience :: System Administrators', - 'License :: OSI Approved :: Python Software Foundation License', - 'Operating System :: MacOS :: MacOS X', - 'Operating System :: Microsoft :: Windows', - 'Operating System :: POSIX', - 'Programming Language :: Python', - 'Topic :: Communications :: Email', - 'Topic :: Office/Business', - 'Topic :: Software Development :: Bug Tracking', - ], - - # Override certain command classes with our own ones - 'cmdclass': { - 'build_doc': build_doc, - 'build_scripts': build_scripts_roundup, - 'build_py': build_py_roundup, - 'build': build_roundup, - 'bdist_rpm': bdist_rpm_roundup, - }, - 'scripts': roundup_scripts, - - 'data_files': installdatafiles - } - if sys.version_info[:2] > (2, 2): - setup_args['py_modules'] = py_modules - - setup(**setup_args) + + setup(name='roundup', + version=__version__, + author="Richard Jones", + author_email="richard@users.sourceforge.net", + description='Issue-tracking System.', + long_description="""Roundup is a simple-to-use and -install issue-tracking system +with command-line, web and e-mail interfaces. Highly customisable.""", + url='http://www.roundup-tracker.org', + download_url='http://pypi.python.org/pypi/roundup', + classifiers=['Development Status :: 5 - Production/Stable', + 'Environment :: Console', + 'Environment :: Web Environment', + 'Intended Audience :: End Users/Desktop', + 'Intended Audience :: Developers', + 'Intended Audience :: System Administrators', + 'License :: OSI Approved :: Python Software Foundation License', + 'Operating System :: MacOS :: MacOS X', + 'Operating System :: Microsoft :: Windows', + 'Operating System :: POSIX', + 'Programming Language :: Python', + 'Topic :: Communications :: Email', + 'Topic :: Office/Business', + 'Topic :: Software Development :: Bug Tracking', + ], + + # Override certain command classes with our own ones + cmdclass= {'build_doc': build_doc, + 'build_scripts': build_scripts, + 'build_py': build_py, + 'build': build, + 'bdist_rpm': bdist_rpm, + }, + packages=packagelist, + py_modules=py_modules, + scripts=roundup_scripts, + data_files=installdatafiles) if __name__ == '__main__': main() -- 2.30.2