conda / conda-lock

Lightweight lockfile for conda environments
https://conda.github.io/conda-lock/
Other
488 stars 103 forks source link

Lock file for `kind=env` should be alphabetized #554

Closed jamesmyatt closed 9 months ago

jamesmyatt commented 10 months ago

Checklist

What is the idea?

Like https://github.com/conda/conda-lock/issues/491 and https://github.com/conda/conda-lock/pull/524, the kind=env lock files should also have the entries sorted. This is required to match the output produced by conda env export.

Why is this needed?

This enables diff of outputs with conda env export. As well as matching the behaviour of the v2 lock file and producing a stable order.

What should happen?

No response

Additional Context

No response

maresb commented 10 months ago

@jamesmyatt, thanks for opening this.

To be clear, this is a feature request and not a bug report, right? (With the release of v2.5.0 today I'm really hoping for no regressions.)

jamesmyatt commented 10 months ago

Yes. I'm pretty sure it's not a regression.

maresb commented 10 months ago

Excellent, that's a relief 😅

I think this would be straightforward, and effectively an aesthetic change. Would you be able to write a PR?

If there is one, probably we want to put the pip: list at the end? In that case, I wonder if the - pip item should go in order or above pip:? Probably makes sense to do whatever conda env export does... if it even makes a pip: section at all?

jamesmyatt commented 10 months ago

Is it just a matter of putting an if kind == ... around https://github.com/conda/conda-lock/blob/6d1273c079c0ca8d70ee5b355e5a063a0c351ec1/conda_lock/conda_lock.py#L611C1-L611C1 and using lockfile.alphasort_inplace?

jamesmyatt commented 10 months ago

conda env export seems to do all of the conda requirements (including pip itself) alphabetically and then all of the pip requirements alphabetically. I think you already have this. It's just a matter of using the method from #524. I think.