Skip to content

Commit

Permalink
ENH: import Pixi environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Oct 18, 2024
1 parent ceff3f8 commit 4643f10
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 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 @@ -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()
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 4643f10

Please sign in to comment.