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

Make file operations return the path they created #27071

Merged
merged 6 commits into from
May 18, 2018

Conversation

oxinabox
Copy link
Contributor

@oxinabox oxinabox commented May 11, 2018

This makes:

  • mv
  • touch
  • cp
  • mkdir
  • mkpath
  • chown
  • chmod

return the path they created/modified, rather than nothing.

It isn't a big change,
but it means you can do things like:

logfile = joinpath(mkpath(string(now())), "logfile.txt")

rather than

logdir =string(now())
mkpath(logdir)
logfile = joinpath(logdirs, "logfile.txt")

@oxinabox
Copy link
Contributor Author

CI errors are because I changed chown and chmod.
Which I thought better of, then forgot to revert.
And for some reason chown has a test that asserts it outputs nothing

@oxinabox
Copy link
Contributor Author

oxinabox commented May 11, 2018

AppVeyor failure is just it being a bit flacky AFAICT

@JeffBezanson
Copy link
Sponsor Member

+1. Always good to return a value if there's any possible useful value to return.

@@ -673,5 +680,4 @@ is `-1` the corresponding ID will not change. Only integer `owner`s and `group`s
function chown(path::AbstractString, owner::Integer, group::Integer=-1)
err = ccall(:jl_fs_chown, Int32, (Cstring, Cint, Cint), path, owner, group)
uv_error("chown",err)
nothing
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Maybe chmod and chown should return the path too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@JeffBezanson JeffBezanson added the status:triage This should be discussed on a triage call label May 13, 2018
base/file.jl Outdated
@@ -658,6 +658,7 @@ end
Change the permissions mode of `path` to `mode`. Only integer `mode`s (e.g. `0o777`) are
currently supported. If `recursive=true` and the path is a directory all permissions in
that directory will be recursively changed.
Returns `path`.
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Returns -> Return I think.

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 think Returns, as in "This function returns path"

Overly complicated explanation for why:
It is a sentence incorporating ellipsis. which is short for "This function returns path"
Returns is the verb in 3rd person present tense (I had to look that up).

Copy link
Member

Choose a reason for hiding this comment

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

We usually use imperative form though, from point 2 in the manual (https://docs.julialang.org/en/latest/manual/documentation/):

The one-line sentence should use the imperative form ("Do this", "Return that") instead of the third person (do not write "Returns the length...") when documenting functions.

Copy link
Contributor Author

@oxinabox oxinabox May 14, 2018

Choose a reason for hiding this comment

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

Fair enough, amazing and excellent that the manual is that specific

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

However, from searching a bit in the doc strings, we are very inconsistent regarding this.

Copy link
Contributor

Choose a reason for hiding this comment

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

The imperative mode guideline was introduced in #15136, among several other guidelines, by @nalimilan. However, I can't seem to find discussion of that particular aspect in the PR. Was it discussed elsewhere, e.g. on discourse or slack?

(FWIW, I do agree with @KristofferC that indicative mode sounds more natural, as neither the author nor the reader of the documentation will be the actor performing the returning action... but I may be missing something.)

Copy link
Member

Choose a reason for hiding this comment

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

I don't remember where that rule comes from, but I don't think I invented it. It's a know problem that our docs are inconsistent, and I don't really care about which convention is chosen as long as one exists.

Copy link
Contributor

@waldyrious waldyrious May 14, 2018

Choose a reason for hiding this comment

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

I do know of that convention/recommendation for git commits, but not for function documentation. I do think it makes more sense in the former context than the latter, but don't meant to discuss this here. Should I open an issue for that, or is everyone else ok with the current convention?

Copy link
Member

Choose a reason for hiding this comment

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

Note that the cited rule applies to the one-line sentence in the following sense:

Include a single one-line sentence describing what the function does or what the object represents after the simplified signature block. If needed, provide more details in a second paragraph, after a blank line

So no need to discuss the rule here, because it doesn't apply.

@oxinabox
Copy link
Contributor Author

oxinabox commented May 14, 2018

Should rm also return the path that was deleted?
I feel like returning a path to something that no longer exists isn't vary useful.

More useful behavours for rm's return, eg it could return true if something was actually removed,
and false if it was called with force=true and nothing was deleted.
But that would be a different PR

@oxinabox
Copy link
Contributor Author

AppVeyor is, afaict failing to get correct status.
It got jammed and @fredrikekre restarted it.

The restarted results are: https://ci.appveyor.com/project/JuliaLang/julia/build/1.0.26765
Which also reads as a failure,
but looking at the results it is fine: https://ci.appveyor.com/project/JuliaLang/julia/build/1.0.26765/job/3x8dn282hs4f2pn2#L3038

It finished all tests and they passed, but then it timed out before it could finish the job

@Keno Keno removed the status:triage This should be discussed on a triage call label May 17, 2018
@StefanKarpinski StefanKarpinski merged commit b5c0cb0 into JuliaLang:master May 18, 2018
haampie pushed a commit to haampie/julia that referenced this pull request May 18, 2018
oxinabox added a commit to oxinabox/julia that referenced this pull request Jun 1, 2018
fredrikekre pushed a commit that referenced this pull request Jun 1, 2018
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.

9 participants