Skip to content

Commit

Permalink
Revert "Use Python version from environment (#174)" (#176)
Browse files Browse the repository at this point in the history
This reverts commit 87e04af.
martinRenou authored Jan 30, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 87e04af commit 99faca6
Showing 3 changed files with 13 additions and 21 deletions.
7 changes: 4 additions & 3 deletions jupyterlite_xeus/_pip.py
Original file line number Diff line number Diff line change
@@ -5,9 +5,10 @@
from tempfile import TemporaryDirectory
from pathlib import Path
import csv
from .constants import PYTHON_VERSION


def _install_pip_dependencies(prefix_path, dependencies, python_version, log=None):
def _install_pip_dependencies(prefix_path, dependencies, log=None):
# Why is this so damn complicated?
# Isn't it easier to download the .whl ourselves? pip is hell

@@ -39,7 +40,7 @@ def _install_pip_dependencies(prefix_path, dependencies, python_version, log=Non
pkg_dir.name,
# Specify the right Python version
"--python-version",
python_version,
PYTHON_VERSION,
# No dependency installed
"--no-deps",
"--no-input",
@@ -84,7 +85,7 @@ def _install_pip_dependencies(prefix_path, dependencies, python_version, log=Non
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
5 changes: 5 additions & 0 deletions jupyterlite_xeus/constants.py
Original file line number Diff line number Diff line change
@@ -3,3 +3,8 @@

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


PYTHON_MAJOR = 3
PYTHON_MINOR = 11
PYTHON_VERSION = f"{PYTHON_MAJOR}.{PYTHON_MINOR}"
22 changes: 4 additions & 18 deletions jupyterlite_xeus/create_conda_env.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import shutil
import sys
from pathlib import Path
@@ -67,7 +66,7 @@ def create_conda_env_from_specs(
channels,
pip_dependencies=None,
):
python_version = _create_conda_env_from_specs_impl(
_create_conda_env_from_specs_impl(
env_name=env_name,
root_prefix=root_prefix,
specs=specs,
@@ -77,7 +76,6 @@ def create_conda_env_from_specs(
_install_pip_dependencies(
prefix_path=Path(root_prefix) / "envs" / env_name,
dependencies=pip_dependencies,
python_version=python_version,
)


@@ -102,12 +100,11 @@ def _create_conda_env_from_specs_impl(env_name, root_prefix, specs, channels):
channels_args.extend(["-c", channel])

if MICROMAMBA_COMMAND:
res = subprocess_run(
subprocess_run(
[
MICROMAMBA_COMMAND,
"create",
"--yes",
"--json",
"--no-pyc",
"--root-prefix",
root_prefix,
@@ -118,9 +115,8 @@ def _create_conda_env_from_specs_impl(env_name, root_prefix, specs, channels):
*specs,
],
check=True,
capture_output=True,
)
return _get_python_version(res.stdout)
return

if MAMBA_COMMAND:
# Mamba needs the directory to exist already
@@ -143,32 +139,22 @@ def _create_env_with_config(conda, prefix_path, specs, channels_args):
check=True,
)
_create_config(prefix_path)
res = subprocess_run(
subprocess_run(
[
conda,
"install",
"--yes",
"--json",
"--prefix",
prefix_path,
*channels_args,
*specs,
],
check=True,
capture_output=True,
env=os.environ.copy(),
)
return _get_python_version(res.stdout)


def _create_config(prefix_path):
with open(prefix_path / ".condarc", "w") as fobj:
fobj.write(f"subdir: {PLATFORM}")
os.environ["CONDARC"] = str(prefix_path / ".condarc")


def _get_python_version(json_str):
for entry in [entry for entry in json.loads(json_str)["actions"]["LINK"] if entry["name"] == "python"]:
python_version = entry["version"]
python_version = python_version[:python_version.rfind(".")]
return python_version

0 comments on commit 99faca6

Please sign in to comment.