-
-
Notifications
You must be signed in to change notification settings - Fork 418
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
Reimplement files.FileLines #2707
Conversation
This one still needs some docstrings and some manual changelog entries. |
I'm uncomfortable with the iso change on buffered.Reader not going through some sort of discussion or RFC. Its out of scope for "Reimplement files.FileLines" and we should have a bit of discussion on a breaking change that expands that scope. |
I know it's not classy to mangle it all together in one PR. I am happy to turn into RFC or separate PR what needs to be turned. This is my desired state of I just wanted to check back, if the outcome is in any way desirable: Having FileLines return |
@SeanTAllen would you find an RFC appropriate for the iso change in buffered.Reader? |
I think we should discuss what is appropriate during sync. |
From today's Pony sync call: this work is inspired by #2185. |
We discussed this on the sync call and decided to make the change on This also needs to have the examples fixed. |
@SeanTAllen this is ready for a review. |
Well actually this still contains a bug. It is not correctly resetting the file position in all cases, might be a bug in the |
It seems to work correctly on most platforms, but is failing on windows due to some condition i do not fully understand. Appveyor fails with:
Which is, in the test it opens a file with the following contents: |
I'll take a look later today. |
Yeah, by default Windows will write
Maybe this should be a separate PR? |
Yes, i think so too, +1 for separate PR. This PR has been digging up some corpses already, one more is just fine. |
By default Windows will translate `\n` to `\r\n` when writing to files, and vice versa when reading. This interacts poorly with seeking in the file first (ponylang#2707). This change makes opening files via the `files` module always use "binary" mode, which will not do any translation.
By default Windows will translate `\n` to `\r\n` when writing to files, and vice versa when reading. This interacts poorly with seeking in the file first (ponylang#2707). This change makes opening files via the `files` package always use "binary" mode, which will not do any translation.
I rebased, added some docstrings and added manual changelog entries for what has been fixed, changed and added. If CI is fine this is ready to be merged. |
Release notes draftThe function In order to only get a single line from a file, and not iterate over the whole file, you can use the following code snippet: let line = my_file.lines().next()? |
Looking at this from afar i recognize that FileLines does not consume the file i.e. advancing the cursor up to where it was reading from the file in general makes sense, but always resetting it to where it was before might actually be counterintuitive. The general expectation is (i suppose) that whenever i read something from a file the cursor is advanced by that amount. FileLines is usually reading more, buffering these contents. It might be more reasonable to advance the cursor beyond the trailing linebreak of the returned line? Any thoughts on this? |
Advancing the cursor would be my expectation.
…On Wed, Jul 4, 2018 at 12:12 PM Matthias Wahl ***@***.***> wrote:
Looking at this from afar i recognize that FileLines does not consume the
file i.e. advancing the cursor up to where it was reading from the file in
general makes sense, but always resetting it to where it was before might
actually be counterintuitive.
The general expectation is (i suppose) that whenever i read something from
a file the cursor is advanced by that amount. FileLines is usually reading
more, buffering these contents.
It might be more reasonable to advance the cursor beyond the trailing
linebreak of the returned line? Any thoughts on this?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2707 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AA-hHGzDXeSDy0Gz3sGWkWgKogFgnyH6ks5uDROIgaJpZM4UJZX7>
.
|
Thanks @winksaville for your input. I think the same way. I would just like to ask @SeanTAllen for his, as he was around when the decision for the reimplementation of FileLines was made during a sync call (I remember what you did last summer!). Gonna change the logic accordingly. |
There seem to be a segfault when running the stdlib tests on armhf:
@dipinhora does that ring a bell to you? |
@mfelsche That output from qemu happens if there is a segfault. Without a backtrace there isn't much to go on to determine what might be occurring. If you think it might be a transient issue (since all the other |
Alrighty, all tests have passed. Thx @dipinhora ! @SeanTAllen or @jemc this is ready for review. |
@mfelsche due to the release of 0.24.1 and its related changes to the CHANGELOG file, please merge or rebase onto master and adjust your CHANGELOG entries into the appropriate area of "unreleased" in the CHANGELOG file. |
updated changelog and rebased. :) |
for use-cases where the Env from the TestHelper is needed to initialize state in a test, which is very hard to do in the constructor (e.g. for creating temporary directories)
Making it maintain its own cursor through the file for not disturbing other operations on the same file. Removed File.line as agreed upon in https://github.com/ponylang/ponyc/issues/2185\#issuecomment-329281827
to be exact it is advanced to after the linebreak
File.line
ponytest.UnitTest.set_up
method for initializing test state that needs aTestHelper
(i.e. for getting anEnv
)Fixes #2185