Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: add support for Pixi activation in Binder #448

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions src/compwa_policy/check_dev_files/binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from __future__ import annotations

import os
from dataclasses import dataclass
from textwrap import dedent
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -74,9 +75,15 @@ def __get_post_builder_for_pixi_with_uv() -> str:
if [[ -n "$pixi_packages" ]]; then
pixi global install $pixi_packages
fi
pixi clean cache --yes
""").strip()
expected_content += "\n"
activation = ___get_pixi_activation()
if activation.environment:
for key, value in activation.environment.items():
expected_content += f'\nexport {key}="{value}"'
if activation.scripts:
for script in activation.scripts:
expected_content += "\nbash " + script
expected_content += "\npixi clean cache --yes\n"
notebook_extras = __get_notebook_extras()
if "uv.lock" in set(git_ls_files(untracked=True)):
expected_content += "\nuv export \\"
Expand All @@ -102,6 +109,25 @@ def __get_post_builder_for_pixi_with_uv() -> str:
return expected_content


@dataclass
class PixiActivation:
scripts: list[str] | None = None
environment: dict[str, str] | None = None


def ___get_pixi_activation() -> PixiActivation:
if not CONFIG_PATH.pixi_toml.exists():
return PixiActivation()
pixi = Pyproject.load(CONFIG_PATH.pixi_toml)
if not pixi.has_table("activation"):
return PixiActivation()
activation = pixi.get_table("activation")
return PixiActivation(
scripts=activation.get("scripts"),
environment=activation.get("env"),
)


def __get_post_builder_for_uv() -> str:
expected_content = dedent("""
#!/bin/bash
Expand Down
Loading