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

Dev #1

Merged
merged 66 commits into from
Nov 30, 2020
Merged

Dev #1

merged 66 commits into from
Nov 30, 2020

Conversation

RobertRosca
Copy link
Owner

@RobertRosca RobertRosca commented Nov 16, 2020

Pretty simple package, with a silly name: Venv in Parent IPykernel.

Working with venv's and jupyter can be a bit awkward since you have to activate the venv, then run python3 -m ipykernel install --user --name venvkernel-name, then in all the notebooks select that kernel, then before you commit the notebook remember to change it back to the default python3 as not everybody will have the same kernel/be using venvs.

The standard python3 kernel is just:

{
 "argv": [
  "/usr/bin/python3",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 3",
 "language": "python"
}

Which launches ipykernel with the system python3. This package overwrites the default kernel with:

{
 "argv": [
  "/usr/bin/python3",
  "-m",
  "vip_ipykernel_launcher",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 3",
 "language": "python"
}

Where the vip_ipykernel_launcher performs a search from the current directory up to the root directory, globbing for a .venv/bin/python3 or venv/bin/python3 along the way.

If it finds a match for a python3 executable in a venv directory, it then passes the subsequent arguments to it (i.e. -m ipykernel -f {connection_file}), which in the end replicates the standard kernel launch process.

Then you can install this kernel and launch a notebook in a project with a .venv in it, and that notebook will run with the correct python environment.

Anybody up for reviewing this? @tmichela @takluyver @antarcticrainforest

tests/test_nb.py Outdated Show resolved Hide resolved
tests/test_nb.py Outdated Show resolved Hide resolved
tests/test_nb.py Outdated Show resolved Hide resolved
@RobertRosca
Copy link
Owner Author

RobertRosca commented Nov 30, 2020

Think I covered all of your comments @takluyver, marked most of the comments as resolved but left a few unresolved for now, if you have anything to add to the remaining ones then feel free to do so when you have time or to mark them as resolved. For like the 8th time thank you for reviewing this, it was really useful!

@takluyver
Copy link

Just gave one last comment; otherwise I think it's fine, but I don't have a button to mark them as resolved. :-)

@RobertRosca RobertRosca merged commit c4fd673 into main Nov 30, 2020
@RobertRosca RobertRosca deleted the dev branch November 30, 2020 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants