Julia: How to set the package Dev path? - julia

I often ]dev Pkg but I want the devved packaged to be stored somewhere other than the default location for convenient access.
I don't want to change the path of the ]add Pkg. This seems to be controlled by the environment parameter DEPOT_PATH.
Is there a way to change only the path for dev Pkg, i.e. the path in which the dev package is stored?

You can set the environment variable JULIA_PKG_DEVDIR to change where development packages are installed. See the develop docs for more info.
As #crstnbr noted, an alternative is to use the --local option to the pkg> dev command to install a development version of the package in a dev directory within the current project. This could make sense if you're developing your own package MyCode.jl which relies on Example.jl and you need to make a hot fix to Example.jl. Then your Pkg REPL command would look like this:
(MyCode) pkg> dev --local Example
If you would like to make changes to a third-party package and submit those changes as a pull request on Github, there are a few more steps in the process. See this Discourse thread for more details on that process.

Not quite what you're asking for but you can of course always git clone the package to a path of your choice and then dev path/to/the/local/clone/of/the/pkg.
You can even do this from within julia:
using Pkg
Pkg.GitTools.clone("<pkg url>", "<local path>")
Pkg.develop(PackageSpec(path="<local path>"))

Related

How do I add a local project to the import path in Julia?

I want to be able to import or using a package that I'm writing in a directory ~/projects/ExamplePkg from my main Julia REPL / from another project or environment.
By ]foo I mean "use the foo command at the Julia Pkg REPL". Type ] at the Julia REPL to enter the Pkg REPL. Use ]help <command name> for more info or check the link below.
Ensure that your package has a Project.toml that gives it a UUID and names it (generate one with ]generate from the Julia REPL or with the PkgTemplates package) and that it is in a git repo with at least one commit including all the relevant files.
Then choose how you would like to use the package.
You probably want to run ]dev ~/projects/ExamplePkg:
If dev is used on a local path, that path to that package is recorded and used when loading that package. The path will be recorded relative to the project file, unless it is given as an absolute path.
If you use dev and you change the dependencies in the dev'd package, then you should probably run ]resolve in all environments that depend on the package.
Or you can run ]add ~/projects/ExamplePkg:
Instead of giving a URL of a git repo to add we could instead have given a local path to a git repo. This works similarly to adding a URL. The local repository will be tracked (at some branch) and updates from that local repo are pulled when packages are updated. Note that changes to files in the local package repository will not immediately be reflected when loading that package. The changes would have to be committed and the packages updated in order to pull in the changes.
In Julia versions <1.4: If you accidentally ]add a package before the git repo is set up correctly then you might get ERROR: GitError(Code:EUNBORNBRANCH, Class:Reference, reference 'refs/heads/master' not found). Unfortunately, Julia will probably have cached the bad repo, and you will need to remove that from ~/.julia/clones/<gibberish>/. You can find the dir to remove with grep: $ grep ExamplePkg ~/.julia/clones/*/config.
Documentation: https://julialang.github.io/Pkg.jl/v1/managing-packages/
you can try
path_to_package = "~/projects/ExamplePkg"
push!(LOAD_PATH,path_to_package)
# then use it, ExamplePkg is the package's name
using ExamplePkg
But you have to run codes above whenever you restart Julia.
reference is Workflow tips-Julia Documentation

Submitting a pull request for a Julia package in Pkg v1.1

I want to add a feature to FITSIO package and submit a pull request. What is the current workflow for that? Before Pkg 1.0 there were Pkg.checkout and Pkg.submit functions. Are there similar commands that I can run in Pkg v1.1?
Of course, I can manually fork the repository on Github, make changes and submit a pull request. But I wonder if there are convenient shortcuts in Pkg 1.1 for that?
Update
Here is a useful guide that I found.
You can use Pkg.develop (or the develop Pkg REPL command) which will download a full git-clone of the package and put it in $HOME/.julia/dev by default. There you can make your changes and push as usual.
Pkg.develop can also take a path as an argument, so if you have git cloned the repository to some other more convenient folder (as compared to $HOME/.julia/dev) and prefer to work there you can "install" that path by Pkg.develop(PackageSpec(path = "path/to/clone")) and it should be available to load from within Julia.
EDIT:
checkout has been replaced by two new things:
if the intention is just to install the master branch of the package you now do pkg> add Example#master (or Pkg.add(PackageSpec(name="Example", rev="master")));
If the intention is to modify the code you use Pkg.develop.
There does not exist something like Pkg.submit in the new package manager; you have to git push and make a PR yourself.

Julia: Use an older version of a package

I am really new to Julia and confused about using an old version of the SISL Vec package.
I am trying to setup ngsim_env and their instructions require you to use an older v0.1.0 of Vec. But, when I followed the instructions to install the Vec package and then checkout the v0.1.0 tag it didn't work.
Here's what I did
$ julia ../build.jl for some package which includes this block
packages = keys(Pkg.installed())
if !in("Vec", packages)
Pkg.clone("https://github.com/tawheeler/Vec.jl.git")
end
Note: This git URL actually goes to the SISL Vec page.
cd ~/.julia/packages/Vec
git fetch tags
git checkout v0.1.0
I did a bunch of other installations with many other packages. At some point I noticed that there is a package ~/.julia/dev/Vec and ~/.julia/packages/Vec. The one in dev has the correct v0.1.0 code and the one in packages has the newer wrong code. When I tried to use other packages that needed the older Vec they were throwing errors and the paths were to files in the packages directory.
I tried Pkg.rm("Vec"). This did something to the project manifest. After nothing worked, every package would throw errors like KeyError: key "Vec" not found and Pkg.add("Vec") nor original Vec installation helped. I even tried removing both the Vec directories from ~/.julia but that didn't help.
I guess a big question is why does Julia put some packages into packages/ and others into dev/ and how to control which one's get used if the same package appears in both places like Vec is.
Would greatly appreciate any assistance, totally confused.
The dev command fetches a full clone of the package to ~/.julia/dev/
via the docs. The only things I have in my dev directory there are the ones I am developing on my own.
I think that triggered when you did a check out manually with git checkout.
Accordingly:
to stop tracking a path and use the registered version again, use free
Try deleting the packages, and whipping mentions of Vec.jl from your manifest:
(v1.0) pkg> rm Vec
(v1.0) pkg> add https://github.com/tawheeler/Vec.jl.git#0.1.0
In general, try using Pkg when possible, cause it does a lot of house keeping magic in the back
(Also, the repl interface with pkg makes everything easier, so hit ] from a blank julia> to get there. And a quick Pkg.status() or ] st will show you what youre tracking and whats in dev and what version you have pinned, etc.)

Nix tutorial on installing in home directory

I am trying to follow this tutorial, in order to install the Nix package manager in my home directory instead of /nix.
I am doing the PRoot installation (see 2. in tutorial). At the end, the
tutorial proposes to be smart in Building native packages section, to be
able to run packages without PRoot:
To run packages natively (without PRoot) they have to be build from source because all paths to the nix store are hard-coded. It is simple, really:
mkdir $HOME/nix
nix-channel --update
env NIX_STORE_DIR=$HOME/nix nix-env -i nix
And now your Nix store gets built up using the new paths. The built binaries can be run directly from there.
I did that, but I don't see how it frees me from PRoot. If I don't do the /nix mounting point with PRoot, nothing works (no nix-env executable,
I can't install new packages).
Should this NIX_STORE_DIR environment variable be put in my .bashrc ?
It seems I always need to run PRoot because ~/.nix-profile points to
a /nix/... directory:
.nix-profile -> /nix/var/nix/profiles/default
There are more steps in the tutorial (5., 6.) - should I follow them ? It seems they apply only in case of using the manual installation (step 4.),
although it is not explicit.
Any help would be appreciated :)
For anyone stumbling on this old question: there is no currently supported way to install Nix without root. The above wiki was moved to https://nixos.wiki/wiki/Nix_Installation_Guide . It may well be out of date. PRoot could work, but even then, rebuilding the whole store at a different path is not a good idea, not the least because the binary caches won't help and you'll need to build everything.
I suggest trying Nix in a virtual machine or cloud server.
Future people from Google, it's still unsupported but does work. Script here that installs a couple dependencies, builds a temporary Nix, and uses that to install a proper version in your directory of choice.

Meteor - Test application using local package over the published one

I'm using Meteor 0.9.3, and I want to try to make some changes to a Meteor smart package. I'm using the package in my app already, let's call it: author:smartpackage.
First, I removed my reference to the published package:
meteor remove author:smartpackage
I've forked the repository on GitHub, and made a local clone in:
/somedir/meteor-smartpackage/
I've created a directory in my meteor app:
/meteor/myApp/packages
and created a symlink:
ln -s /somedir/meteor-smartpackage /meteor/myApp/packages/meteor-smartpackage
How do I now add this local package into my app? I've tried a variety of
meteor add xxxx
options, but I can't find the right command. Am I even close?
The steps you described look good to me, so maybe this is the symlink stuff which is messing around.
The proper way of maintaining private packages is to have a packages/ directory somewhere in your filesystem, let's say in ~/meteor/packages, then you have to set a special environment variable that is called PACKAGE_DIRS, which is looked up by the meteor command line tool to find local packages that reside out of official package repositories.
So let's set this environment variable in your .bashrc and resource it :
echo "export PACKAGE_DIRS=$HOME/meteor/packages" >> ~/.bashrc;
. ~/.bashrc
Then assuming your forked package resides in ~/meteor/packages, meteor add author:package should work normally.
Update to saimeunt's answer, for Meteor 1.2+
I found that loading the local package requires leaving out the author when running meteor add.
Loads Local Package
meteor add cocos2d-meteor
Loads Remote Package
meteor add jakelin:cocos2d-meteor

Resources