Skip to content

Commit

Permalink
Non-hardcoded python version (jupyterlite#177)
Browse files Browse the repository at this point in the history
* Non-hardcoded python version

* Raise error if Python is not found

* Fix syntax

* Oups
  • Loading branch information
martinRenou committed Jan 30, 2025
1 parent 42c864a commit 616905e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
19 changes: 16 additions & 3 deletions jupyterlite_xeus/_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@
from tempfile import TemporaryDirectory
from pathlib import Path
import csv
from .constants import PYTHON_VERSION
import json
import glob


def _get_python_version(prefix_path):
path = glob.glob(f"{prefix_path}/conda-meta/python-3.*.json")

if not path:
raise RuntimeError("Python needs to be installed for installing pip dependencies")

version = json.load(open(path[0]))["version"].split(".")
return f"{version[0]}.{version[1]}"


def _install_pip_dependencies(prefix_path, dependencies, log=None):
Expand All @@ -28,6 +39,8 @@ def _install_pip_dependencies(prefix_path, dependencies, log=None):
# So we need to do this whole mess "manually"
pkg_dir = TemporaryDirectory()

python_version = _get_python_version(prefix_path)

subprocess_run(
[
sys.executable,
Expand All @@ -40,7 +53,7 @@ def _install_pip_dependencies(prefix_path, dependencies, log=None):
pkg_dir.name,
# Specify the right Python version
"--python-version",
PYTHON_VERSION,
python_version,
# No dependency installed
"--no-deps",
"--no-input",
Expand Down Expand Up @@ -85,7 +98,7 @@ def _install_pip_dependencies(prefix_path, dependencies, log=None):
install_path = (
prefix_path
if not inside_site_packages
else prefix_path / "lib" / f"python{PYTHON_VERSION}" / "site-packages"
else prefix_path / "lib" / f"python{python_version}" / "site-packages"
)

src_path = Path(pkg_dir.name) / file_path
Expand Down
5 changes: 0 additions & 5 deletions jupyterlite_xeus/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,3 @@

EXTENSION_NAME = "xeus"
STATIC_DIR = Path("@jupyterlite") / EXTENSION_NAME / "static"


PYTHON_MAJOR = 3
PYTHON_MINOR = 11
PYTHON_VERSION = f"{PYTHON_MAJOR}.{PYTHON_MINOR}"

0 comments on commit 616905e

Please sign in to comment.