|
| 1 | +# Developing |
| 2 | + |
| 3 | +This guide contains information important when developing FastAI.jl. Concretely: |
| 4 | + |
| 5 | +- how to set up a local development environment |
| 6 | +- how to run the tests |
| 7 | +- how to preview the documentation locally |
| 8 | + |
| 9 | +## Setting up FastAI.jl locally for development |
| 10 | + |
| 11 | +**Fork FastAI.jl and add it as a `dev` dependency.** You can fork it from [the GitHub repository](https://github.com/FluxML/FastAI.jl). Then use `Pkg` to add the fork to your Julia environment: |
| 12 | + |
| 13 | +```julia |
| 14 | +using Pkg |
| 15 | +Pkg.develop(url="https://github.com/<myusername>/FastAI.jl.git") |
| 16 | +``` |
| 17 | + |
| 18 | +You should now be able to import FastAI (`using FastAI`) in Julia. If you are using [Revise.jl](https://github.com/timholy/Revise.jl), any changes you make to its source code will also be reflected in your interactive sessions. |
| 19 | + |
| 20 | + |
| 21 | +## Running the tests |
| 22 | + |
| 23 | +Like any Julia package, you can run the entire test suite in an isolated environment using `Pkg.test`: |
| 24 | + |
| 25 | +```julia |
| 26 | +using Pkg |
| 27 | +Pkg.test("FastAI") |
| 28 | +``` |
| 29 | + |
| 30 | +When developing, however, it can be helpful to repeatedly rerun parts of the tests. FastAI.jl uses [ReTest.jl](https://github.com/JuliaTesting/ReTest.jl) to set up tests which makes it possible to run subsets of tests or only tests that have not previously succeeded. |
| 31 | + |
| 32 | +First, activate the test environment and install its dependencies: |
| 33 | + |
| 34 | +```julia |
| 35 | +using Pkg |
| 36 | +Pkg.activate(joinpath(Pkg.devdir(), "FastAI", "test")) |
| 37 | +Pkg.instantiate() |
| 38 | +``` |
| 39 | + |
| 40 | +Then, you can run the test suite or subsets of it: |
| 41 | + |
| 42 | +```julia |
| 43 | +using FastAI, ReTest |
| 44 | + |
| 45 | +FastAI.runtests() # full test suite |
| 46 | +FastAI.runtests("block") # all tests containing `"block"` |
| 47 | +FastAI.runtests([ReTest.fail, ReTest.not(ReTest.pass)]) # run only tests that have not been run or have failed previously |
| 48 | + |
| 49 | +``` |
| 50 | + |
| 51 | + |
| 52 | +## Local documentation preview |
| 53 | + |
| 54 | +FastAI.jl uses [Pollen.jl](https://github.com/lorenzoh/Pollen.jl) as its documentation system, which allows you to preview documentation locally. |
| 55 | + |
| 56 | +First, activate the documentation environment and install its dependencies: |
| 57 | + |
| 58 | +```julia |
| 59 | +using Pkg |
| 60 | +Pkg.activate(joinpath(Pkg.devdir(), "FastAI", "docs")) |
| 61 | +Pkg.add([ |
| 62 | + Pkg.PackageSpec(url="https://github.com/c42f/JuliaSyntax.jl"), |
| 63 | + Pkg.PackageSpec(url="https://github.com/lorenzoh/ModuleInfo.jl"), |
| 64 | + Pkg.PackageSpec(url="https://github.com/lorenzoh/Pollen.jl", rev="main"), |
| 65 | +]) |
| 66 | +``` |
| 67 | + |
| 68 | +Now you can build the documentation locally, giving you a preview at [http://localhost:3000](http://localhost:3000). Using the `lazy = true` will build pages lazily only once you request them on the website, which reduces the build time when you only care about specific pages. |
| 69 | + |
| 70 | + |
| 71 | +```julia |
| 72 | +using FastAI, Pollen |
| 73 | +Pollen.servedocs(@__MODULE__, FastAI, lazy = true) |
| 74 | +``` |
| 75 | + |
| 76 | +### Adding documentation pages files |
| 77 | + |
| 78 | +Documentation pages correspond to a Markdown `.md` or Jupyter Notebook `.ipynb` file that should be stored in the `docs/` folder. If a document should show up in the left sidebar of the docs page, add an entry to `FastAI/docs/toc.json`. |
| 79 | + |
| 80 | +- Jupyter Notebooks should be used when they use resources that are not available on the GitHub CI, like a GPU needed for training. You should run them locally and the outputs will be captured and inserted into the HTML page. |
| 81 | +- Markdown documents should be preferred for everything else, as they allow the code examples to be run on the GitHub CI, meaning they'll stay up-to-date unlike a notebook that has to be manually rerun. |
| 82 | + |
| 83 | +Both formats support the [Markdown syntax of Publish.jl](https://michaelhatherly.github.io/Publish.jl/dev/docs/syntax.html) and in markdown files the [cell syntax of Publish.jl](https://michaelhatherly.github.io/Publish.jl/dev/docs/cells.html) can be used to mark code cells. These will be run and the output is inserted into the HTML page. |
| 84 | + |
| 85 | +### Linking to documentation |
| 86 | + |
| 87 | +For a new documentation file to be discoverable, you have to add an entry to the nested Markdown list in `toc.md`, which corresponds to the sidebar in the documentation _(updating the sidebar currently requires interrupting and reincluding the file that starts the development server)_. |
| 88 | + |
| 89 | +Documentation pages can also link to each other using standard Markdown link syntax. |
| 90 | + |
| 91 | +### Referencing code symbols |
| 92 | + |
| 93 | +Symbols like `fitonecycle!` can be referenced by using the cross-referencing syntax ```[`fitonecycle!`](#) ``` which will link to and create a reference page from the symbol's docstrings. It will also be added as an entry on the references page. |
0 commit comments