diff --git a/jupyterlite_xeus/_pip.py b/jupyterlite_xeus/_pip.py index b74249c..6ed0536 100644 --- a/jupyterlite_xeus/_pip.py +++ b/jupyterlite_xeus/_pip.py @@ -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 diff --git a/jupyterlite_xeus/constants.py b/jupyterlite_xeus/constants.py index 7690583..d1ddd3c 100644 --- a/jupyterlite_xeus/constants.py +++ b/jupyterlite_xeus/constants.py @@ -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}" diff --git a/jupyterlite_xeus/create_conda_env.py b/jupyterlite_xeus/create_conda_env.py index 61e7a2a..303380c 100644 --- a/jupyterlite_xeus/create_conda_env.py +++ b/jupyterlite_xeus/create_conda_env.py @@ -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