Mercurial > p > roundup > code
annotate roundup/dist/command/build_scripts.py @ 5305:e20f472fde7d
issue2550799: provide basic support for handling html only emails
Initial implementation and testing with the dehtml html converter
done.
The use of beautifulsoup 4 is not tested. My test system breaks when
running dehtml.py using beautiful soup. I don't get the failures when
running under the test harness, but the text output is significantly
different (different line breaks, number of newlines etc.)
The tests for dehtml need to be generated for beautiful soup and the
expected output changed. Since I have a wonky install of beautiful
soup, I don't trust my output as the standard to test against. Also
since beautiful soup is optional, the test harness needs to skip the
beautifulsoup tests if import bs4 fails. Again something outside of my
expertise. I deleted the work I had done to implement that. I could
not get it working and wanted to get this feature in in some form.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Fri, 13 Oct 2017 21:46:59 -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) |
