Mercurial > p > roundup > code
annotate roundup/dist/command/build_scripts.py @ 5096:e74c3611b138
- issue2550636, issue2550909: Added support for Whoosh indexer.
Also adds new config.ini setting called indexer to select
indexer. See ``doc/upgrading.txt`` for details. Initial patch
done by David Wolever. Patch modified (see ticket or below for
changes), docs updated and committed.
I have an outstanding issue with test/test_indexer.py. I have to
comment out all imports and tests for indexers I don't have (i.e.
mysql, postgres) otherwise no tests run.
With that change made, dbm, sqlite (rdbms), xapian and whoosh indexes
are all passing the indexer tests.
Changes summary:
1) support native back ends dbm and rdbms. (original patch only fell
through to dbm)
2) Developed whoosh stopfilter to not index stopwords or words outside
the the maxlength and minlength limits defined in index_common.py.
Required to pass the extremewords test_indexer test. Also I
removed a call to .lower on the input text as the tokenizer I chose
automatically does the lowercase.
3) Added support for max/min length to find. This was needed to pass
extremewords test.
4) Added back a call to save_index in add_text. This allowed all but
two tests to pass.
5) Fixed a call to:
results = searcher.search(query.Term("identifier", identifier))
which had an extra parameter that is an error under current whoosh.
6) Set limit=None in search call for find() otherwise it only return
10 items. This allowed it to pass manyresults test
Also due to changes in the roundup code removed the call in
indexer_whoosh to
from roundup.anypy.sets_ import set
since we use the python builtin set.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 25 Jun 2016 20:10:03 -0400 |
| parents | 5e2888db6c48 |
| children | 64c4e43fbb84 |
| rev | line source |
|---|---|
| 4068 | 1 # |
| 2 # Copyright (C) 2009 Stefan Seefeld | |
| 3 # All rights reserved. | |
| 4 # For license terms see the file COPYING.txt. | |
| 5 # | |
| 6 from distutils.command.build_scripts import build_scripts as base | |
|
5023
5e2888db6c48
build_scripts: self.announce --> log.info because it is visible
anatoly techtonik <techtonik@gmail.com>
parents:
5022
diff
changeset
|
7 from distutils import log |
| 4068 | 8 import sys, os, string |
| 9 | |
| 10 class build_scripts(base): | |
| 11 """ Overload the build_scripts command and create the scripts | |
| 12 from scratch, depending on the target platform. | |
| 13 | |
| 14 You have to define the name of your package in an inherited | |
| 15 class (due to the delayed instantiation of command classes | |
| 16 in distutils, this cannot be passed to __init__). | |
| 17 | |
| 18 The scripts are created in an uniform scheme: they start the | |
| 19 run() function in the module | |
| 20 | |
| 21 <packagename>.scripts.<mangled_scriptname> | |
| 22 | |
| 23 The mangling of script names replaces '-' and '/' characters | |
| 24 with '-' and '.', so that they are valid module paths. | |
| 25 | |
| 26 If the target platform is win32, create .bat files instead of | |
| 27 *nix shell scripts. Target platform is set to "win32" if main | |
| 28 command is 'bdist_wininst' or if the command is 'bdist' and | |
| 29 it has the list of formats (from command line or config file) | |
| 30 and the first item on that list is wininst. Otherwise | |
| 31 target platform is set to current (build) platform. | |
| 32 """ | |
| 33 package_name = 'roundup' | |
| 34 | |
| 35 def initialize_options(self): | |
| 36 base.initialize_options(self) | |
| 37 self.script_preamble = None | |
| 38 self.target_platform = None | |
| 39 self.python_executable = None | |
| 40 | |
| 41 def finalize_options(self): | |
| 42 base.finalize_options(self) | |
| 43 cmdopt=self.distribution.command_options | |
| 44 | |
| 45 # find the target platform | |
| 46 if self.target_platform: | |
| 47 # TODO? allow explicit setting from command line | |
| 48 target = self.target_platform | |
| 49 if cmdopt.has_key("bdist_wininst"): | |
| 50 target = "win32" | |
| 51 elif cmdopt.get("bdist", {}).has_key("formats"): | |
| 52 formats = cmdopt["bdist"]["formats"][1].split(",") | |
| 53 if formats[0] == "wininst": | |
| 54 target = "win32" | |
| 55 else: | |
| 56 target = sys.platform | |
| 57 if len(formats) > 1: | |
| 58 self.warn( | |
| 59 "Scripts are built for %s only (requested formats: %s)" | |
| 60 % (target, ",".join(formats))) | |
| 61 else: | |
| 62 # default to current platform | |
| 63 target = sys.platform | |
|
5022
9250620c7219
build_scripts: Fix long term bug with setting self.target_platform
anatoly techtonik <techtonik@gmail.com>
parents:
4068
diff
changeset
|
64 self.target_platform = target |
| 4068 | 65 |
| 66 # for native builds, use current python executable path; | |
| 67 # for cross-platform builds, use default executable name | |
| 68 if self.python_executable: | |
| 69 # TODO? allow command-line option | |
| 70 pass | |
| 71 if target == sys.platform: | |
| 72 self.python_executable = os.path.normpath(sys.executable) | |
| 73 else: | |
| 74 self.python_executable = "python" | |
| 75 | |
| 76 # for windows builds, add ".bat" extension | |
| 77 if target == "win32": | |
| 78 # *nix-like scripts may be useful also on win32 (cygwin) | |
| 79 # to build both script versions, use: | |
| 80 #self.scripts = list(self.scripts) + [script + ".bat" | |
| 81 # for script in self.scripts] | |
| 82 self.scripts = [script + ".bat" for script in self.scripts] | |
| 83 | |
| 84 # tweak python path for installations outside main python library | |
| 85 if cmdopt.get("install", {}).has_key("prefix"): | |
| 86 prefix = os.path.expanduser(cmdopt['install']['prefix'][1]) | |
| 87 version = '%d.%d'%sys.version_info[:2] | |
| 88 self.script_preamble = """ | |
| 89 import sys | |
| 90 sys.path.insert(1, "%s/lib/python%s/site-packages") | |
| 91 """%(prefix, version) | |
| 92 else: | |
| 93 self.script_preamble = '' | |
| 94 | |
| 95 def copy_scripts(self): | |
| 96 """ Create each script listed in 'self.scripts' | |
| 97 """ | |
| 98 | |
| 99 to_module = string.maketrans('-/', '_.') | |
| 100 | |
| 101 self.mkpath(self.build_dir) | |
| 102 for script in self.scripts: | |
| 103 outfile = os.path.join(self.build_dir, os.path.basename(script)) | |
| 104 | |
| 105 #if not self.force and not newer(script, outfile): | |
| 106 # self.announce("not copying %s (up-to-date)" % script) | |
| 107 # continue | |
| 108 | |
| 109 if self.dry_run: | |
|
5023
5e2888db6c48
build_scripts: self.announce --> log.info because it is visible
anatoly techtonik <techtonik@gmail.com>
parents:
5022
diff
changeset
|
110 log.info("would create %s" % outfile) |
| 4068 | 111 continue |
| 112 | |
| 113 module = os.path.splitext(os.path.basename(script))[0] | |
| 114 module = string.translate(module, to_module) | |
| 115 script_vars = { | |
| 116 'python': self.python_executable, | |
| 117 'package': self.package_name, | |
| 118 'module': module, | |
| 119 'prefix': self.script_preamble, | |
| 120 } | |
| 121 | |
|
5023
5e2888db6c48
build_scripts: self.announce --> log.info because it is visible
anatoly techtonik <techtonik@gmail.com>
parents:
5022
diff
changeset
|
122 log.info("writing %s" % outfile) |
| 4068 | 123 file = open(outfile, 'w') |
| 124 | |
| 125 try: | |
| 126 # could just check self.target_platform, | |
| 127 # but looking at the script extension | |
| 128 # makes it possible to build both *nix-like | |
| 129 # and windows-like scripts on win32. | |
| 130 # may be useful for cygwin. | |
| 131 if os.path.splitext(outfile)[1] == ".bat": | |
| 132 file.write('@echo off\n' | |
| 133 'if NOT "%%_4ver%%" == "" "%(python)s" -c "from %(package)s.scripts.%(module)s import run; run()" %%$\n' | |
| 134 'if "%%_4ver%%" == "" "%(python)s" -c "from %(package)s.scripts.%(module)s import run; run()" %%*\n' | |
| 135 % script_vars) | |
| 136 else: | |
| 137 file.write('#! %(python)s\n%(prefix)s' | |
| 138 'from %(package)s.scripts.%(module)s import run\n' | |
| 139 'run()\n' | |
| 140 % script_vars) | |
| 141 finally: | |
| 142 file.close() | |
| 143 os.chmod(outfile, 0755) |
