Package: env-exec
env-execOverviewTheenv-execlibrary is a versatile Python utility designed for managing computational environments and containers, as well as executing code within them. It aims to simplify the process of setting up, utilizing, and tearing down different kinds of environments, including but not limited to Conda environments.Installationpipinstallenv-execUsage as a libaryCreate an ephemeral Conda environment with dependencies installed.withCondaEnv(dependencies=['python'])asenv:# Execute a command in the environmentenv.exec('python -V')# The environment is automatically cleaned up after exiting the context managerCapture the output of executed commands.withCondaEnv(dependencies=['python'])asenv:output=env.exec('python -V',capture_output=True)print(output.stdout)# Python 3.8.5Give the environment a name to prevent it from being deleted. If the environment already exists, it will be reused.withCondaEnv('my-env',dependencies=['python'])asenv:env.exec('python -V')CondaEnv('my-env').exists# TrueError if dependencies are missing from env.# Raises MissingDependencyErrorwithCondaEnv('my-env',dependencies=['python','numpy'])asenv:passInstall dependencies if they are missing.withCondaEnv('my-env',dependencies=['python','numpy'],install_missing=True)asenv:env.exec('python -c "import numpy"')Usage as a CLI$env-exec-dpython=3.12.0mambapython-VPython 3.12.0usage: env-exec [-h] [-n NAME] [-d DEPENDENCY] [-c CHANNEL] [-v] {conda,mamba,docker} ...

cli for executing commands in a virtual environment

positional arguments:
  {conda,mamba,docker}  The package manager to use.
  command               The command to execute.

options:
  -h, --help            show this help message and exit
  -n NAME, --name NAME  The name of the environment.
  -d DEPENDENCY, --dependency DEPENDENCY
                        The dependencies to install.
  -c CHANNEL, --channel CHANNEL
                        Channel to use.
  -v, --verbose         If True, the output of the commands will be captured.FeaturesEnvironment ManagementAutomated Setup: Create new computational environments programmatically.Dependency Management: Specify and manage dependencies for each environment.Dynamic Names: Generate random environment names or specify them manually.Command ExecutionRun Code: Execute code blocks, shell commands, or scripts within the environment.Capture Output: Option to capture the output of executed commands.Error HandlingCustom Exceptions: Well-defined exceptions for handling environment-specific issues.Extensible DesignPluggable Backends: Easily extend the library to support other environment managers or container systems.CleanupContext Manager: Use as a context manager to ensure proper resource cleanup.DependenciesPython 3.7 or higherConda installed and accessible via the command line (if usingCondaEnv)Extending for Other ManagersYou can also extend the library to create your own environment managers. Just inherit from theEnvclass and implement the required methods.Error HandlingThe library raises custom exceptions for more explicit error handling. These include:ExecError: Raised if an error occurs while executing a command in the environment.MissingDependencyError: Raised if missing dependencies are found and not installed.ContributingContributions are welcome! If you have a feature request, bug report, or wish to contribute code, please feel free to open an issue or a pull request.LicenseThe code in this project is licensed under MIT. Please see the accompanying LICENSE file for details.