Skip to content

fix: Read from STDIN#56

Merged
kesara merged 13 commits intoietf-tools:mainfrom
kesara:fix/stdin
Oct 14, 2024
Merged

fix: Read from STDIN#56
kesara merged 13 commits intoietf-tools:mainfrom
kesara:fix/stdin

Conversation

@kesara
Copy link
Copy Markdown
Member

@kesara kesara commented Sep 30, 2024

Fixes #36

@kesara kesara marked this pull request as ready for review September 30, 2024 09:01
Copy link
Copy Markdown
Member

@jennifer-richards jennifer-richards left a 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).

@kesara kesara marked this pull request as draft October 1, 2024 19:38
@kesara kesara marked this pull request as ready for review October 10, 2024 01:23
This add support for stdin input from Windows from Python 3.12 onwards.
Copy link
Copy Markdown
Member

@jennifer-richards jennifer-richards left a 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.

Copy link
Copy Markdown
Member

@jennifer-richards jennifer-richards left a 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.)

@kesara
Copy link
Copy Markdown
Member Author

kesara commented Oct 13, 2024

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?

@kesara kesara merged commit 87031fd into ietf-tools:main Oct 14, 2024
@kesara kesara deleted the fix/stdin branch October 14, 2024 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restore ability to use STDIN

3 participants