inkex/base.py cannot be imported when stdout is closed
If stdout is closed (as can happen with some extensions out there, like inkscape-silhouette when running in multi-action mode, in an effort to cede control back to inkscape while the extension runs for an extended period of time), then it is impossible even to import inkex
.
The difficulty is in inkex/base.py, which has at the top level (line 37 in current head):
stdout = sys.stdout.buffer
This statement throws a
AttributeError: 'NoneType' object has no attribute 'buffer'
exception if stdout is closed. And in general, it seems to me that the module ought to work if stdout is any file-like object, and nothing in the IOBase specification says there should be an attribute 'buffer' for a file-like object.
In fact, the only place that stdout
is used in inkex/base.py is on line 132:
def run(self, args=None, output=stdout):
to supply the default output stream for saving the result of the extension. Here again, it seems that any file-like object should do, and that it should be fine to remove the local variable stdout
altogether and change line 132 to
def run(self, args=None, output=sys.stdout):
which would avoid the exception noted above. I would be happy to file a minimal merge request with that change if someone with more experience with the inkex code could provide a concurring opinion that the change would be a positive.
In any case, I think it's reasonable to consider the current situation a bug; it doesn't seem as though the absence of standard output should prevent inkex even from being imported, even if it might likely cause exceptions later if/when the extension attempts to save its results (but it might be fine even then, for example if the output option has been explicitly specified).