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

Loosen filename type constraints #259

Merged
merged 4 commits into from
May 1, 2020
Merged

Conversation

rofinn
Copy link
Contributor

@rofinn rofinn commented Apr 29, 2020

Maintains the same public API (e.g., type constraints on methods remains the same),
but allows FilePaths.jl to extend the public methods to work with AbstractPaths.
This seemed preferable to depending directly on FilePathsBase or loosening the type constraints on all methods.

Loosen the restriction that filenames must be strings which will allow any AbstractPath to also work with FileIO. This approach doesn't require an explicit dependency, but I've added it as a test dependency to help ensure that load, save, query, etc work with the base AbstractPath types.

Partially addresses #219 with support from extended methods in FilePaths.jl. Also, closes rofinn/FilePaths.jl#34.

Maintains the same public API (e.g., type constraints on methods remains the same),
but allows FilePaths.jl to extend the public methods to work with `AbstractPath`s.
This seemed preferable to depending directly on FilePathsBase or loosening the type constraints on all methods.
@rofinn rofinn marked this pull request as draft April 29, 2020 16:03
@codecov
Copy link

codecov bot commented Apr 29, 2020

Codecov Report

Merging #259 into master will decrease coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #259      +/-   ##
==========================================
- Coverage   76.08%   76.02%   -0.06%     
==========================================
  Files           8        8              
  Lines         414      413       -1     
==========================================
- Hits          315      314       -1     
  Misses         99       99              
Impacted Files Coverage Δ
src/query.jl 86.84% <ø> (+1.12%) ⬆️
src/loadsave.jl 85.91% <100.00%> (ø)
src/types.jl 63.15% <100.00%> (-2.64%) ⬇️
src/registry.jl 92.64% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0423143...26c9484. Read the comment docs.

@rofinn rofinn changed the title WIP: Loosen File and Stream filename type constraints WIP: Loosen filename type constraints Apr 29, 2020
@rofinn rofinn changed the title WIP: Loosen filename type constraints Loosen filename type constraints Apr 29, 2020
@rofinn rofinn marked this pull request as ready for review April 29, 2020 17:22
Project.toml Show resolved Hide resolved
src/loadsave.jl Outdated Show resolved Hide resolved
src/types.jl Show resolved Hide resolved
test/runtests.jl Outdated Show resolved Hide resolved
test/query.jl Outdated Show resolved Hide resolved
@omus
Copy link
Member

omus commented Apr 29, 2020

I'll just mention this PR is easier to review with: https://github.com/JuliaIO/FileIO.jl/pull/259/files?w=1

@rofinn
Copy link
Contributor Author

rofinn commented Apr 29, 2020

Coverage says types.jl#31 isn't being hit anymore, but it should still be getting called by loadsave.jl#128 :/

Copy link
Member

@timholy timholy left a comment

Choose a reason for hiding this comment

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

Nice!

Coverage says types.jl#31 isn't being hit anymore, but it should still be getting called by loadsave.jl#128 :/

Probably a coverage-analysis bug. You could try locally "breaking" that method with a deliberate error and see if the error gets thrown.

src/types.jl Show resolved Hide resolved
@rofinn
Copy link
Contributor Author

rofinn commented Apr 30, 2020

Okay, yep, that constructor is definitely being hit by the tests cause switching it to an error breaks the tests.

@rofinn
Copy link
Contributor Author

rofinn commented May 1, 2020

Are there any other concerns or is this safe to merge and tag?

src/loadsave.jl Outdated Show resolved Hide resolved
src/loadsave.jl Outdated Show resolved Hide resolved
@omus
Copy link
Member

omus commented May 1, 2020

I think the only thing left to do is a minor version bump

@omus omus merged commit 882dc75 into JuliaIO:master May 1, 2020
@omus
Copy link
Member

omus commented May 1, 2020

I'll just mention I did "Squash and merge" and GitHub flashed an error message and then just did a merge. Oh well ¯\_(ツ)_/¯

@timholy
Copy link
Member

timholy commented Dec 31, 2020

For some reason this passes when run with Pkg.test but fails if you run it locally, with

Load PosixPath: Error During Test at /home/tim/.julia/dev/FileIO/test/loadsave.jl:36
  Test threw exception
  Expression: load(joinpath(fp, "file1.pbm")) == "PBMText"
  MethodError: no method matching splitext(::PosixPath)
  Closest candidates are:
    splitext(::String) at path.jl:201
    splitext(::AbstractString) at path.jl:528
  Stacktrace:
   [1] query(filename::PosixPath; checkfile::Bool)
     @ FileIO ~/.julia/dev/FileIO/src/query.jl:74
   [2] query(filename::PosixPath)
     @ FileIO ~/.julia/dev/FileIO/src/query.jl:73
   [3] load(::PosixPath; options::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
     @ FileIO ~/.julia/dev/FileIO/src/loadsave.jl:137
   [4] load(::PosixPath)
     @ FileIO ~/.julia/dev/FileIO/src/loadsave.jl:137
   [5] macro expansion
     @ ~/.julia/dev/FileIO/test/loadsave.jl:36 [inlined]
   [6] macro expansion
     @ ~/src/julia-master/usr/share/julia/stdlib/v1.6/Test/src/Test.jl:1222 [inlined]
   [7] top-level scope
     @ ~/.julia/dev/FileIO/test/loadsave.jl:27

Can splitext support be added for PosixPath?

EDIT: nevermind, it's a Pkg-hold-back issue (AWSTools and Bonsai are holding it back, the first indirectly via BugReporting).

timholy added a commit to JuliaLang/BugReporting.jl that referenced this pull request Dec 31, 2020
This is holding back FilePathsBase, which is causing JuliaIO/FileIO.jl#259 (comment).

If this works, it would be good to get a new release.
timholy added a commit that referenced this pull request Dec 31, 2020
After #259, the result of `filename(q)` is not inferrable.
This uses "the kernel trick" to provide a single point where the result
must be inferred, and an `invokelatest` to prevent the abstract signature
from being inferred. It then precompiles the `::String` variant.
Consequently, with respect to latency this should get us back to where
we were before #259.
@timholy timholy mentioned this pull request Dec 31, 2020
Keno pushed a commit to JuliaLang/BugReporting.jl that referenced this pull request Jan 2, 2021
This is holding back FilePathsBase, which is causing JuliaIO/FileIO.jl#259 (comment).

If this works, it would be good to get a new release.
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.

Enhancement: save and load methods for AbstractPaths
3 participants