Macros
ShareAdd.@usingany
— Macro@usingany pkg
@usingany pkg1, pkg2, ...
@usingany pkg: fn
@usingany pkg: fn, @mcr, ...
@usingany kwarg = true [pkg...]
Makes package(s) available, if they are not already, and loads them with using
keyword.
- If a package is available in an environment in
LOAD_PATH
, that's OK. - If a package is available in a shared environment, this environment will be pushed into
LOAD_PATH
. - Otherwise if package(s) can be installed, you will be prompted to select an environment to install each package.
- If the package is not listed in any registry, an error will be thrown.
The macro can be called with keyword arguments:
update_pkg::Bool
: if set totrue
, first updates the package(s) called by the macroupdate_env::Bool
: update the shared environments currently in theLOAD_PATH
update_all::Bool
: update the current package as well as ALL shared environments
If Julia version supports versioned manifests, on any updates a versioned manifest will be created in each updated env. See also make_current_mnf
and update_shared
.
If update_all
or update_env
kwarg is set, @usingany
can be called without specifying any package(s) for import. If update_pkg
kwarg is set, package(s) to import must be specified.
This macro is exported.
Examples
julia> @usingany Foo, Bar
julia> @usingany Baz: quux
julia> @usingany update_all = true
julia> @usingany update_pkg = true Qux
ShareAdd.@usingtmp
— Macro@usingtmp
@usingtmp pkg
@usingtmp pkg1, pkg2, ...
@usingtmp pkg: fn
@usingtmp pkg: fn, @mcr, ...
Activates a temporary environment, optionally installs packages into it and loads them with using
keyword.
- If current environment is a temporary one, environment is not changed.
- If current env was a project (not package!), a temporary env will be activated.
- If current env was a package (under development), e.g.
MyPkg
, a temporary env will be activated, ANDMyPkg
will bedev
-ed in that temporary env.
Afterwards, if @usingtmp
was called with arguments, the corresponding packages will be installed into that temporary env, and imported with using
keyword.
This macro is exported.
Functions
Exported functions
ShareAdd.activate_temp
— Methodactivate_temp()
If current environment is a temporary one, does nothing. Otherwise activates a temporary environment. If the initial environment was a package (under development), makes this package available in the new environment by calling Pkg.develop
.
Returns nothing
.
ShareAdd.delete_shared_env
— Methoddelete_shared_env(env::Union{AbstractString, EnvInfo})
Deletes the shared environment env
by erasing it's directory.
Returns nothing
.
ShareAdd.delete_shared_pkg
— Methoddelete_shared_pkg(pkg::AbstractString)
Deletes the package pkg
from it's shared environment. Deletes this environment if it was the only package there. If the package is present in multiple environments, it will not be deleted and an error will be thrown, suggesting you do it manually.
Returns nothing
.
ShareAdd.list_shared_envs
— Methodlist_shared_envs() -> Vector{String}
list_shared_envs(pkg_name) -> Vector{String}
Returns the names of all shared environments (if called without an argument), or the environment(s) containing the package pkg_name
.
ShareAdd.list_shared_pkgs
— Methodlist_shared_pkgs(; all=false) -> Vector{String}
list_shared_pkgs(env_name) -> Vector{String}
Returns the names of packages in all shared environments, or in given environment. If all=true
, also includes packages in @stdlib.
Examples
julia> list_shared_pkgs()
5-element Vector{String}:
"foo"
"bar"
"baz"
"qux"
"quux"
julia> list_shared_pkgs("@Qu")
2-element Vector{String}:
"qux"
"quux"
ShareAdd.make_current_mnf
— Methodmake_current_mnf(path_or_name)
make_current_mnf(env::EnvInfo)
make_current_mnf(; current::Bool)
If called make_current_mnf(; current=true)
, the current environment will be processed by this function.
path_or_name
can name of a shared environment starting with @
, or a path to any environment.
- If currently executed Julia version doesn't support versioned manifests, do nothing.
- Else, if a versioned manifest for current Julia already exists, do nothing.
- Else, is a (versioned) manifest for an older Julia exists in the given directory, copy it to a file
named according to the current Julia version, e.g. Manifest-v1.11.toml
.
- Else, create empty one.
ShareAdd.make_importable
— Methodmake_importable(pkg::AbstractString)
make_importable(pkgs::AbstractVector{<:AbstractString})
make_importable(pkg1, pkg2, ...)
make_importable(::Nothing) => :success
Checks packages (by name only, UUIDs not supported!), prompts to install packages which are not in any shared environment, and adds relevant shared environments to LOAD_PATH
.
make_importable
is used internally by @usingany
, but it can be used separately e.g. if you e.g. want to import a package via import
statement instead of using
.
Returns :success
if the operation was successful, and nothing
if the user selected "Quit. Do Nothing." on any of the prompts.
Throws an error on unavailable packages.
Examples
julia> using ShareAdd
julia> make_importable("Foo")
:success
julia> import Foo
julia> using ShareAdd
julia> make_importable("Foo")
:success
julia> using Foo: bazaar as baz # @usingany Foo: bazaar as baz is not a supported syntax
ShareAdd.reset_loadpath!
— Methodreset_loadpath!()
Resets the LOAD_PATH to the default values: removes any manually added paths, and resets the load path to the standard values of ["@", "@v#.#", "@stdlib"].
ShareAdd.sh_add
— Methodsh_add(env_name::AbstractString; depot = first(DEPOT_PATH)) -> Vector{String}
sh_add(env_names::AbstractVector{<:AbstractString}; depot = first(DEPOT_PATH)) -> Vector{String}
sh_add(env_name::AbstractString, ARGS...; depot = first(DEPOT_PATH)) -> Vector{String}
Adds shared environment(s) to LOAD_PATH
, making the corresponding packages all available in the current session.
Returns the list of all packages in the added environments as a Vector{String}
.
Examples
julia> sh_add("@StatPackages")
3-element Vector{String}:
"Arrow"
"CSV"
"DataFrames"
julia> sh_add(["@StatPackages", "@Makie"])
4-element Vector{String}:
"Arrow"
"CSV"
"DataFrames"
"Makie"
julia> sh_add("@StatPackages", "@Makie")
4-element Vector{String}:
"Arrow"
"CSV"
"DataFrames"
"Makie"
ShareAdd.update_shared
— Functionupdate_shared()
update_shared(nm::AbstractString)
update_shared(nm::Vector{<:AbstractString})
update_shared(env::AbstractString, pkgs::Union{AbstractString, Vector{<:AbstractString}})
update_shared(env::EnvInfo, pkgs::Union{Nothing, S, Vector{S}} = Nothing) where S <: AbstractString
- Called with no arguments, updates all shared environments.
- Called with a single argument
nm::String
starting with "@", updates the environmentnm
(if it exists). - Called with a single argument
nm::String
not starting with "@", updates the packagenm
in all shared environments. - Called with a single argument
nm::Vector{String}
, updates the packages and/or environments innm
. - Called with two arguments
env
andpkgs
, updates the package(s)pkgs
in the environmentenv
.
If Julia version supports versioned manifests, on any updates, a versioned manifest will be created in each updated env. See also make_current_mnf
.
Returnes nothing
.
Public functions
ShareAdd.check_packages
— Methodcheck_packages(packages; depot = first(DEPOT_PATH)) -> NamedTuple
checks whether packages are available in the current environment, shared environments, or are installable.
Returns a NamedTuple with the following fields:
inpath_pkgs
: packages that are already present in some environment inLOAD_PATH
inshared_pkgs
: packages that are available in some shared environmentsinstallable_pkgs
: available packagesunavailable_pkgs
: packages that are not available from any registryshared_pkgs
: Dictionary of packages in shared environmentscurrent_pr
: information about the current environment as@NamedTuple{name::String, shared::Bool}
ShareAdd.current_env
— Methodcurrent_env(; depot = first(DEPOT_PATH)) -> EnvInfo
Returns information about the current active environment as an EnvInfo
object.
ShareAdd.env_path
— Functionenv_path(env_name::AbstractString, depot = first(DEPOT_PATH); skipfirstchar = true) -> String
Returns the path of the environment with name env_name
. If skipfirstchar
is true
, the first character of env_name
is skipped, so that the name of a shared environment can be passed without the leading @
.
ShareAdd.list_shared_packages
— Methodlist_shared_packages(;depot = first(DEPOT_PATH)) -> Dict{String, PackageInfo}
ShareAdd.shared_environments_envinfos
— Methodshared_environments_envinfos(; depot = first(DEPOT_PATH)) ->
(; shared_envs::Vector{EnvInfo},
envs_folder_path::String,
shared_env_names::Vector{String})
Internal functions
ShareAdd.fn2string
— Methodconverts function or macro name to string
ShareAdd.optim_set
— Methodoptim_set(pks::AbstractArray{<:AbstractString}, envs::AbstractVector{EnvInfo}) -> OptimSet
optim_set(pkgs::AbstractArray{PackageInfo}) -> OptimSet
Finds the optimum set of environments for the given list of packages. Optimal is a set of environments with the least number of extraneous packages. If two sets have the same number of extraneous packages, then the one with the least number of environments is chosen.
The function is internal.
ShareAdd.prompt2install
— Methodprompt2install(packages::AbstractVector{<:AbstractString})
prompt2install(package::AbstractString)
Prompt user to select a shared environment to install a package or packages.
For a single package, if the user selects an environment, the package will be installed there. If the user selects "A new shared environment (you will be prompted for the name)", the user will be prompted to enter a name for a new environment.
For multiple packages, the function will be called on each package and the user will be prompted for each package.
The function will return a vector of NamedTuples, each with field pkg
and env
, where pkg
is the name of the package and env
is the environment where it should be installed.
The function will return nothing
if the user selects "Quit. Do Nothing." on any of the prompts.
ShareAdd.update_all
— Methodupdated all shared environments and the current project
ShareAdd.update_all_envs
— Methodupdates all shared environments currently in LOAD_PATH
Public types
ShareAdd.EnvInfo
— Typemutable struct EnvInfo
name::String
- name of the environmentpath::String
- path of the environment's folderpkgs::Vector{String}
- list of packages in the environmentin_path::Bool
- whether the environment is inLOAD_PATH
ShareAdd.EnvSet
— Typestruct EnvSet
envs::Set{String}
- set of environment namesextraneous_pks::Set{String}
- (internally used, seeoptim_set
function for details)extra_lng::Int
- as aboveno_of_sets::Int
- as above
ShareAdd.OptimSet
— Typemutable struct OptimSet
best_set::EnvSet
- the best set of environments currently found - seeoptim_set
function for details.
ShareAdd.PackageInfo
— Typemutable struct PackageInfo
name::String
- name of the packageenvs::Vector{EnvInfo}
- list of environments in which the package is presentin_path::Bool
- whether any of the environments is inLOAD_PATH
Index
ShareAdd.EnvInfo
ShareAdd.EnvSet
ShareAdd.OptimSet
ShareAdd.PackageInfo
ShareAdd.activate_temp
ShareAdd.check_packages
ShareAdd.current_env
ShareAdd.delete_shared_env
ShareAdd.delete_shared_pkg
ShareAdd.env_path
ShareAdd.fn2string
ShareAdd.list_shared_envs
ShareAdd.list_shared_packages
ShareAdd.list_shared_pkgs
ShareAdd.make_current_mnf
ShareAdd.make_importable
ShareAdd.optim_set
ShareAdd.prompt2install
ShareAdd.reset_loadpath!
ShareAdd.sh_add
ShareAdd.shared_environments_envinfos
ShareAdd.update_all
ShareAdd.update_all_envs
ShareAdd.update_shared
ShareAdd.@usingany
ShareAdd.@usingtmp