API¶
-
cpenv.api.
activate
(requirements, ignore_unresolved=False)[source]¶ Resolve and active a list of module requirements.
- Usage:
>>> cpenv.activate('moduleA', 'moduleB')
- Arguments:
- requirements (List[str]): List of module requirements
- Returns:
- list of Module objects that have been activated
-
cpenv.api.
deactivate
()[source]¶ Deactivates an environment by restoring all env vars to a clean state stored prior to activating environments
-
cpenv.api.
clone
(module, from_repo=None, where=None, overwrite=False)[source]¶ Clone a module for local development.
- A typical development workflow using clone and publish:
- clone a module
- make changes
- test changes
- increment version in module.yml
- publish a new version of your module
-
cpenv.api.
create
(where, name, version, **kwargs)[source]¶ Create a new module.
- Arguments:
- where (str): Path to new module name (str): Name of module version (str): Version of module description (str): Optional description of module author (str): Optional author of module email (str): Optional email address of author requires (list): Optional modules that this module depends on environment (dict): Optional environment variables
- Returns:
- Module object
-
cpenv.api.
localize
(requirements, to_repo='home', overwrite=False, ignore_unresolved=False)[source]¶ Localize a list of requirements.
-
cpenv.api.
publish
(module, to_repo='home', overwrite=False)[source]¶ Publish a module to the specified repository.
-
cpenv.api.
resolve
(requirements, ignore_unresolved=False)[source]¶ Resolve a list of module requirements.
-
cpenv.api.
set_home_path
(path)[source]¶ Convenient function used to set the CPENV_HOME environment variable.
-
cpenv.api.
get_home_path
()[source]¶ Returns the cpenv home directory.
- Default home paths:
- win - C:/ProgramData/cpenv mac - /Library/Application Support/cpenv OR /Library/Caches/cpenv linux - /usr/local/share/cpenv OR ~/.local/share/cpenv
-
cpenv.api.
get_home_modules_path
()[source]¶ Return the modules directory within the cpenv home directory.
-
cpenv.api.
get_cache_path
(*parts)[source]¶ Return the cpenv cache directory within the cpenv home directory.
- Arguments:
- *parts (str) - List of path parts to join with cache path
-
cpenv.api.
get_user_path
()[source]¶ Returns the cpenv user directory.
- Default user paths:
- win - C:/Users/<username>/AppData/Roaming/cpenv mac - ~/Library/Application Support/cpenv linux - ~/.local/share/cpenv
-
cpenv.api.
get_user_modules_path
()[source]¶ Returns the modules directory within the cpenv user directory.
- Default user paths:
- win - C:/Users/<username>/AppData/Roaming/cpenv/modules mac - ~/Library/Application Support/cpenv/modules linux - ~/.local/share/cpenv/modules
-
cpenv.api.
get_module_paths
()[source]¶ Returns a list of paths used to lookup local modules.
- The list of lookup paths contains:
- use modules path
- home modules path
- paths in CPENV_MODULES environment variable
-
cpenv.api.
add_active_module
(module)[source]¶ Add a module to CPENV_ACTIVE_MODULES environment variable.
- Arguments:
- module (Module): Module to add to CPENV_ACTIVE_MODULES
-
cpenv.api.
remove_active_module
(module)[source]¶ Remove a module from CPENV_ACTIVE_MODULES environment variable.
- Arguments:
- module (Module): Module to remove from CPENV_ACTIVE_MODULES
-
cpenv.api.
add_repo
(repo, priority=None)[source]¶ Register a Repo.
- Arguments:
- priority (int): Override the Repos priority when adding.
-
cpenv.api.
read_config
(key=None, default=<object object>)[source]¶ Read the whole config or a specific key from disk.
- Examples:
# Read whole config config = read_config()
# Read one key repos = read_config(‘repos’, {})
-
cpenv.api.
write_config
(*args)[source]¶ Write the whole config or a specific key to disk.
- Examples:
# Write whole config write_config({‘repos’: {}})
# Write one config key write_config(‘repos’, {})
-
class
cpenv.hooks.
HookFinder
(*hook_paths)[source]¶ Find python hooks by name in the provided path.
usage:
>>> hook_finder = HookFinder('~/.cpenv/hooks') >>> hook = hook_finder('precreate') >>> hook.run(env=VirtualEnvironment('path/to/env'))
-
cpenv.hooks.
run_global_hook
(hook_name, *args)[source]¶ Attempt to run a global hook by name with args
-
exception
cpenv.resolver.
ResolveError
[source]¶ Raised when a Resolver fairs to resolve a module or list of modules.
-
class
cpenv.resolver.
Resolver
(repos)[source]¶ Responsible for resolving ModuleSpecs from requirement strings.
Modules will be looked up sequentially in all registered Repos. By default this order is:
- LocalRepo pointing to current working directory
- LocalRepo pointing to cpenv_user_modules_path
- LocalRepo pointing to cpenv_home_modules_path ($CPENV_HOME/modules)
- LocalRepos pointing to the paths in $CPENV_MODULES
- Custom Repos registered via cpenv.add_repo
If there are still unresolved modules, fallback to the old algorithm for module lookups using the resolve functions in the cpenv.resolver.module_resolvers list.