Skip to content

Commit 4c93073

Browse files
abhronhz2
andauthored
Documentation site update (#393)
* Rename make_docs.jl make_docs.jl only deals with the registry, so rename to populat_registry.jl * Use Documenter.jl v1 to build documentation site * Add method and type headers to docstrings * Add fence language tags * Remove REPL prompt from install instructions The code is more likely to be copy-pasted * Export info `info()` is listed in FileIO module docstring * Wrap lines * Add Downloads to test dependencies Base.download() is deprecated * Add markdown ref links to types and methods * Loosen Downloads compat for tests * Revert "Export info" This reverts commit 037496a. * Add docstring for info() to API reference page * Reformat docstring for stream() --------- Co-authored-by: Nathan Zimmerberg <[email protected]>
1 parent 97bdfc9 commit 4c93073

File tree

15 files changed

+131
-75
lines changed

15 files changed

+131
-75
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Aqua = "0.8"
1616
CSVFiles = "1"
1717
CodecZlib = "0.5, 0.6, 0.7"
1818
ColorTypes = "0.11"
19+
Downloads = "1.4"
1920
FilePathsBase = "0.9"
2021
HTTP = "0.6, 1"
2122
Random = "<0.0.1, 0.7, 1"
@@ -26,10 +27,11 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
2627
CSVFiles = "5d742f6a-9f54-50ce-8119-2520741973ca"
2728
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
2829
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
30+
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
2931
FilePathsBase = "48062228-2e41-5def-b9a4-89aafe57970f"
3032
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
3133
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
3234
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3335

3436
[targets]
35-
test = ["Aqua", "ColorTypes", "CodecZlib", "CSVFiles", "FilePathsBase", "HTTP", "Random", "Test"]
37+
test = ["Aqua", "ColorTypes", "CodecZlib", "CSVFiles", "Downloads", "FilePathsBase", "HTTP", "Random", "Test"]

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Documenter
22
using FileIO
33

4-
include("make_docs.jl")
4+
include("populate_registry.jl")
55

66
makedocs(
77
sitename = "FileIO",

docs/make_docs.jl renamed to docs/populate_registry.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fs = open(joinpath(pkgdir(FileIO), "docs", "src", "registry.md"), "w")
9090

9191
println(fs, """
9292
| Format Name | extensions | IO library | detection or magic number |
93-
| ----------- | ---------- | ---------- | ---------- |""")
93+
| ----------- | ---------- | ---------- | ------------------------- |""")
9494
include(joinpath(pkgdir(FileIO), "src", "registry.jl"))
9595

9696
close(fs)

docs/src/implementing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ closing any streams you opened in order to read or write the file. If you are
8787
given a `Stream`, your `close` method should only do the clean up for your
8888
reader or writer type, not close the stream.
8989

90-
```jl
90+
```julia
9191
struct WAVReader
9292
io::IO
9393
ownstream::Bool

docs/src/index.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ provide support for standard file formats through functions named
1313
Install FileIO within Julia via
1414

1515
```julia
16-
julia> using Pkg
17-
18-
julia> Pkg.add("FileIO")
16+
using Pkg
17+
Pkg.add("FileIO")
1918
```
2019

2120
## Usage

docs/src/reference.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
Modules = [FileIO]
55
Private = false
66
```
7+
```@docs
8+
FileIO.info
9+
```

docs/src/registering.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ You'll need to [`pkg> dev FileIO`](https://julialang.github.io/Pkg.jl/v1/managin
1414
Before going into detail explaining the arguments of `add_format`,
1515
here is a real example that could be used to register an I/O package for one of the [Netpbm image formats](https://en.wikipedia.org/wiki/Netpbm#File_formats):
1616

17-
```
17+
```julia
1818
add_format(format"PPMBinary", "P6", ".ppm", [:Netpbm => UUID("f09324ee-3d7c-5217-9330-fc30815ba969")])
1919
```
2020

docs/src/world_age_issue.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ thing related to image IO.
1313
To avoid such unnecessary loading latency, FileIO defers package loading until it's actually used.
1414
For instance, when you use FileIO, you'll probably observe something like this:
1515

16-
```julia
16+
```julia-repl
1717
julia> using TestImages, FileIO
1818
1919
julia> path = testimage("cameraman"; download_only=true)
@@ -38,20 +38,20 @@ after initial compilation finishes) than the one you called them from.
3838
Let's demonstrate the problem concretely. In case you don't have a suitable file to play with, let's
3939
first create one:
4040

41-
```julia
41+
```julia-repl
4242
julia> using IndirectArrays, ImageCore
4343
4444
julia> img = IndirectArray(rand(1:5, 4, 4), rand(RGB, 5))
4545
4×4 IndirectArray{RGB{Float64}, 2, Int64, Matrix{Int64}, Vector{RGB{Float64}}}:
46-
...
46+
[...]
4747
4848
julia> save("indexed_image.png", img)
4949
```
5050

5151
Now, **reopen a new julia REPL** (this is crucial for demonstrating the problem) and call `load`
5252
from **within a function** (this is also crucial):
5353

54-
```julia
54+
```julia-repl
5555
julia> using FileIO
5656
5757
julia> f() = size(load("indexed_image.png"))
@@ -95,7 +95,7 @@ which you called `f()`. This leads to the observed error.
9595

9696
The good news is it's easy to fix, just try calling `f()` again:
9797

98-
```julia
98+
```julia-repl
9999
julia> f()
100100
(4, 4)
101101
```
@@ -113,7 +113,7 @@ around this world-age dispatch problem. Literally, `invokelatest` dispatches the
113113
the latest world age (which may be newer than when you typed `f()` at the REPL). **In a fresh Julia
114114
session**,
115115

116-
```julia
116+
```julia-repl
117117
julia> using FileIO
118118
119119
julia> f() = Base.invokelatest(size, load("indexed_image.png"))
@@ -138,7 +138,7 @@ Another solution to the world age issue is simple and doesn't have long-term dow
138138
load the needed packages**. For instance, if you're seeing world age issue complaining methods
139139
related to `IndirectArray`, then load IndirectArrays eagerly:
140140

141-
```julia
141+
```julia-repl
142142
julia> using FileIO, IndirectArrays # try this on a new Julia REPL
143143
144144
julia> f() = size(load("indexed_image.png"))

src/FileIO.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,26 @@ include("registry.jl")
4141
`FileIO` API (brief summary, see individual functions for more detail):
4242
4343
- `format"PNG"`: specifies a particular defined format
44-
- `File{fmt}` and `Stream{fmt}`: types of objects that declare that a resource has a particular format `fmt`
44+
- [`File{fmt}`](@ref) and [`Stream{fmt}`](@ref): types of objects that declare that a resource has a particular format `fmt`
4545
46-
- `load([filename|stream])`: read data in formatted file, inferring the format
46+
- [`load([filename|stream])`](@ref): read data in formatted file, inferring the format
4747
- `load(File{format"PNG"}(filename))`: specify the format manually
48-
- `loadstreaming([filename|stream])`: similar to `load`, except that it returns an object that can be read from
49-
- `save(filename, data...)` for similar operations involving saving data
50-
- `savestreaming([filename|stream])`: similar to `save`, except that it returns an object that can be written to
48+
- [`loadstreaming([filename|stream])`](@ref): similar to `load`, except that it returns an object that can be read from
49+
- [`save(filename, data...)`](@ref) for similar operations involving saving data
50+
- [`savestreaming([filename|stream])`](@ref): similar to `save`, except that it returns an object that can be written to
5151
5252
- `io = open(f::File, args...)` opens a file
53-
- `io = stream(s::Stream)` returns the IOStream from the query object `s`
53+
- [`io = stream(s::Stream)`](@ref stream) returns the IOStream from the query object `s`
5454
55-
- `query([filename|stream])`: attempt to infer the format of `filename`
56-
- `unknown(q)` returns true if a query can't be resolved
57-
- `skipmagic(io, fmt)` sets the position of `io` to just after the magic bytes
58-
- `magic(fmt)` returns the magic bytes for format `fmt`
59-
- `info(fmt)` returns `(magic, extensions)` for format `fmt`
55+
- [`query([filename|stream])`](@ref): attempt to infer the format of `filename`
56+
- [`unknown(q)`](@ref) returns true if a query can't be resolved
57+
- [`skipmagic(io, fmt)`](@ref) sets the position of `io` to just after the magic bytes
58+
- [`magic(fmt)`](@ref) returns the magic bytes for format `fmt`
59+
- [`info(fmt)`](@ref) returns `(magic, extensions)` for format `fmt`
6060
61-
- `add_format(fmt, magic, extension, libraries...)`: register a new format
62-
- `add_loader(fmt, :Package)`: indicate that `Package` supports loading files of type `fmt`
63-
- `add_saver(fmt, :Package)`: indicate that `Package` supports saving files of type `fmt`
61+
- [`add_format(fmt, magic, extension, libraries...)`](@ref): register a new format
62+
- [`add_loader(fmt, :Package)`](@ref): indicate that `Package` supports loading files of type `fmt`
63+
- [`add_saver(fmt, :Package)`](@ref): indicate that `Package` supports saving files of type `fmt`
6464
"""
6565
FileIO
6666

src/error_handling.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
"""
2+
LoaderError <: Exception
3+
24
`LoaderError` should be thrown when loader library code fails, and other libraries should
35
be given the chance to recover from the error. Reports the library name and an error message:
6+
```julia
47
LoaderError("ImageMagick", "Foo not available")
8+
```
59
"""
610
struct LoaderError <: Exception
711
library::String
@@ -12,9 +16,13 @@ Base.showerror(io::IO, e::LoaderError) = println(IOContext(io, :limit=>true), e.
1216
e.msg, "\n due to ", e.ex, "\n Will try next loader.")
1317

1418
"""
19+
WriterError <: Exception
20+
1521
`WriterError` should be thrown when writer library code fails, and other libraries should
1622
be given the chance to recover from the error. Reports the library name and an error message:
23+
```julia
1724
WriterError("ImageMagick", "Foo not available")
25+
```
1826
"""
1927
struct WriterError <: Exception
2028
library::String
@@ -34,6 +42,8 @@ end
3442
Base.showerror(io::IO, e::SpecError) = print(io, e.mod, " is missing $(e.call) and fileio_$(e.call)")
3543

3644
"""
45+
handle_exceptions(exceptions::Vector, action)
46+
3747
Handles a list of thrown errors after no IO library was found working
3848
"""
3949
function handle_exceptions(exceptions::Vector, action)

0 commit comments

Comments
 (0)