diff --git a/pyproject.toml b/pyproject.toml index 0f79fda..15bafcb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -83,6 +83,7 @@ strict = true [tool.pytest.ini_options] addopts = ["--strict-config", "--strict-markers"] asyncio_default_fixture_loop_scope = "function" +asyncio_mode = "auto" filterwarnings = [ "ignore:Jupyter is migrating its paths to use standard platformdirs", ] diff --git a/src/pixi_kernel/pixi.py b/src/pixi_kernel/pixi.py index f82aa63..24b591d 100644 --- a/src/pixi_kernel/pixi.py +++ b/src/pixi_kernel/pixi.py @@ -31,7 +31,7 @@ class Project(BaseModel): manifest_path: str -def ensure_readiness( +async def ensure_readiness( *, cwd: Path, env: dict[str, str], diff --git a/src/pixi_kernel/provisioner.py b/src/pixi_kernel/provisioner.py index c28d2f9..443b5e9 100644 --- a/src/pixi_kernel/provisioner.py +++ b/src/pixi_kernel/provisioner.py @@ -35,7 +35,7 @@ async def pre_launch(self, **kwargs: Any) -> dict[str, Any]: logger.info(f"The current working directory is {cwd}") env: dict[str, str] = kwargs.get("env", os.environ) - pixi_environment = ensure_readiness( + pixi_environment = await ensure_readiness( cwd=cwd.resolve(), env=env, required_package=required_package, diff --git a/tests/unit/test_pixi.py b/tests/unit/test_pixi.py index c62d43d..0747dd3 100644 --- a/tests/unit/test_pixi.py +++ b/tests/unit/test_pixi.py @@ -20,34 +20,34 @@ @pytest.mark.usefixtures("_patch_path") -def test_pixi_not_installed(): +async def test_pixi_not_installed(): message = re.escape(PIXI_NOT_FOUND.format(kernel_name="Pixi")) with pytest.raises(RuntimeError, match=message): - ensure_readiness( + await ensure_readiness( cwd=Path.cwd(), env=os.environ.copy(), required_package="pixi", kernel_name="Pixi" ) @pytest.mark.usefixtures("_patch_pixi_version_exit_code") -def test_pixi_version_bad_exit_code(): +async def test_pixi_version_bad_exit_code(): message = re.escape(PIXI_VERSION_ERROR.format(kernel_name="Pixi")) with pytest.raises(RuntimeError, match=message): - ensure_readiness( + await ensure_readiness( cwd=Path.cwd(), env=os.environ.copy(), required_package="pixi", kernel_name="Pixi" ) @pytest.mark.usefixtures("_patch_pixi_version_stdout") -def test_pixi_version_bad_stdout(): +async def test_pixi_version_bad_stdout(): message = re.escape(PIXI_VERSION_ERROR.format(kernel_name="Pixi")) with pytest.raises(RuntimeError, match=message): - ensure_readiness( + await ensure_readiness( cwd=Path.cwd(), env=os.environ.copy(), required_package="pixi", kernel_name="Pixi" ) @pytest.mark.usefixtures("_patch_pixi_version") -def test_outdated_pixi(): +async def test_outdated_pixi(): message = re.escape( PIXI_OUTDATED.format( kernel_name="Pixi", @@ -55,32 +55,32 @@ def test_outdated_pixi(): ) ) with pytest.raises(RuntimeError, match=message): - ensure_readiness( + await ensure_readiness( cwd=Path.cwd(), env=os.environ.copy(), required_package="pixi", kernel_name="Pixi" ) @pytest.mark.usefixtures("_patch_pixi_info_exit_code") -def test_pixi_info_bad_exit_code(): +async def test_pixi_info_bad_exit_code(): message = re.escape("Failed to run 'pixi info': error") with pytest.raises(RuntimeError, match=message): - ensure_readiness( + await ensure_readiness( cwd=Path.cwd(), env=os.environ.copy(), required_package="pixi", kernel_name="Pixi" ) @pytest.mark.usefixtures("_patch_pixi_info_stdout") -def test_pixi_info_bad_stdout(): +async def test_pixi_info_bad_stdout(): message = re.escape( ("Failed to parse 'pixi info' output: not JSON\n1 validation error for PixiInfo") ) with pytest.raises(RuntimeError, match=message): - ensure_readiness( + await ensure_readiness( cwd=Path.cwd(), env=os.environ.copy(), required_package="pixi", kernel_name="Pixi" ) -def test_empty_project(): +async def test_empty_project(): cwd = Path("/") assert not (cwd / "pixi.toml").exists(), "You should not have a pixi.toml file in /" assert not (cwd / "pyproject.toml").exists(), "You should not have a pyproject.toml file in /" @@ -89,30 +89,30 @@ def test_empty_project(): "could not find pixi.toml or pyproject.toml which is configured to use pixi" ) with pytest.raises(RuntimeError, match=message): - ensure_readiness( + await ensure_readiness( cwd=cwd, env=os.environ.copy(), required_package="pixi", kernel_name="Pixi" ) -def test_bad_pixi_toml(): +async def test_bad_pixi_toml(): cwd = data_dir / "bad_pixi_toml" message = re.escape("failed to parse project manifest") + "|" + re.escape("unknown field") with pytest.raises(RuntimeError, match=message): - ensure_readiness( + await ensure_readiness( cwd=cwd, env=os.environ.copy(), required_package="pixi", kernel_name="Pixi" ) @pytest.mark.usefixtures("_patch_pixi_info_no_default_env") -def test_missing_default_environment(): +async def test_missing_default_environment(): message = re.escape("Default Pixi environment not found.") with pytest.raises(RuntimeError, match=message): - ensure_readiness( + await ensure_readiness( cwd=Path.cwd(), env=os.environ.copy(), required_package="pixi", kernel_name="Pixi" ) -def test_missing_ipykernel(): +async def test_missing_ipykernel(): cwd = data_dir / "missing_ipykernel" required_package = "ipykernel" kernel_name = "Python (Pixi)" @@ -125,7 +125,7 @@ def test_missing_ipykernel(): ) ) with pytest.raises(RuntimeError, match=message): - ensure_readiness( + await ensure_readiness( cwd=cwd, env=os.environ.copy(), required_package=required_package, @@ -133,14 +133,14 @@ def test_missing_ipykernel(): ) -def test_non_existing_dependency(): +async def test_non_existing_dependency(): cwd = data_dir / "non_existing_dependency" required_package = "ipykernel" kernel_name = "Python (Pixi)" message = re.escape("Failed to run 'pixi install':") with pytest.raises(RuntimeError, match=message): - ensure_readiness( + await ensure_readiness( cwd=cwd, env=os.environ.copy(), required_package=required_package, @@ -148,12 +148,12 @@ def test_non_existing_dependency(): ) -def test_pixi_project(): +async def test_pixi_project(): cwd = data_dir / "pixi_project" required_package = "ipykernel" kernel_name = "Python (Pixi)" - environment = ensure_readiness( + environment = await ensure_readiness( cwd=cwd, env=os.environ.copy(), required_package=required_package, @@ -162,12 +162,12 @@ def test_pixi_project(): assert Path(environment.prefix).parts[-2:] == ("envs", "default") -def test_pyproject_project(): +async def test_pyproject_project(): cwd = data_dir / "pyproject_project" required_package = "ipykernel" kernel_name = "Python (Pixi)" - environment = ensure_readiness( + environment = await ensure_readiness( cwd=cwd, env=os.environ.copy(), required_package=required_package, @@ -202,12 +202,12 @@ def env_for_pixi_in_pixi(): # https://github.com/renan-r-santos/pixi-kernel/issues/35 @pytest.mark.skipif(sys.platform == "win32", reason="No need to write Windows-specific code here") -def test_pixi_in_pixi(env_for_pixi_in_pixi: dict[str, str]): +async def test_pixi_in_pixi(env_for_pixi_in_pixi: dict[str, str]): cwd = data_dir / "pixi_in_pixi" / "good_project" required_package = "ipykernel" kernel_name = "Python (Pixi)" - environment = ensure_readiness( + environment = await ensure_readiness( cwd=cwd, env=env_for_pixi_in_pixi, required_package=required_package,