pdm
                                
                                 pdm copied to clipboard
                                
                                    pdm copied to clipboard
                            
                            
                            
                        fix: properly handle interpreter resolution while importing
Pull Request Checklist
- [ ] A news fragment is added in news/describing what is new.
- [ ] Test cases added for changed code.
Describe what you have changed in this PR.
Add and use Project.resolve_interpreter(in_import=True) which does not memoize the result of resolution that uses a potentially incorrect requires-python information and does not create a virtualenv from this (potentially wrong) python version.
Additionally, the quality of informational output from Project.resolve_interpreter() is improved, hiding some misleading messages during the first resolution.
Fixes #2608.
This is too complex IMO. What you need is to revert all side-effect caused by Project.resolve_interpreter(), this is enough:
project._saved_python = None
project._python = None
@frostming Unfortunately, one of the side-effects of Project.resolve_interpreter() is creating a virtualenv.
Consider a project that has an upper-bound requires-python dependency, something like requires-python < 3.10 (together with a virtualenv provider that can satisfy such a dependency). In this case, the virtualenv will be created with a wrong python version, because it is created on the first resolution pass, where the bound is not yet known.
I agree that resolve_interpreter has too many side-effects and it's bad.
We need a side-effect-free version of it, no writing files, no saving states, no virtualenv creation. but in_import isn't a good name for it.
And I wonder if the side-effect version can call the side-effect-free version inside.
Fair enough, I'll think about it!
I am closing this PR, if you have further fixes feel free to open a new one.