Skip to content

Commit 501e8e4

Browse files
authored
Non-hardcoded python version (#177) (#178)
* Non-hardcoded python version * Raise error if Python is not found * Fix syntax * Oups
1 parent 42c864a commit 501e8e4

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

jupyterlite_xeus/_pip.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,18 @@
55
from tempfile import TemporaryDirectory
66
from pathlib import Path
77
import csv
8-
from .constants import PYTHON_VERSION
8+
import json
9+
import glob
10+
11+
12+
def _get_python_version(prefix_path):
13+
path = glob.glob(f"{prefix_path}/conda-meta/python-3.*.json")
14+
15+
if not path:
16+
raise RuntimeError("Python needs to be installed for installing pip dependencies")
17+
18+
version = json.load(open(path[0]))["version"].split(".")
19+
return f"{version[0]}.{version[1]}"
920

1021

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

42+
python_version = _get_python_version(prefix_path)
43+
3144
subprocess_run(
3245
[
3346
sys.executable,
@@ -40,7 +53,7 @@ def _install_pip_dependencies(prefix_path, dependencies, log=None):
4053
pkg_dir.name,
4154
# Specify the right Python version
4255
"--python-version",
43-
PYTHON_VERSION,
56+
python_version,
4457
# No dependency installed
4558
"--no-deps",
4659
"--no-input",
@@ -85,7 +98,7 @@ def _install_pip_dependencies(prefix_path, dependencies, log=None):
8598
install_path = (
8699
prefix_path
87100
if not inside_site_packages
88-
else prefix_path / "lib" / f"python{PYTHON_VERSION}" / "site-packages"
101+
else prefix_path / "lib" / f"python{python_version}" / "site-packages"
89102
)
90103

91104
src_path = Path(pkg_dir.name) / file_path

jupyterlite_xeus/constants.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,3 @@
33

44
EXTENSION_NAME = "xeus"
55
STATIC_DIR = Path("@jupyterlite") / EXTENSION_NAME / "static"
6-
7-
8-
PYTHON_MAJOR = 3
9-
PYTHON_MINOR = 11
10-
PYTHON_VERSION = f"{PYTHON_MAJOR}.{PYTHON_MINOR}"

0 commit comments

Comments
 (0)