You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this conversation about CIME: ESMCI/cime#3886 (comment) @jhkennedy made clear that there are better ways for developers to run compass as a package while still developing.
First, we have a yaml file that defines the development environment that users can easily install for themselves, e.g.:
conda env create -f ./environment.yml
This way, we don't have do maintain a list of dependencies in the documentation itself. We would still need to have a yaml file for the development environment and another for the conda recipe, as far as I can tell.
Second, we should install the package to our own test environment in edit mode with:
python -m pip install -e .
This way, we can just do conda list, etc. instead of python -m conda list but you can still edit the code (in the repo) and have it update in the conda environment (which just points to the repo as I understand it).
This way, we don't have do maintain a list of dependencies in the documentation itself. We would still need to have a yaml file for the development environment and another for the conda recipe, as far as I can tell.
@xylar yeah, there's now way around duplicate dependency lists as far as I can tell -- usually there's 3 with when you're in the python + conda world:
we set this one up to be all the development dependencies needed, and use it for all the CI/CD pipelines, so it'll have, runtime dependencies, testing dependencies (e.g., flake8/pylint, pytest), packaging dependencies (e.g., wheel, twine) plus any additional things the team wants like jupyter
Runtime dependencies (things for pip to check when it installs)
you can also add a develop to extras_require and be able to do a python -m pip install -e .[develop] to get develop dependencies if you expect developers to use either conda or pip
One of the benefits of using the environment.yml file instead of a list in docs, is that the environment.yml file on main becomes the "official" list (instead of recipe/meta.yml) and when it comes to updating the recipe (new version released) you can just look at a the environment.yml file diff across version to see if you need to update the recipe:
That keeps all the dependency management tightly coupled to the repo and testing.
I'm realizing that the pip install -e approach won't be so easy for us. COMPASS needs system-built ESMF as well as a specific set of comilers, MPI and libraries like NetCDF and SCORPIO. Some experimentation has shown that these system libraries can't go in the conda environment because there are conflicts between system and conda libraries (no surprise, really). So our test deployment isn't going to be quite as simple as a developer creating their own test conda environment whenever they need it.
But hopefully with a little thought it can be close to that. Basically, a developer's environment could maybe be created with the equivalent of my deploy tools but into their own miniconda and with the name of their choice.
@jhkennedy, I have a question about conda env create that Googling hasn't been able to solve for me. Let's suppose I want to develop compass and mpas_tools simultaneously. As soon as MPAS-Dev/MPAS-Tools#418 goes in, I will be able to do:
It looks like this will work, based on my Googling. But it's annoying to me that the name of the environment is mpas_tools_dev unless I edit the dev_environment.yaml file to rename the environment. The --name flag to conda env create doesn't seem to work as I would expect, overriding the environment name. Instead, I get:
$ conda env create -n test -f ./dev_environment.yaml
SpecNotFound: Invalid name, try the format: user/package
Yeah, conda CLI arguments vs same arguments given in the YAML is weird and not always clear which is going to take precedence.
There are two "file" types in the conda world that can be used for environments as well, an envionment.yml and a spec-file.txt. environment.yml is used as discussed above by conda env commands, while spec-file.txt is used by the (maybe?) more familiar conda create/conda install commands and is pretty analogous to pip's requirements.txt.
Annoyingly, both of these are rather under-documented by conda (hmm, I suppose I should open a PR...), but you can glean most of the workings from their managing environments docs.
conda-file.txt
You can pass conda create/conda install a (or multiple) --file=spec-file.txt argument(s), and the packages specified within will be combined with the arguments given on the command line, with one big-fat gotcha (see below).
So for MPAS, where you'll want to use multiple dev tools in the same repo, you could instead follow a spec-file.txt pattern that'd look like:
(I can't remember if you need the = for the file argument, or if you can do both editable installs on the same line -- I did a deep dive into both environment.yml and spec-file.txt when I added support for them to tox-conda)
Getting multiple repos into a single dev environment (e.g., for a problem spanning a library + package) is something I still find kind of clunky and if you come up with something great, let me know!
Gotcha!
Both general dependencies (e.g., numpy>=1.17.5) and explicit dependencies (e.g., https://conda.anaconda.org/conda-forge/linux-64/numpy-1.17.5-py38h95a1406_0.tar.bz2) are allowed inside the spec-file.txt file, but explicit dependencies are not allowed to be mixed with general ones (you need to pick one style or the other). Additionally, if the @EXPLICIT header is in spec-file.txt, all general dependencies will be ignored, including those given on the command line. Notably
conda list --export > spec-file.txt will produce general dependencies
conda list --explicit > spec-file.txt will produce explicit dependencies with the @EXPLICIT header
I've done a lot of work based on this. I've got some nifty features lined up that will make our workflow more flexible and more similar between users and developers.
However, I'm waiting on conda-forge/staged-recipes#14775 (adding PNetCDF to conda-forge) before I roll out these changes because it will make setting up compass on Linux and OSX much easier. If that recipe doesn't get added soon, I may do an interim solution where I build the package myself for the e3sm channel.
Activity
xylar commentedon Apr 29, 2021
@jhkennedy, let me know if you have other tips for us.
jhkennedy commentedon Apr 29, 2021
@xylar yeah, there's now way around duplicate dependency lists as far as I can tell -- usually there's 3 with when you're in the python + conda world:
jupyterdeveloptoextras_requireand be able to do apython -m pip install -e .[develop]to get develop dependencies if you expect developers to use eithercondaorpipOne of the benefits of using the
environment.ymlfile instead of a list in docs, is that theenvironment.ymlfile on main becomes the "official" list (instead of recipe/meta.yml) and when it comes to updating the recipe (new version released) you can just look at a the environment.yml file diff across version to see if you need to update the recipe:That keeps all the dependency management tightly coupled to the repo and testing.
xylar commentedon Apr 29, 2021
I'm realizing that the
pip install -eapproach won't be so easy for us. COMPASS needs system-built ESMF as well as a specific set of comilers, MPI and libraries like NetCDF and SCORPIO. Some experimentation has shown that these system libraries can't go in the conda environment because there are conflicts between system and conda libraries (no surprise, really). So our test deployment isn't going to be quite as simple as a developer creating their own test conda environment whenever they need it.But hopefully with a little thought it can be close to that. Basically, a developer's environment could maybe be created with the equivalent of my
deploytools but into their ownminicondaand with the name of their choice.xylar commentedon May 1, 2021
@jhkennedy, I have a question about
conda env createthat Googling hasn't been able to solve for me. Let's suppose I want to developcompassandmpas_toolssimultaneously. As soon as MPAS-Dev/MPAS-Tools#418 goes in, I will be able to do:Then, I would want to install
compassand its dependencies into the environment so I would run something like:It looks like this will work, based on my Googling. But it's annoying to me that the name of the environment is
mpas_tools_devunless I edit thedev_environment.yamlfile to rename the environment. The--nameflag toconda env createdoesn't seem to work as I would expect, overriding the environment name. Instead, I get:Do you have any tips for handling this better?
xylar commentedon May 1, 2021
To answer my own question, it seems that
conda env updatedoes use the-nor--nameflag as I expect. So the following would work:jhkennedy commentedon May 1, 2021
Yeah, conda CLI arguments vs same arguments given in the YAML is weird and not always clear which is going to take precedence.
There are two "file" types in the conda world that can be used for environments as well, an
envionment.ymland aspec-file.txt.environment.ymlis used as discussed above byconda envcommands, whilespec-file.txtis used by the (maybe?) more familiarconda create/conda installcommands and is pretty analogous topip'srequirements.txt.Annoyingly, both of these are rather under-documented by conda (hmm, I suppose I should open a PR...), but you can glean most of the workings from their managing environments docs.
conda-file.txtYou can pass
conda create/conda installa (or multiple)--file=spec-file.txtargument(s), and the packages specified within will be combined with the arguments given on the command line, with one big-fat gotcha (see below).So for MPAS, where you'll want to use multiple dev tools in the same repo, you could instead follow a
spec-file.txtpattern that'd look like:(I can't remember if you need the
=for the file argument, or if you can do both editable installs on the same line -- I did a deep dive into bothenvironment.ymlandspec-file.txtwhen I added support for them totox-conda)Getting multiple repos into a single dev environment (e.g., for a problem spanning a library + package) is something I still find kind of clunky and if you come up with something great, let me know!
Gotcha!
Both general dependencies (e.g.,
numpy>=1.17.5) and explicit dependencies (e.g.,https://conda.anaconda.org/conda-forge/linux-64/numpy-1.17.5-py38h95a1406_0.tar.bz2) are allowed inside thespec-file.txtfile, but explicit dependencies are not allowed to be mixed with general ones (you need to pick one style or the other). Additionally, if the@EXPLICITheader is inspec-file.txt, all general dependencies will be ignored, including those given on the command line. Notablyconda list --export > spec-file.txtwill produce general dependenciesconda list --explicit > spec-file.txtwill produce explicit dependencies with the@EXPLICITheaderxylar commentedon May 2, 2021
Thanks @jhkennedy, this has given me a lot to work with.
xylar commentedon May 12, 2021
I've done a lot of work based on this. I've got some nifty features lined up that will make our workflow more flexible and more similar between users and developers.
However, I'm waiting on conda-forge/staged-recipes#14775 (adding PNetCDF to conda-forge) before I roll out these changes because it will make setting up
compasson Linux and OSX much easier. If that recipe doesn't get added soon, I may do an interim solution where I build the package myself for thee3smchannel.