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

Deprecate readstring in favor of read(io, String) #22864

Merged
merged 14 commits into from
Jul 20, 2017

Conversation

jpfairbanks
Copy link
Contributor

Here is a a pull request for Deprecating readstring in favor of read(io, String) closes #22793.

@jpfairbanks
Copy link
Contributor Author

This looks like CI is failing outside of the main Base.runtests(). This PR should only affect Base so I don't know what is going on in the travis logs.

0.05s$ du -sk /tmp/julia/*
du: cannot access ‘/tmp/julia/*’: No such file or directory
The command "du -sk /tmp/julia/*" exited with 1.
0.01s$ if [ `uname` = "Darwin" ]; then for name in suitesparseconfig spqr umfpack colamd cholmod amd suitesparse_wrapper; do install -pm755 usr/lib/lib${name}*.dylib* /tmp/julia/lib/julia/; done; fi
The command "if [ `uname` = "Darwin" ]; then for name in suitesparseconfig spqr umfpack colamd cholmod amd suitesparse_wrapper; do install -pm755 usr/lib/lib${name}*.dylib* /tmp/julia/lib/julia/; done; fi" exited with 0.
0.01s$ cd .. && mv julia julia2
The command "cd .. && mv julia julia2" exited with 0.
0.01s$ /tmp/julia/bin/julia --precompiled=no -e 'true' && /tmp/julia/bin/julia-debug --precompiled=no -e 'true'
/home/travis/.travis/job_stages: line 57: /tmp/julia/bin/julia: No such file or directory
The command "/tmp/julia/bin/julia --precompiled=no -e 'true' && /tmp/julia/bin/julia-debug --precompiled=no -e 'true'" exited with 127.
0.01s$ /tmp/julia/bin/julia -e 'versioninfo()'
/home/travis/.travis/job_stages: line 57: /tmp/julia/bin/julia: No such file or directory

The text is assumed to be encoded in UTF-8.
"""
readstring(s::IO) = String(read(s))
readstring(filename::AbstractString) = open(readstring, filename)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is still relevant, isn't it? I didn't see it redefined elsewhere in the diff but maybe I missed it. In this case it'd just be

read(filename::AbstractString, ::Type{String}) = open(io -> read(io, String), filename)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I responded to this below

@jpfairbanks
Copy link
Contributor Author

base/io.jl L 167 https://github.com/JuliaLang/julia/pull/22864/files#diff-775ff60d66216b33269fc5fcb6be714fR167

read on a filename lifts that for you right?

"""
    read(filename::AbstractString, args...)

Open a file and read its contents. `args` is passed to `read`: this is equivalent to
`open(io->read(io, args...), filename)`.
"""
read(filename::AbstractString, args...) = open(io->read(io, args...), filename)

@ararslan
Copy link
Member

Oh yeah, you're right, it should indeed go through that method.

@ararslan ararslan changed the title Jpfairbanks/#22793 Deprecate readstring in favor of read(io, String) Jul 19, 2017
@ararslan ararslan added kind:deprecation This change introduces or involves a deprecation domain:io Involving the I/O subsystem: libuv, read, write, etc. domain:strings "Strings!" labels Jul 19, 2017
@jpfairbanks
Copy link
Contributor Author

The problem with the build had something to do with a ref in the manual it was failing the documentation build step.

@jpfairbanks
Copy link
Contributor Author

There is a problem finding references to code I didn't deprecate:
https://travis-ci.org/JuliaLang/julia/jobs/255254663#L1076
For example dropzeros!

@tkelman
Copy link
Contributor

tkelman commented Jul 19, 2017

yeah that's been happening in a few places. something is buggy, not sure what.

@jpfairbanks
Copy link
Contributor Author

Works on FreeBSD!
What do I do about the docs failures?


@deprecate readstring(s::IO) read(s, String)
@deprecate readstring(filename::String) read(filename, String)
@deprecate readstring(cmd::AbstractCmd) read(cmd, String)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps nix the extra empty line above these definitions and restore the empty line before # END ...?

base/iostream.jl Outdated
@@ -144,7 +144,7 @@ end
Apply the function `f` to the result of `open(args...)` and close the resulting file
descriptor upon completion.

**Example**: `open(readstring, "file.txt")`
**Example**: `open(f->read(f, String), "file.txt")`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tangentially, perhaps change this line to match the emerging convention for examples?

# Examples
```julia-repl
... [example] ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this?

"""
open(f::Function, args...)

Apply the function f to the result of open(args...) and close the resulting file
descriptor upon completion.

Examples

open(f->read(f, String), "file.txt")

"""

Copy link
Member

@Sacha0 Sacha0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

julia> print(longmeeting(longpr))
lgtm! :)

@@ -1581,6 +1581,10 @@ end

@deprecate String(io::GenericIOBuffer) String(take!(copy(io)))


@deprecate readstring(s::IO) read(s, String)
@deprecate readstring(filename::String) read(filename, String)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be tighter than the removed method, should be AbstractString?

readstring(stream::IO)
readstring(filename::AbstractString)

Read the entire contents of an I/O stream or a file as a string.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the new method's signature should be added to the read docstring

@tkelman
Copy link
Contributor

tkelman commented Jul 19, 2017

I see one more occurrence at examples/wordcount.jl:78: text *= readstring(file)

@jpfairbanks
Copy link
Contributor Author

All review comments are handled and the tests pass

@JeffBezanson JeffBezanson merged commit 876294d into JuliaLang:master Jul 20, 2017
@JeffBezanson
Copy link
Sponsor Member

Thanks for working on this, James.

Copy link
Member

@ararslan ararslan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, just two super minor things. You could put those in a separate commit with [ci skip] in the commit message, which will keep the CI builds from running again for two tiny doc changes.

@@ -144,7 +144,10 @@ end
Apply the function `f` to the result of `open(args...)` and close the resulting file
descriptor upon completion.

**Example**: `open(readstring, "file.txt")`
# Examples
```julia-repl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

julia-repl blocks are for things that look like REPL sessions, i.e. have julia> input lines and lines of output. Since this doesn't have a "prompt" in front of it, I think it should just be julia instead of julia-repl.


read(stream::IO, String)

Read the entirety of `stream`, as a String.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with the other docstring you added, I'd remove the comma and lowercase string. If you leave it uppercase as in the type, it should have code formatting.

@ararslan
Copy link
Member

Whoops. Too slow. Never mind. 😛 Nice work here!

jeffwong pushed a commit to jeffwong/julia that referenced this pull request Jul 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:io Involving the I/O subsystem: libuv, read, write, etc. domain:strings "Strings!" kind:deprecation This change introduces or involves a deprecation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

deprecate readstring to read(io, String)
6 participants