From ceff3f8239a8d868cfbde3149bebf9770ba3d369 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:28:22 +0200 Subject: [PATCH 1/2] ENH: add support for Pixi activation scripts --- src/compwa_policy/check_dev_files/binder.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/compwa_policy/check_dev_files/binder.py b/src/compwa_policy/check_dev_files/binder.py index a6c936d7..c289bf3d 100644 --- a/src/compwa_policy/check_dev_files/binder.py +++ b/src/compwa_policy/check_dev_files/binder.py @@ -74,9 +74,12 @@ 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_scripts = ___get_pixi_activation_scripts() + 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 \\" @@ -102,6 +105,16 @@ def __get_post_builder_for_pixi_with_uv() -> str: return expected_content +def ___get_pixi_activation_scripts() -> list[str] | None: + if not CONFIG_PATH.pixi_toml.exists(): + return None + pixi = Pyproject.load(CONFIG_PATH.pixi_toml) + if not pixi.has_table("activation"): + return None + activation = pixi.get_table("activation") + return activation.get("scripts") + + def __get_post_builder_for_uv() -> str: expected_content = dedent(""" #!/bin/bash From 4643f106b79a15743bd302412910056fe646279b Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Fri, 18 Oct 2024 09:34:55 +0200 Subject: [PATCH 2/2] ENH: import Pixi environment variables --- src/compwa_policy/check_dev_files/binder.py | 27 +++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/compwa_policy/check_dev_files/binder.py b/src/compwa_policy/check_dev_files/binder.py index c289bf3d..6ce23101 100644 --- a/src/compwa_policy/check_dev_files/binder.py +++ b/src/compwa_policy/check_dev_files/binder.py @@ -6,6 +6,7 @@ from __future__ import annotations import os +from dataclasses import dataclass from textwrap import dedent from typing import TYPE_CHECKING @@ -75,9 +76,12 @@ def __get_post_builder_for_pixi_with_uv() -> str: pixi global install $pixi_packages fi """).strip() - activation_scripts = ___get_pixi_activation_scripts() - if activation_scripts: - for script in activation_scripts: + 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() @@ -105,14 +109,23 @@ def __get_post_builder_for_pixi_with_uv() -> str: return expected_content -def ___get_pixi_activation_scripts() -> list[str] | None: +@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 None + return PixiActivation() pixi = Pyproject.load(CONFIG_PATH.pixi_toml) if not pixi.has_table("activation"): - return None + return PixiActivation() activation = pixi.get_table("activation") - return activation.get("scripts") + return PixiActivation( + scripts=activation.get("scripts"), + environment=activation.get("env"), + ) def __get_post_builder_for_uv() -> str: