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

Fix behavior when missing Pip #6020

Merged
merged 9 commits into from
Jan 22, 2025
Merged

Fix behavior when missing Pip #6020

merged 9 commits into from
Jan 22, 2025

Conversation

samclark2015
Copy link
Contributor

@samclark2015 samclark2015 commented Jan 16, 2025

When selecting an interpreter missing ipykernel, the UI prompt now states that both Pip and ipykernel must be installed. ProductInstaller logic was modified to pass flags to enable Pip to be installed automatically. Additional flags were set in ProductInstaller to enable the Pip install to respect the python.installModulesInTerminal setting.

Screenshot 2025-01-16 at 9 43 13 AM

Addresses #5505

Release Notes

New Features

  • N/A

Bug Fixes

  • N/A

QA Notes

Updated UI prompt to include Pip in the modules to be installed when missing, and updated installer logic to actually do that.
Copy link

github-actions bot commented Jan 16, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copy link

github-actions bot commented Jan 16, 2025

E2E Tests 🚀
This PR will run tests tagged with: @:critical

readme  valid tags

@samclark2015
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

Revised l10n call to conform better to the localization API
Mocked up environment to ensure that Pip gets installed when `ModuleInstallFlags.installPipIfRequired` is set
@samclark2015
Copy link
Contributor Author

Added a unit test to check the business logic of installing Pip; do we need an e2e test?

@samclark2015
Copy link
Contributor Author

P.S., a screencap of the new behavior:
https://github.com/user-attachments/assets/7c98e872-a40a-4480-870d-7ef9f1573727

@samclark2015 samclark2015 marked this pull request as ready for review January 16, 2025 22:03
Copy link
Contributor

@austin3dickey austin3dickey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, I tried it out and it seems to work well! (Can't tell if the test failures are related to this PR or not)

ModuleInstallFlags.installPipIfRequired,
);
expect(result).to.equal(InstallerResponse.Installed, 'Should be Installed');
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice test!

Also removes an unnecessary Positron overlay comment
Copy link
Contributor

@juliasilge juliasilge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great and working well for me!

With no pip or ipykernel (note that we should update the header as pointed out by @austin3dickey):

Screenshot 2025-01-17 at 10 24 23 AM

With no ipykernel only:

Screenshot 2025-01-17 at 10 26 04 AM

We mostly, sort of support uv right now and certainly want to do better for uv users as we move forward; what happens if someone is using uv? In term of us detecting if pip is there or not? See https://docs.astral.sh/uv/pip/compatibility/

And then same question for conda, which do expect to work in Positron well. I believe that currently for conda environments, the call to this.install() uses conda not pip.

Copy link
Contributor

@isabelizimm isabelizimm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't look like the tests failures are related to these changes since it looks like they're failing in setup (?). it might be worth trying to kick them off again. nice tests and the change looks reasonable to me!

@juliasilge
Copy link
Contributor

The CI failures definitely look unrelated, and sadly we are having some MASSIVE CI PROBLEMS right now as runners moved to Ubuntu 24. Let's not merge this until we get an all clear from QA folks on the situation on main.

@austin3dickey
Copy link
Contributor

what happens if someone is using uv?

FWIW I set up my local test by doing uv venv in the positron-python directory and picking the venv that was created there, since I think uv venvs don't come with pip by default.

@samclark2015
Copy link
Contributor Author

UV behavior: As Austin said, no Pip, but it gets installed per the new behavior. Is this what we want (vs. ipykernel getting installed directly by uv)?

Conda behavior: I created a conda environment with just Python (+ required dependencies). I got no prompt to install ipykernel when activating it in Positron. No ipykernel in the conda list output. Do we know if Conda has some integrated version of ipykernel?

@juliasilge
Copy link
Contributor

UV behavior: As Austin said, no Pip, but it gets installed per the new behavior. Is this what we want (vs. ipykernel getting installed directly by uv)?

I do not think we should install pip into uv environments, no. I don't know if we can install ipykernel into uv easily right now (does it exist as one of the installer types already?) but solving that is probably out of scope for this PR. Let's think about this PR as installing pip when needed for non-conda, non-uv environments.

@juliasilge
Copy link
Contributor

For conda, for learning mainly for you @samclark2015, can you step through with the debugger and see what is happening around here for conda:

const hasCompatibleKernel = await installer.isProductVersionCompatible(
Product.ipykernel,
IPYKERNEL_VERSION,
interpreter,
);

i.e. is the infrastructure already there checking if the conda env has appropriate ipykernel?

@samclark2015
Copy link
Contributor Author

The infrastructure does check for for ipykernel in conda environments; it was being bypassed due to ipykernel being installed in my user directory (~/.local/lib/python3.12/site-packages/ipykernel, this is Pip's default behavior when it's standard site-packages directory is read-only). 🤔 After ipykernel removing from there, the Positron installer behaves as expected for conda (i.e., detects no ipykernel in the conda env, installs it with conda).

Re UV: there is no infrastructure to install via UV, nor to even detect if it is a UV environment. Currently, it only detects Conda, Pipenv, and Poetry environments. If none of those match, it's declared a Pip environment and subsequently uses Pip to install the package.

Some questions:

  • Should we prevent Pip from installing ipykernel in this user directory?
  • Do we need to implement infrastructure for detecting a UV environment? (Perhaps out of scope for this PR)

@juliasilge
Copy link
Contributor

For uv, we've got a couple of other issues tracking better support:

The only thing I would advocate we do in this PR is if possible not install pip into uv (because I think that will be very weird/bad), but I am open to discussion on that, especially if we don't even have tools to see if we are in an uv env yet. If so, let's open a followup issue to address this. Our uv users will be able to workaround by installing ipykernel when setting up their environments (they have to do this now anyway, i.e. #3093).

@juliasilge
Copy link
Contributor

Should we prevent Pip from installing ipykernel in this user directory?

I am going to look to @austin3dickey and @isabelizimm for answers on this.

@samclark2015
Copy link
Contributor Author

samclark2015 commented Jan 17, 2025

The only thing I would advocate we do in this PR is if possible not install pip into uv (because I think that will be very weird/bad), but I am open to discussion on that, especially if we don't even have tools to see if we are in an uv env yet.

Doesn't look like there are tools to tell if it's UV; it's labeled as EnvironmentType.Venv. Perhaps we can discuss more in next week's sync?

@austin3dickey
Copy link
Contributor

The only thing I would advocate we do in this PR is if possible not install pip into uv

I don't think installing the pip package into a uv environment would be that bad; in fact their docs recognize that many projects have an undeclared dependency on pip and recommend installing pip if that's the case.

@isabelizimm
Copy link
Contributor

Are the conda problems happening because ipykernel is being installed in ~/.local instead of the conda environment, or that ipykernel was previously installed and we are looking in the wrong spot for pip/ipykernel? I think either of those two things could be addressed without blocking installation at a certain path. Historically, we have not prevented people from installing ipykernel anywhere (including in system or global Pythons 😬).

@samclark2015
Copy link
Contributor Author

ipykernel was previously installed and we are looking in the wrong spot for pip/ipykernel

Discussed, but for posterity, this is the case. It was previously installed in the user-local site-packages directory when selecting a system interpreter in a previous run.

When in a clean state, the installer uses conda to install ipykernel within a conda environment.

isabelizimm
isabelizimm previously approved these changes Jan 21, 2025
IModuleInstaller,
InterpreterUri,
ModuleInstallFlags,
} from '../../../client/common/installer/types';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit: can you pull these out into their own line? with // --- Start/End Positron ---

See: https://connect.posit.it/positron-wiki/overlay-strategy.html#a-note-on-imports

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.e. this? Will the lint check yell about importing the package multiple times?

Screenshot 2025-01-21 at 12 14 59 PM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to // eslint-disable-next-line no-duplicate-imports right above that line to ignore the yelling 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry - should have looked at the link more closely. 😅 Two notes:

  • Looks like the annotation is now import/no-duplicates... the no-duplicate-imports has no impact so it seems and errors with Definition for rule ... was not found.
  • With either annotation, the original import is still flagged. The first one at least satisfies ESLint for the added import.

Thoughts? Should the whole import block in the referenced commit just be wrapped with Positron markers?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh that is new! I don't have strong opinions here, but others might. (@seeM maybe?)

Copy link
Contributor

@juliasilge juliasilge Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if our advice is now outdated because of the change in imports in the recent upstream merge.

No wait actually, did it ever work in the Python extension?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@juliasilge juliasilge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still working great for pyenv, conda, venvs after the latest changes:

Screenshot 2025-01-22 at 9 41 33 AM

@samclark2015 samclark2015 merged commit 775a468 into main Jan 22, 2025
27 checks passed
@samclark2015 samclark2015 deleted the bugfix/prompt-install-pip branch January 22, 2025 17:36
@github-actions github-actions bot locked and limited conversation to collaborators Jan 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants