Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pinning python version in the created environment #114

Open
jaimergp opened this issue Nov 27, 2020 · 11 comments · Fixed by #190
Open

Pinning python version in the created environment #114

jaimergp opened this issue Nov 27, 2020 · 11 comments · Fixed by #190
Labels
type:bug Something isn't working
Milestone

Comments

@jaimergp
Copy link
Member

Just ran into a weird issue. Some complex environment files will happily downgrade (and I guess also upgrade) Python versions to solve the environment.

% conda create -n py39 python=3.9
% conda activate py39
% conda env update -f teachopencadd.yml

, where teachopencadd.yml is this file.

That example above will downgrade Python to 3.8, silently! As a result, my CI branch is NOT testing Python 3.9 at all! See this in live action here.

To avoid that problem (there's no conda-env flag to avoid that behavior), I suggest pinning Python in that environment with

echo "python 3.9.*" > $CONDA_PREFIX/conda-meta/pinned

Even with that pinning, conda env STILL ignores that but at least a warning is now shown:

 - WARNING conda.core.solve:_add_specs(611): pinned spec python=3.9 conflicts with explicit specs.  Overriding pinned spec.

We might want to catch that warning and thrown an error instead because this kind of behavior in a CI context is very unexpected.

Alternatively, we might want to check the output of python -V once everything is installed and see if it matches python-version, but I think that's a bit more complicated?

Question is: should we always pin Python if python-version was specified? I can't think of any example where not doing this would lead to surprising behaviour, but happy to discuss!

@jaimergp
Copy link
Member Author

I added an extra CI step for now:

      #  After setup-miniconda
      - name: Ensure we have the right Python
        shell: bash -l {0}
        run: |
          echo "Installed Python: $(python --version)"
          echo "Expected: ${{ matrix.python-version }}"
          python --version | grep "Python ${{ matrix.python-version }}"

@goanpeca
Copy link
Member

goanpeca commented Nov 27, 2020

Hi @jaimergp, thanks for the thorough report and explanation. This is indeed an issue I was worrying some day will happen :), having the loose python version is not a guarantee (in very specific environments)

We could look at and test

https://docs.conda.io/projects/conda/en/latest/configuration.html

# # pinned_packages (sequence: primitive)
# #   env var string delimiter: '&'
# #   A list of package specs to pin for every environment resolution. This
# #   parameter is in BETA, and its behavior may change in a future release.
# # 
# pinned_packages: []

We could also inject the dependency on the yaml file. If no yaml file is used, well then it means the user is in charge of intaling hs things.

Even with that pinning, conda env STILL ignores that but at least a warning is now shown:

Yeah that is a very odd behavior... and still there... conda/conda#9016

A pin is a pin, and specified in a file there is no reason for it to be ignored., unless --no-pin was used.

Question is: should we always pin Python if python-version was specified? I can't think of any example where not doing this would lead to surprising behaviour, but happy to discuss!

Can't think of one either, so yes either pin + updating the yaml file by injecting the python=python-version. I think the yaml one would be much easier and actually failed with the right error if not possible to satisfy.

@goanpeca goanpeca added the type:bug Something isn't working label Nov 27, 2020
@bollwyvl
Copy link
Contributor

bollwyvl commented Nov 27, 2020 via email

@goanpeca
Copy link
Member

Hi @bollwyvl thanks for the input.

I prefer exposing one off options than the yaml in yaml option.

These options are fine as they are conda config options so except for the "complex" ones the rest should probably be exposed to be used in the with:

Unless I did not understand things correctly 🙃

@bollwyvl
Copy link
Contributor

bollwyvl commented Nov 27, 2020 via email

@goanpeca
Copy link
Member

Ok I understood correctly :-p

actions.yml is a pretty poor
specification language, even weaker than JSON Schema, and we do very little
checking on them anyhow because everything comes in as "a string".

True, may be extra work on our side to maintain but providing options, keeps providing the best UX and that is important too.

@bollwyvl
Copy link
Contributor

Whew, "best UX" would likely be a whole shooting match of gathering a bunch of observational data (e.g. survey, poll, etc).

@goanpeca goanpeca added this to the v2.1.0 milestone Nov 29, 2020
@bollwyvl
Copy link
Contributor

As of master, and at some complexity, if python-version is specified along with a YAML file, it will actually build a temporary file with the full spec to python specified:

https://github.com/conda-incubator/setup-miniconda/blob/master/src/env/yaml.ts#L44

This should save us both the initial env spin-up, as well as only consider your new, confected environment, in this case with - python=3.9.

We should probably add a test for this scenario.

@goanpeca
Copy link
Member

Just checking @bollwyvl, is this solved by the latest work you did?

@bollwyvl
Copy link
Contributor

bollwyvl commented Dec 30, 2020 via email

@huangliang0828
Copy link

I meet the same problems in win10 conda64 python3.8 & python 3.9,the pinned file in conda-meta folder was ignoreed or overrided, I hope there will be a good solution

@goanpeca goanpeca modified the milestones: v2.2.0, v3.0.0 Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants