Macros

ShareAdd.@usinganyMacro
@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 to true, first updates the package(s) called by the macro
  • update_env::Bool: update the shared environments currently in the LOAD_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
source
ShareAdd.@usingtmpMacro
@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, AND MyPkg will be dev-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.

source

Functions

Exported functions

ShareAdd.activate_tempMethod
activate_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.

source
ShareAdd.delete_shared_envMethod
delete_shared_env(env::Union{AbstractString, EnvInfo})

Deletes the shared environment env by erasing it's directory.

Returns nothing.

source
ShareAdd.delete_shared_pkgMethod
delete_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.

source
ShareAdd.list_shared_envsMethod
list_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.

source
ShareAdd.list_shared_pkgsMethod
list_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"
source
ShareAdd.make_current_mnfMethod
make_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.
source
ShareAdd.make_importableMethod
make_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
source
ShareAdd.reset_loadpath!Method
reset_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"].

source
ShareAdd.sh_addMethod
sh_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"
source
ShareAdd.update_sharedFunction
update_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 environment nm (if it exists).
  • Called with a single argument nm::String not starting with "@", updates the package nm in all shared environments.
  • Called with a single argument nm::Vector{String}, updates the packages and/or environments in nm.
  • Called with two arguments env and pkgs, updates the package(s) pkgs in the environment env.

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.

source

Public functions

ShareAdd.check_packagesMethod
check_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 in LOAD_PATH
  • inshared_pkgs: packages that are available in some shared environments
  • installable_pkgs: available packages
  • unavailable_pkgs: packages that are not available from any registry
  • shared_pkgs: Dictionary of packages in shared environments
  • current_pr: information about the current environment as @NamedTuple{name::String, shared::Bool}
source
ShareAdd.current_envMethod
current_env(; depot = first(DEPOT_PATH)) -> EnvInfo

Returns information about the current active environment as an EnvInfo object.

source
ShareAdd.env_pathFunction
env_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 @.

source

Internal functions

ShareAdd.optim_setMethod
optim_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.

source
ShareAdd.prompt2installMethod
prompt2install(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.

source

Public types

ShareAdd.EnvInfoType
mutable struct EnvInfo
  • name::String - name of the environment
  • path::String - path of the environment's folder
  • pkgs::Vector{String} - list of packages in the environment
  • in_path::Bool - whether the environment is in LOAD_PATH
source
ShareAdd.EnvSetType
struct EnvSet
  • envs::Set{String} - set of environment names
  • extraneous_pks::Set{String} - (internally used, see optim_set function for details)
  • extra_lng::Int - as above
  • no_of_sets::Int - as above
source
ShareAdd.PackageInfoType
mutable struct PackageInfo
  • name::String - name of the package
  • envs::Vector{EnvInfo} - list of environments in which the package is present
  • in_path::Bool - whether any of the environments is in LOAD_PATH
source

Index