I’m having a hard time understanding how to “properly” lay out semi-shared code among a series of mini-projects, especially in the context of preparing for Julia v0.7/Pkg3. (I’m just starting the project, so with v0.7 imminent, I don’t want to lock myself in to the v0.6 way of doing things, even though I can’t actually use v0.7 consistently yet due to packages I need being not yet compatible.)
The basic idea is that I have one top-level directory which encompasses a whole project — the exploration of various research topics — for just me personally. There’s potential for some amount of code reuse — which I imagine are submodules of this directory — as well as serial-numbered/chronologically-ordered one-off scripts which drive through to some result. My imagined layout ends up looking something like:
Research.jl
├── PlotFuncs
│ └── src
│ └── PlotFuncs.jl
├── src
│ ├── Research.jl
│ └── paths.jl
├── ToyPixPixCov
│ └── src
│ ├── fft_tools.jl
│ ├── matrixpipe.jl
│ ├── ToyPixPixCov.jl
│ └── toysims.jl
├── S0001_proj_algorithms.ipynb
├── S0002_purif_params.ipynb
└── S0002_purif_params.jl
where there exist three modules — the top-level (generic) Research
and two sub-projects ToyPixPixCov
and PlotFuncs
— and the one-off scripts are each of the SXXXX
-prefixed *.jl
or *.ipynb
files.
Now to the problem. Say I try setting this up using Julia v0.7 + Pkg3, and include in one of the sub-modules a dependency on one of the other modules in this directory:
pkg> generate Research
┌ Info: Pkg3 is running without precompile statements, first action will be slow.
│ Rebuild julia with the environment variable `JULIA_PKG3_PRECOMPILE` set to enable precompilation of Pkg3.
└ This message can be disabled by setting the env variable `JULIA_PKG3_DISABLE_PRECOMPILE_WARNING`.
Generating project Research:
Research/Project.toml
Research/src/Research.jl
shell> cd Research
/tmp/Research
pkg> generate ToyPixPixCov
Generating project ToyPixPixCov:
ToyPixPixCov/Project.toml
ToyPixPixCov/src/ToyPixPixCov.jl
pkg> develop ToyPixPixCov
Resolving package versions...
Updating `Project.toml`
[9c9cea7e] + ToyPixPixCov v0.1.0 [`ToyPixPixCov`]
Updating `Manifest.toml`
[9c9cea7e] + ToyPixPixCov v0.1.0 [`ToyPixPixCov`]
pkg> generate PlotFuncs
Generating project PlotFuncs:
PlotFuncs/Project.toml
PlotFuncs/src/PlotFuncs.jl
shell> sed -i -e 's/^greet().*$/using ToyPixPixCov\nToyPixPixCov.greet()/g' PlotFuncs/src/PlotFuncs.jl
pkg> develop PlotFuncs
Resolving package versions...
Updating `Project.toml`
[b2d8554e] + PlotFuncs v0.1.0 [`PlotFuncs`]
Updating `Manifest.toml`
[b2d8554e] + PlotFuncs v0.1.0 [`PlotFuncs`]
Now trying to load the two modules, I can load ToyPixPixCov
since it relies on no other modules, but I get an error with PlotFuncs
saying it can’t find ToyPixPixCov
:
julia> using ToyPixPixCov
julia> using PlotFuncs
ERROR: LoadError: ArgumentError: Module ToyPixPixCov not found in current path.
Run `Pkg.add("ToyPixPixCov")` to install the ToyPixPixCov package.
Stacktrace:
[1] require(::Module, ::Symbol) at ./loading.jl:869
[2] include at ./boot.jl:306 [inlined]
[3] include_relative(::Module, ::String) at ./loading.jl:1072
[4] _require(::Base.PkgId) at ./loading.jl:998
[5] require(::Base.PkgId) at ./loading.jl:879
[6] require(::Module, ::Symbol) at ./loading.jl:874
in expression starting at /tmp/Research/PlotFuncs/src/PlotFuncs.jl:3
If I switch to Julia v0.6, I can get around most of this by just adding the current working directory to LOAD_PATH
:
julia> VERSION
v"0.6.2"
julia> push!(LOAD_PATH, pwd())
3-element Array{Any,1}:
"/usr/local/share/julia/site/v0.6"
"/usr/share/julia/site/v0.6"
"/tmp/Research"
julia> using ToyPixPixCov
julia> using PlotFuncs
Hello World!
julia>
(Of course, to load Resarch
on v0.6 I also need to do push!(LOAD_PATH, realpath(".."))
first, while that does just work on v0.7+Pkg3…)
I realize things are still very much in flux and a work in progress, but any guidance on how to accomplish this?