Skip to content

Commit

Permalink
Improve logging and error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
renan-r-santos committed Nov 29, 2024
1 parent b6c8097 commit c865700
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ uv run tox run -e type_check

1. Bump
1. Increment version in `pyproject.toml`
2. Update all Pixi lock files by running `uv sync`
2. Update all lock files by running `uv sync -U` and `pixi update`
3. Commit with message "chore: Bump version number to X.Y.Z"
4. Push commit to GitHub
5. Check [CI](https://github.com/renan-r-santos/pixi-kernel/actions/workflows/ci.yml) to ensure
Expand Down
3 changes: 2 additions & 1 deletion src/pixi_kernel/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
PIXI_KERNEL_NOT_FOUND = """
To run the {kernel_name} kernel, you need to add the {required_package} package to
your project dependencies. You can do this by running 'pixi add {required_package}'
in your project directory and restarting your kernel.
in your project directory and restarting your kernel. Make sure the prefix {prefix}
points to the correct Pixi environment.
If you continue to face issues, report them at https://github.com/renan-r-santos/pixi-kernel/issues
"""
9 changes: 8 additions & 1 deletion src/pixi_kernel/pixi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import logging
import os
import shutil
import subprocess
Expand All @@ -12,6 +13,8 @@

MINIMUM_PIXI_VERSION = "0.30.0"

logger = logging.getLogger(__name__)


class PixiInfo(BaseModel):
environments: list[Environment] = Field(alias="environments_info")
Expand Down Expand Up @@ -75,6 +78,8 @@ def ensure_readiness(*, cwd: Path, required_package: str, kernel_name: str) -> E
capture_output=True,
text=True,
)
logger.info(f"pixi info stdout: {result.stdout}")
logger.info(f"pixi info stderr: {result.stderr}")
if result.returncode != 0:
raise RuntimeError(f"Failed to run 'pixi info': {result.stderr}")

Expand Down Expand Up @@ -108,7 +113,9 @@ def ensure_readiness(*, cwd: Path, required_package: str, kernel_name: str) -> E
if required_package not in dependencies:
raise RuntimeError(
PIXI_KERNEL_NOT_FOUND.format(
kernel_name=kernel_name, required_package=required_package
kernel_name=kernel_name,
required_package=required_package,
prefix=default_environment.prefix,
)
)

Expand Down
1 change: 1 addition & 0 deletions src/pixi_kernel/provisioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async def pre_launch(self, **kwargs: Any) -> dict[str, Any]:
raise ValueError("Pixi Kernel metadata is missing the 'required-package' key")

cwd = Path(kwargs.get("cwd", Path.cwd()))
logger.info(f"JupyterLab provided the following kwargs: {kwargs}")
logger.info(f"The current working directory is {cwd}")

environment = ensure_readiness(
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_pixi.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def test_missing_ipykernel():
PIXI_KERNEL_NOT_FOUND.format(
required_package=required_package,
kernel_name=kernel_name,
prefix="envs/default",
)
)
with pytest.raises(RuntimeError, match=message):
Expand Down

0 comments on commit c865700

Please sign in to comment.