Custom location for ad-hoc package (code)


#1

Is it possible to place a temporary ad-hoc package at an individually choosen location, say ~/code/julia/MyPkg.jl ? The idea is, to gather some initial code in a ‘package-like’ form but - as it is quite temporary/unfinished - to separate it from the real packages.

From the manual (and tests) I suppose that ‘MyPkg.jl’ can only be placed under ~/.julia/v0.5 (or a custom JULIA_PKGDIR location which then is true for all packages).

Is this correct? (Side question: will this be possible with Pkg3?)
Thank you!


#2

You can use LOAD_PATH

For example,
push!(LOAD_PATH, "~/code/Julia")

and this can be put into your .juliarc.jl so it loads when Julia starts.


#3

LOAD_PATH works well with e.g. using MyPkg. However my - not mentioned - aim was to generate documentation:

using Documenter
Documenter.generate("MyPkg")

and here I still get an error (Unable to find package…). - Now looking at Documenter.jl:646 I see that Pkg.dir is being used and thus iiuc I’m back to ~/.julia/v0.5 as the only possibility.


#4

Modifying LOAD_PATH won’t help with that. See the docs for generate for how to do it:

help?> Documenter.generate
  generate(pkgname; dir)
  
  Creates a documentation stub for a package called pkgname. The location of the
  documentation is assumed to be <package directory>/docs, but this can be
  overriden with the keyword argument dir.

So you’ll need to specify the dir you’d like to use:

julia> Documenter.generate("MyPackage", dir = "<directory name>/docs")

Note that the /docs directory is created by generate; you’ll get an error if it already exists.


#5

Now it’s working fine :slight_smile:

I tried with a dir argument before but missed that it is a keyword argument and 'dir = ’ is required. ‘LOAD_PATH’ is also helpful for ‘using MyPkg’.


#6

Could you clarify why want to use another directory? Afaics i’m doing package development inside .julia/v0.5 (even without have a remote on github or similar) and apart from some complaints from Pkg.update had no real problems to solve. A package is just a git repository in place.


#7

For me ‘.julia’ screams hidden. And it’s where the standard julia package universe resides: Gallium, StaticArrays, RCall, Cxx, Documenter, PyPlot, … If technically necessary I would put my (ad-hoc) packages in there too, but if I have the choice I think they don’t belong there. (And where to put, under v0.4, v0.5 or v0.6)?

[Don’t know about Pkg.update complaints, for me this command is sometimes quite lengthy (homebrew) and I kind of avoid updating if not necessary].

The idea is to organize my own, ad-hoc or developing code, in projects having packages, e.g. ~/code/prj1/MyPkg1.jl, ~/code/pr1/MyPkg2.jl and ~/code/prj2 … The ‘packages’ are just a folder to organize relating code. While not (yet) proper packages, I still sometimes like to use the standard naming, testing and documenting conventions. Sometimes MyPkg1.jl is a git repository, but sometimes, for simplicity, the enclosing folder, prj1 is the repository.

This said, atm I just wait until Pkg3 comes and will then adapt to ‘the rules’.


#8

not only for you. Many of my text editors don’t show hidden files/dirs in file selector dialogs, so i needed to add execeptions. I still find .julia a poor choice for putting packages and code. For config or package information it might be matching. But i guess someone very early in the project found it a good idea and it was never discussed in a larger group. But again, it’s just ‘a’ directory that hold all packages.


#9

Another simple way is to just symlink your package to .julia from whatever path you want to keep it at. It will from julias point of view look like a normally installed package.