Package: conda-poetry-liaison
conda_poetry_liaisonMake conda and poetry communicateInstallation•Example•Scripts•Development•Deploying•LicenseDo not use another package manager in a conda environment.Many are given this advice, but we do this anyway.
We want our conda-only packages with the awesome features ofpoetry.conda_poetry_liaisonis a small collection of scripts to make this as painless and reproducible as possible.InstallationYou can installconda_poetry_liaisonwith condacondainstall-cconda-forgeconda-poetry-liaisonExampleCreate and activate a conda environment.
For this example, we are creating an environment namedsunshine.condacreate-y-nsunshinepython=3.11&&condaactivatesunshineInstall the following required packages.condainstall-y-cconda-forgepoetrypre-committomlitomli-wconda-poetry-liaisonInstall your desired packages; for example, suppose you wantnumpy,scipy, andmatplotlib.condainstall-y-cconda-forgenumpyscipymatplotlibUpdate thetool.poetry.group.conda.dependenciesgroup in yourpyproject.tomlwith thecpl-depsscript.cpl-depspyproject.toml--env_namesunshineCleanup your conda environment withcpl-cleanbefore switching to using poetry exclusively.cpl-clean--env_namesunshineNow you are good to go!
For example, you can runpoetry installto install all poetry-managed PyPI packages inpyproject.toml.Scriptscpl-depsThe primary issue of using other package managers like pip and poetry inside a conda environment is that they will not communicate.
If you install a package with conda, then install a different one in pip, conda will have no idea what has changed.
So once you start using pip or poetry, you cannot use conda to install a package in that same environment.This script will add all Python packages installed in the conda environment into thepyproject.tomlfile.
Now, poetry will be aware of these packages during dependency solving.usage: cpl-deps [-h] [--env_name [ENV_NAME]] [--env_path [ENV_PATH]] [--group_name [GROUP_NAME]] [toml_path]

Notify poetry of conda Python packages

positional arguments:
  toml_path             Path to TOML file

options:
  -h, --help            show this help message and exit
  --env_name [ENV_NAME]
                        Name of conda environment to probe
  --env_path [ENV_PATH]
                        Path of conda environment to probe
  --group_name [GROUP_NAME]
                        Name of poetry dependency groupcpl-cleanThere seems to be a remnant ofdirect_url.jsonfiles from conda package installations that break poetry (as discussedhere).
One workaround is to delete these files in the conda environment directory before using poetry.usage: cpl-clean [-h] [--env_name [ENV_NAME]] [--env_path [ENV_PATH]]

Clean up the conda environment for use with poetry

options:
  -h, --help            show this help message and exit
  --env_name [ENV_NAME]
                        Name of conda environment to probe
  --env_path [ENV_PATH]
                        Path of conda environment to probeDevelopmentClone theGitHub repository.gitclonehttps://github.com/oasci/conda-poetry-liaison&&cdconda-poetry-liaisonInstall poetry if you do not have it.makepoetry-download[!NOTE]
We use theGNUmaketool to help automate these commands.
This can be installed on linux withsudoapt-getinstallbuild-essentialIf you cannot installmake, you can just individually run the commands in theMakefile.If you already have poetry installed, ensure you havepoetry-dynamic-versioning.poetryselfadd"poetry-dynamic-versioning[plugin]"Run the following command to install all dependencies, this package, and pre-commits.makerefreshDeployingA note to maintainers.We usebump-my-versionto release a new version.
This will create a git tag that is used bypoetry-dynamic-versionto generate version strings and updateCHANGELOG.md.For example, to bump theminorversion, you would run the following command.poetryrunbump-my-versionbumpminorAfter releasing a new version, you must push and include all tags.gitpush--follow-tagsLicenseCode contained in this project is released under theMIT Licenseas specified inLICENSE.
This license grants you the freedom to use, modify, and distribute it as long as you include the original copyright notice inLICENSEand the following notice.Portions of this code were incorporated and adapted with permission fromconda-poetry-liaisonby OASCI under theMIT License.