Remove ‘Path.IO’, switch to ‘path-io’ package#1720
Remove ‘Path.IO’, switch to ‘path-io’ package#1720mgsloan merged 1 commit intocommercialhaskell:masterfrom
Conversation
0da5e8b to
ec7dce3
Compare
|
I rebased on current master and fixed some stuff so GHC 7.8 should be happy now. However for some reason it failed to install |
255b9ef to
35613bd
Compare
|
@mrkkrp: To fix the Travis build with Regarding the Travis build with OSX build I'm not sure what's wrong. |
|
That's quite a bunch of work, @mrkkrp! I really look forward to using Regarding the replacement for There are two more things that I feel could be more "ergonomic":
|
|
Great ideas, I will address all these things in |
|
I've added |
e4570e7 to
2dee9ab
Compare
2dee9ab to
46a7c46
Compare
I think that if you provide functions with similar names and similar types as existing functions in IMO, by using For I also think that we should move this discussion to |
|
The only difference now that temporary directory should exist or
All in all, everything should work now. Good, it passed all checks this time. |
|
Ping (?) Can someone review it and tell me what to fix or merge it? |
|
@mrkkrp Looks good to me, thanks for working on this! I'm going to go ahead and merge to avoid future merge conflicts. I do have the following thoughts:
|
Remove ‘Path.IO’, switch to ‘path-io’ package
|
I don't feel too strongly about the naming, though. Feel free to address these tweaks in another PR. |
|
@mgsloan, I have to admit that The only reason to have I don't know if changing the API is a good idea now, it seems like people are beginning to use the package. |
Ohh, I actually didn't consider that |
|
@mrkkrp Also, we've added you to the stack repository! Feel free to make changes you're confident in directly to the repo. So, for example, if path-io's API changes, it'd be quite fine to push a refactoring to stack. |
|
@mgsloan, Thank you! |
For previous discussion, please see #1701.
This PR eliminates Stack's ad-hoc
Path.IOmodule and replaces it withpath-iopackage. The package provides well-typed interface todirectoryandtemporaryplus commonly useful functions like recursive copying of directories. IOW, everything that a user ofpathmay need.With respect to function names,
path-iopreserves names fromdirectoryandtemporary, so it's easier for newcomers to get started (one difference is that “directory” is replaced with “dir” like everywhere inpath). Stack'sPath.IOon the other hand introduces its own terminology for some actions, so we have different names for the same things inpath-ioand Stack'sPath.IO.Most of the time there is direct correspondence, so simple renaming is enough, but sometimes there is subtle semantic differences, which I'll address shortly to make reviewing easier.
This may look like a massive PR, but is not. We have several recurring patterns that the code base that are just (almost mechanically) replaced with alternative solutions. Here, I list all those patters and explain some subtle moments and why new functions are equivalent (I don't want Stack users to blame me for breaking the tool, after all, so I've approached this with all my care):
createTree→createDirIfMissing True†listDirectory→listDir†fileExists→doesFileExist†dirExists→doesDirExist†removeFileIfExists→forgivingAbsence' . removeFile.forgivingAbsence'is a general way to ignoredoesNotExistErrorTypeexceptions. Other exceptions propagate (we don't want to silence something unexpected and important). Instead of creating a bunch of functions withIfExistssuffix, I decided to make a higher-level helper.withCanonicalizedSystemTempDirectory→withSystemTempDir. Difference here is that the former function canonicalizes argument of callback, while the replacement just usesparseAbsDir. System temp directory is alwaysPath Abs Dir, so the argument should be already in correct normal form, unlessdirectoryis broken, so additional canonicalization is not necessary or will not make difference anyway.resolveFileMaybe→forgivingAbsence . resolveFile.forgivingAbsencereturnsNothingif its argument throwsdoesNotExistErrorType, whileresolveFileMaybefirst checks “manually” whether file exists. I think the new approach is better in a way. The same applies toresolveDirMaybe.removeTree→removeDirRecur† Sometimes with above-mentionedforgivingAbsencewrapper that corresponds toremoveTreeIfExists.copyDirectoryRecursive→copyDirRecur. Almost the same. The latter tries to preserve permissions where possible, while the former does not care.getAppUserDataDiris now wrapped, so there is no point in marshalling types to call it.getWorkingDir→getCurrentDir†parseRelAsAbsDir→resolveDir'(and the same for files). Effectively the same, although code looks a bit different.† — means that these things are just the same on the source code level.
Somewhere I removed
MonadThrow mconstraint when it already hadMonadCatch m, because the former is super class of the latter.Finally, please note that I've put
path-io-0.3.0in extra-deps for now. As soon as Stackage builds it, you can fix this.Reference for reviewer (I hope docs will be there by the time you start reviewing this): https://hackage.haskell.org/package/path-io