Understanding environments and projects

I have a few questions about environments and projects in julia’s package manager. I have read the documentation, so these questions are really about making sure I understand properly.

Q1. In .julia/environments lists all the environments that Julia sees. As of right now, I see a folder called v0.7 and v1.0, each with a Manifest.toml and Project.toml files. What this tells me is that in the default environment of v1.0, the Project.toml files tells me what packages are available for me to use. I can edit this file using add, up, rm from the package manager.

Q2. I also see a folder called .julia/packages. Here I see all the packages I’ve added previously (as well as their dependencies. In each package folder, there are subfolders each containing a full copy of the source. I assume these subfolders are packages at some state (given by the git hash). This makes perfect sense since different projects may depend on different versions of a package. Is my understanding correct? (There might be way more packages in this folder than in Project.toml… some of these are dependencies of the packages themselves, some of them do nothing and would be deleted once I run garbage collector, correct?)

It’s time to write my own package, so I do generate FooBar which will create a folder with a Manifest.toml and a Project.toml file, as well as a source folder with a barebones module. I can cd into this directory and type in activate . which changes my environment from default v1.0 to FooBar. Here lies my confusion.

Q3. I can add a dependency by saying add Example which adds the project at its latest release (in github). This edits the Project.toml file as well as downloads a copy to .julia/packages (it dosn’t redownload if it’s already there), correct?

Q4. However, why do I have to add? If I just type in using Example, it works… I am a little confused here. Since I never add the package, how can I run using Example? What version does it use? I suppose if I want to share my package with others, I should add first to force the end user to download the package… otherwise they may have the wrong version or might not even have the package at all.

Q5. Why dosn’t the .julia/environments update itself? I’ve added a new environment called FooBar (which is in some other directory) but I would like to have all my environments in one folder… I am not sure if this makes sense.

Q6. At no point did I ever run dev? What is the purpose of that? I am already “developing” my package so do I need to run dev?

Q7. What is the correct way to contribute to Julia/packages? Right now, my work flow is simply to git clone the project, stay in my v1.0 environment, download the packages I need, and submit PR if required. I’ve seen people using dev for an alternative workflow.

5 Likes

Q1: Yes
Q2: Yes
Q3: Yes
Q4: Environments are stacked, if you look at e.g. Base.load_path() after you activate your new package you see that there are multiple entries there. When you do using Example Julia finds it in the second entry in the stack – the default environment v1. However, since you have not added the Example package to the new environment you can not using Example from within that package itself.
Q5: Not sure what you mean, why would you want all projects in that folder? Instead you keep each toml-pair in your project folder.
Q6: dev is convenience for git clone url.to.pacakge && dev path/to/git-repo. For example, if you want to be able to using Foobar from your default environment you can add it to that environment by deving the path to your generated package.
Q7: Easiest is either to use dev as described above, or you can just manually git clone it and work within that package environment. You should never have to download any packages yourself though.

4 Likes