Package: conda-ops
conda-opsCreating, maintaining and not breaking conda-based python environments can be messy and complicated. Sharing environments (or creating environments to run a notebook or project that's been handed to you) is even harder.conda-opsprovides a simple, easy-to-use solution to the often confusing, complex, and complicated python+conda packaging and environment nightmare that "just works". Think of it like "poetry for conda". It helps keep track of and integrate pip installed packages with conda, which isnotoriously fraught with perilbut impossible to avoid in an everyday development environment (pip install -e .).conda opsis a command line tool, in fact, a conda plugin, that manages your project's conda environment and transparently keeps track of:what you asked for (requirements file)what you needed (lock file)your shareable conda settings (project-based .condarc file)It gives you the ability to run status checks on your environment and lets you know what you should or can do next (conda ops) to keep everything working and in sync.InstallationRequirements: Note thatconda-opsrequires modern conda with plugin support (and python/pip). e.g.>>> conda install -n base -c defaults conda>=23.5.0
>>> conda install -n base -c defaults python>=3.11conda-opsis still under significant development and is changing rapidly. We recommend updating it regularly no matter which version you choose to install.For the latest development version:conda run -n base pip install git+https://github.com/acwooding/conda-opsFor the latest alpha release available via PyPI:conda run -n base pip install conda-opsTo install the plugin locally in development mode, clone the repo and then runpip install -e .from your basecondainstall (e.g.conda run -n base pip install -e ..Please make sure that you installconda-opsinto yourbaseconda environment for the plugin for work properly. (If you install it into a conda environment, you will have to use that environment'scondainstallation to pick up the plugin; that is, installing conda into that environment and runningpath/to/environment/conda/bin opsinstead ofconda ops).To uninstall,pip uninstall conda-opsfrom your within yourbaseconda environment.Basic UsageInitializationTo set up a conda ops managed project environment in the current working directory (similar togit init):conda ops initThis creates a.conda-opsdirectory that contains the conda ops configuration files and lock files, and anenvironment.ymlfile if it doesn't already exist.Similar togityou can always check the status of your conda ops managed environment viaconda ops statusor simply,conda ops. This will prompt you for what you may need to next do if anything ever gets out of sync.Package ManagementBeyondconda ops initandconda ops, there are only 3 commands that you need to regularly:conda ops add: Add packages to the requirements file.conda ops remove: Remove packages from the requirements file. Removes all versions of the packages from any channel they are found in.conda ops sync: Sync the environment and lock file with the requirements file.To add packages from conda channels other than the default conda channel, you can use-cor--channel:conda ops add -c channel1 package1 package2 -c channel2 package3This adds the entrieschannel1::package1,channel1::package2andchannel2::package3to the requirements file and is shorthand forconda ops add channel1::package1 channel1::package2 channel2::package3For anything usingpipinstead ofconda, you can use--pipor-edepending on the circumstance:conda ops add --pip package1will addpackage1under thepipsection of the requirements file.We also support VCS and editable installs via pip. For example, the ubiquitouspip install -e .can be done as:conda ops add -e .
conda ops syncor simplyconda ops install -e .In this case, the line-e .is added to the pip section of the requirements file. If-eis used,--pipis not needed as editable installs are done via pip.As a convenienceconda ops installworks likeconda installbut allows conda ops to track the installed packages transparently and reproducibly (it does aconda ops addand thenconda ops sync). Similarly,conda ops uninstallworks likeconda uninstalland consists ofconda ops removeandconda ops sync. (Note that becauseinstallis anadd+synclocal pacakges specified for pip installation are relative to the requirements file).Helpful CommandsOther helpful commands include:conda ops reqs list: Show the contents of the requirements file.conda ops reqs edit: Open the requirements file in the default editor.conda ops config: Behaves similarly toconda configbut only handles the configuration tracked in.conda-ops/.condarc. Seeconda ops config --helpfor details.conda ops env clean: Remove any temporary environments that have been left lying around.The interface for conda ops is still experimental and may change between commits. The best way to see what can be done at a given moment is to use the help menu:conda ops --helpor to check the status of your conda ops project viaconda opsand follow the prompts from there.Working with JupyterIf you want to work with your conda-ops project environment from with a Jupyter Notebook or Jupyter Lab context, we recommend running your Jupyter instance from adifferentenvironment from your current project environment, and making sure that the (conda) environment you're running Jupyter from hasnb_conda_kernelsinstalled in it so that you can select your conda-ops project environment from within the list of kernels in Jupyter (e.g. have a separate conda-ops project for managing your Jupyter instance!)To interact with and update your conda-ops managed project environment, we recommend using a terminal where the managed project environment isnotactive. You may need to add a cell at the top of your notebooks with%load_ext autoreload
%autoreload 2so that changes to the environment automatically translate to the notebook. Everything shouldjust work. If not, file an issue and we'll help to sort it out.Managing conda ConfigurationsThere is also a project specific.condarcfile that is always and only invoked byconda opswithin the current conda ops project. This configuration file contains all of the conda config settings relating to the solver and the channel settings so that solves are reproducible and the relevant configurations are easily shareable. Seeconda ops config --helpfor more details on how to work with and manage the conda configuration within a conda ops project.We get that things can sometimes be slow. If you'd like to try the libmamba to try to speed things up:conda install -n base conda-libmamba-solver
conda ops config --set solver libmambaLibmamba is especially useful if your environment isn't solving since it gives much better error messages (and quickly) about what's going on.Requirements Fileconda-opsuses anenvironment.ymlfile as its requirements file. If you have an existingenvironment.ymlfile in your repo when you initialize a conda ops project (conda ops init), it will automatically pick up the existing file and use it. Furthermore, if there are any additions or changes that need to be made to make it compatible withconda-ops(namely, channels, if used, must all be specified in the sectionchannelsin order of preference), you will be prompted to have the file updated accordingly.Development Requirements: Testing and LintingTo set up testing or linting, you'll need the depedencies specified under[project.optional-dependencies]in thepyproject.tomlinstalled into your environment.Running testsOnce dependencies are set up, runpytestorcoverage run -m pytest. After runningcoverage,coverage reportwill display the basic coverage information andcoverage htmlwill generate an html interactive coverage report.LintingFor now, keep a line length of 200Always run black for auto-formatting.black . -l 200: specify a larger max line length with blackTake a look at flake8 or pylint reports for linting. flake8 is more lightweight.flake8 --max-line-length=200 --exclude conda_ops_later.pypylint src --max-line-length=200 --ignore=conda_ops_later.py