Conversation
jennifer-richards
left a comment
There was a problem hiding this comment.
One potentially important comment inline. Requesting changes because I think that's a bug, but it depends on what input you intend to accept.
Also... Rather than inserting a cleanup function in every code path, I think you could put the call to delete_tempfile() in a finally: block at the end of your try. However, you might consider getting fancy and using ExitStack from contextlib:
from contextlib import ExitStack
# ... setup stuff ...
with ExitStack() as stack:
if len(args) < 1:
tmp_file = stack.enter_context(NamedTemporaryFile(delete_on_close=False, mode="w+t")) # or w+b
data = #...
tmp_file.write(data)
tmp_file.close()
source = tmp_file.name
else:
source = args[0]
# test existence...
# ... rest of the processing, minus the delete_tempfile() callsThis will conditionally open a context and let NamedTemporaryFile do the deletion magic (note the significant change from delete=False to delete_on_close=False in its call).
This add support for stdin input from Windows from Python 3.12 onwards.
jennifer-richards
left a comment
There was a problem hiding this comment.
Just a minor suggestion to consider.
I have slight misgivings about the separate calls to process_svg() in the two paths and the introduction of version-dependent code paths. That's only on the basis of slippery slopes toward complexity, though, so I don't object.
jennifer-richards
left a comment
There was a problem hiding this comment.
One last tweak needed. (You could also take the post-tmp_file-write stuff out of the with block instead of explicitly closing, but I think that's ok either way.)
yeah, but no gains or adverse effects either way? |
Fixes #36