Skip to content
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

Merged
merged 13 commits into from
Oct 14, 2024
Merged

fix: Read from STDIN #56

merged 13 commits into from
Oct 14, 2024

Conversation

kesara
Copy link
Member

@kesara kesara commented Sep 30, 2024

Fixes #36

@kesara kesara marked this pull request as ready for review September 30, 2024 09:01
svgcheck/run.py Outdated Show resolved Hide resolved
svgcheck/run.py Outdated Show resolved Hide resolved
Copy link
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).

svgcheck/run.py Outdated Show resolved Hide resolved
@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
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.

svgcheck/run.py Outdated Show resolved Hide resolved
svgcheck/run.py Outdated Show resolved Hide resolved
Copy link
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.)

svgcheck/run.py Outdated Show resolved Hide resolved
@kesara
Copy link
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
18 checks passed
@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