Skip to content

Investigate using pip install -e #91

Closed

Description

@xylar

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).

Activity

  1. added
    python package
    on Apr 29, 2021
  2. self-assigned this
    on Apr 29, 2021
  3. xylar commented on Apr 29, 2021

    @xylar
    CollaboratorAuthor

    @jhkennedy, let me know if you have other tips for us.

  4. added
    enhancement
    and removed on Apr 29, 2021
  5. jhkennedy commented on Apr 29, 2021

    @jhkennedy

    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:

    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:

    image

    That keeps all the dependency management tightly coupled to the repo and testing.

  6. xylar commented on Apr 29, 2021

    @xylar
    CollaboratorAuthor

    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.

  7. xylar commented on May 1, 2021

    @xylar
    CollaboratorAuthor

    @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:

    cd conda_package
    conda env create -f ./dev_environment.yaml
    conda activate mpas_tools_dev
    python -m pip install -e .
    

    Then, I would want to install compass and its dependencies into the environment so I would run something like:

    cd ~/mpas_work/compass/compass
    conda env update -f ./dev_environment.yaml
    python -m pip install -e .
    

    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
    

    Do you have any tips for handling this better?

  8. xylar commented on May 1, 2021

    @xylar
    CollaboratorAuthor

    To answer my own question, it seems that conda env update does use the -n or --name flag as I expect. So the following would work:

    conda create -y -n test python=3.8
    conda activate test
    
    cd ~/mpas_work/mpas_tools/mpas_tools/conda_package
    conda env update -n test -f ./dev_environment.yaml
    python -m pip install -e .
    
    cd ~/mpas_work/compass/compass
    conda env update -n test -f ./dev_environment.yaml
    python -m pip install -e .
    
  9. jhkennedy commented on May 1, 2021

    @jhkennedy

    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:

    cd ~/mpas_work
    conda create -y -n test python=3.8 \
        --file=mpas_tools/mpas_tools/conda_package/dev-spec.txt \
        --file=ompass/compass/dev-spec.txt
    python -m pip install -e ./mpas_tools/mpas_tools/conda_package
    python -m pip install -e ./compass/compass
    

    (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
  10. xylar commented on May 2, 2021

    @xylar
    CollaboratorAuthor

    Thanks @jhkennedy, this has given me a lot to work with.

  11. xylar commented on May 12, 2021

    @xylar
    CollaboratorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementpython package

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions