-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Read from STDIN #56
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() calls
This 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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