From: David G. <go...@py...> - 2004-09-19 14:31:53
|
[Felix Wiemann] > The overriding mechanism for stylesheet and stylesheet_path is > broken, because if 'stylesheet_path' is specified at any place, > setting 'stylesheet' has no effect. This was discussed here in July. See <http://thread.gmane.org/gmane.text.docutils.devel/2068>. > So, as you can see from the last command, when specifying > --stylesheet at the command line, the stylesheet-path in > docutils.conf isn't overriden. That's bad and unintuitive. > > There are several fixes I can think of: > > 1. Delete ``stylesheet`` when ``stylesheet_path`` is set and vice > versa. That's the conclusion Beni & I reached as well. I don't think fix 2 or 3 are worth exploring. > I tried to implement fix number 1, and encountered the following > difficulties: > > * There is duplicate logic in the html4css1 and the latex2e writer > concerning stylesheets. I'm not arguing for moving the stylesheet > handling to the Docutils core, but I think that the logic > shouldn't be redundantly stored in two files. Maybe have a common > baseclass or so? They do have a common base class: docutils.writers.Writer. If the code is duplicated between the two writers, it could be moved to the base class. If it's not desirable to have the shared code in docutils.writers.Writer, we could make a new subclass of that, perhaps WriterWithStylesheet. But looking at docs/user/config.txt and at the command-line option descriptions, the two writers seem to have different semantics. I don't really understand the descriptions for the LaTeX writer, and I suspect that there might be some confusion there. > * Setting options is done differently when doing command line > parsing and when overlaying settings settings_spec and > settings_overrides. So I had to fix it twice. I don't think settings_overrides etc. should have any special support. If "stylesheet" and "stylesheet_path" are mutually-overriding options, they could also become mutually-exclusive settings: if both are set, an error should be raised. If client code sets both programmatically, that's an error. > The following output from ``cvs diff`` is an example implementation, > but only for the html4css1 writer. It's extremely hackish and I'm > not sure if it will always work. > > -------------------------------------------------------------------- > Index: docutils/frontend.py ... > + ATTRS = optparse.Option.ATTRS + ['overrides'] I like this; the "validator" keyword should be implemented similarly. > + def set_defaults(self, **k): > + """ > + Hack to make stylesheet override stylesheet_path and v.v. > + """ > + s = 'stylesheet' > + sp = 'stylesheet_path' > + if k.has_key(s) and k.has_key(sp): > + # arbitrary > + k[s] = k[sp] > + if k.has_key(s): > + self.set_default(sp, None) > + if k.has_key(sp): > + self.set_default(s, None) > + optparse.OptionParser.set_defaults(self, **k) I don't think this is useful. If either stylesheet or stylesheet_path is set in code, the other should be explicitly unset (set to None). The code that uses stylesheet/stylesheet_path should check for the collision. -- David Goodger <http://python.net/~goodger> |