I’m happy to see that the documentation in the 0.7 manual for the new package manager is greatly expanded, but it’s still a bit thin in describing how to develop applications (as opposed to packages). I’d like to develop my application using the package manager, but I’m not sure how.
Following the instructions in the manual about application development, I executed activate . in Pkg mode of the REPL in a new, empty directory, followed by add for packages needed by my application. What’s next? Should I create a subdirectory called src and place my .jl files in it? I did that. For example, suppose that the entry point to my application is a no-argument function run() in a module called app in a file called app.jl in the src subdirectory. How do I execute my application so that (1) the loader knows to look for source files in that directory and (2) the correct packages that were added with the add command are available when the application starts?
Also, is Revise.jl the recommended way to keep the REPL up-to-date with edits made to the source files during development?
I have a trace below showing the output of st. There is one other feature to note about this trace that I don’t understand. After the activate command, the system variable LOAD_PATH is unaffected, but the unexported function Base.load_path() has changed.
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.0.0 (2018-08-08)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
(v1.0) pkg> activate .
(TestApp) pkg> add Revise
Resolving package versions...
(TestApp) pkg> st
[295af30f] Revise v0.6.4
julia> import TestApp
ERROR: ArgumentError: Package TestApp not found in current path:
- Run `Pkg.add("TestApp")` to install the TestApp package.
 require(::Module, ::Symbol) at .\loading.jl:817
OK, I got this to work! The missing step was to cobble together my own Project.toml file. I copied the example out of the Julia manual, changing the name from HelloWorld to TestApp, changing a random digit in the UUID (so as not to collide with a possibly already existing UUID), and putting my own email address. Then I executed activate ., and now import TestApp works as expected. The next step is to try this with my real application.
I just want to pipe in to say I am also confused/unsatisfied with the documentation on how to use to “project environments” and Pkg3 for application development.
My use case is both simple and typical. I want to release code along with a scientific paper, and I want that code to have a easy way for the user to install the project dependencies. In python it is simple (and hacky):
I create a virtual environment and install all dependencies in it (git ignored).
I create/include a “requirements.txt” file via pip freeze in the repository
The user clones my code, creates a virtual environment, and points pip to the requirements file, installing the dependencies. (I can even give them a shell script that does all this for them).
My source code can now be run in the correct python environment by either:
a) activating the virtual environment before calling the python scripts, or
b) specifying the python binary which should be used, e.g., venv/bin/python src/mycode.py
Both 4a and 4b are useful: a) when the user wants to run my code in a REPL, add new packages, edit things, etc., and b) when I want to include a shell script (e.g. run.sh) that calls python (and the dependencies I specified).
Can someone clarify how I do this in Julia 0.7.0 / 1.0.0? Preferably going over the Julia equivalent of each step I mentioned? I seem to have found a cumbersome way of achieving 4a, but 4b is still eluding me.
In the project directory (e.g. MyApp ) run ] activate . , then add any dependencies via (MyApp) pkg> add SomeDep .
Include the Project.toml and optionally the Manifest.toml in the repository (these live in the root of the project dir).
The user clones my code, then either runs ] activate . and (MyApp) pkg> instantiate , OR julia --project -e "import Pkg; Pkg.instantiate()" (where the latter can be put into a setup script).
a & b) the user / shell script simply adds the --project command line option when calling Julia.
Is this the best practice for my use case?
If so, what I was missing (and what is missing in the docs) is the --project option. Note it doesn’t even show up with julia --help . (I’m on Version 0.7.0 (2018-08-08 06:46 UTC) x86_64-apple-darwin14.5.0)
Hmm, will that work…? I’m not sure. That seems like the best way to proceed if the project is structured as a Julia package.
My use case falls under what the Pkg docs consider an application. I’m releasing a repository that simply showcases my experiments, scripts etc. I’m not releasing reusable code (in the sense of a package), but rather I’m showing how I’ve used a bunch of existing packages to create the experimental results I’ve published. Giving the user a platform to continue experimenting.