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] 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: