-
Notifications
You must be signed in to change notification settings - Fork 19
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
StarWriter.lines
#62
StarWriter.lines
#62
Conversation
Generates strings that are written out by `StarWriter.write`.
very nice! will review properly some time after Thursday (prepping/running a workshop) |
maybe @jojoelfe has some time now? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #62 +/- ##
==========================================
+ Coverage 80.93% 82.73% +1.80%
==========================================
Files 7 7
Lines 278 307 +29
==========================================
+ Hits 225 254 +29
Misses 53 53 ☔ View full report in Codecov by Sentry. |
I'll try to look at this tonight, but can't really promise too much. @jahooker Thanks so much for the PR! Can you maybe write one or two lines what the motivation for this is? I do think it's a bit nicer that the constructor does not immediately write to disk, but when would one want to do this? |
Hi! Thanks for taking the time to consider my changes! Quite a few times now, I have found myself wanting — in an interactive Python session — to see what #!python3
import starfile
from starfile.writer import StarWriter
from elsewhere import foo
bar = starfile.read('bar.star')
writer = StarWriter(foo(bar), '')
print(''.join(writer.file_contents())) Admittedly, the interface could be nicer. Perhaps |
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.
I do think this usecase makes sense. There are a couple thoughts I have:
- I guess there is a chance that this breaks some existing if somebody used the StarWriter class. But as far as I can tell the StarWriter class is not documented anywhere, so I don't think this is a large concern.
- Since the StarWriter class is not really supposed to be a public API, wouldn't it be nice to have an exposed function so one could do this:
import starfile
from elsewhere import foo
bar = starfile.read('bar.star')
starstring = starfile.to_string(foo(bar))
- I do like having a generator for the lines, as this might help people who want to stream/paginate starfiles. But to me looks like in the current state the actual data is returned as a single string by the file_contents() function.
- If we do not care about the API stability, it would make sense to remove the filename from the constructor and instead make it an argument to the
write()
method
@alisterburt I don't think I can trigger the tests on this PR. Can you do it? |
Hey @jahooker, I've just added a few tests and minor fixes. The speed test for python3.9 keeps on failing, but on my machine the new code does not cause performance recession with py3.9 and py3.10... Maybe it just gets assigned to a runner with performance problems. If you don't have anything to add (maybe some documentation would be nice, but can also be done later) this seems good to got to me. Thanks again! Johannes |
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.
Thanks @jojoelfe! Looks good. I'll write a little bit of documentation.
Great, I merged for now and created an issue for the documentation. |
I've made a few small modifications to
StarWriter
.Now, you can instantiate the class without writing to disk.
To write, you need to explicitly call
StarWriter.write
.You can also just see the contents of the file that a
StarWriter
would write, withStarWriter.file_contents
.