1515
1616from __future__ import annotations
1717
18+ import hashlib
1819import os
20+ import shutil
21+ import sys
22+ import tempfile
1923import warnings
2024from dataclasses import fields , is_dataclass , replace
2125from pathlib import Path
2226from typing import Any , cast
2327
24- import numpy as np
25- from absl .testing import absltest
26-
2728
2829def _configure_matplotlib () -> None :
2930 """Configure Matplotlib without importing EnvPool's Jumanji package."""
@@ -39,7 +40,53 @@ def _configure_matplotlib() -> None:
3940 os .environ ["MPLCONFIGDIR" ] = str (mpl_config )
4041
4142
43+ def _shorten_windows_oracle_site_packages () -> None :
44+ """Copy oracle wheels to a short path before loading Windows extensions."""
45+ if os .name != "nt" :
46+ return
47+
48+ oracle_sites : list [Path ] = []
49+ for entry in sys .path :
50+ if "jumanji_oracle_requirements" not in str (entry ):
51+ continue
52+ path = Path (entry )
53+ if path .name == "site-packages" :
54+ oracle_sites .append (path )
55+ if not oracle_sites :
56+ return
57+
58+ key = hashlib .sha1 (
59+ "|" .join (str (path ) for path in oracle_sites ).encode ("utf-8" )
60+ ).hexdigest ()[:12 ]
61+ short_site = Path (tempfile .gettempdir ()) / "ej_o" / key / "s"
62+ marker = short_site / ".copied"
63+ if not marker .exists ():
64+ short_site .mkdir (parents = True , exist_ok = True )
65+ for site in oracle_sites :
66+ for src in site .iterdir ():
67+ if src .name == "__pycache__" :
68+ continue
69+ dst = short_site / src .name
70+ if src .is_dir ():
71+ shutil .copytree (
72+ src ,
73+ dst ,
74+ dirs_exist_ok = True ,
75+ ignore = shutil .ignore_patterns ("__pycache__" ),
76+ )
77+ else :
78+ shutil .copy2 (src , dst )
79+ marker .write_text ("ok" )
80+
81+ sys .path [:] = [str (short_site )] + [
82+ entry
83+ for entry in sys .path
84+ if "jumanji_oracle_requirements" not in str (entry )
85+ ]
86+
87+
4288_configure_matplotlib ()
89+ _shorten_windows_oracle_site_packages ()
4390warnings .filterwarnings (
4491 "ignore" ,
4592 message = "FigureCanvasAgg is non-interactive.*" ,
@@ -55,6 +102,8 @@ def _configure_matplotlib() -> None:
55102import jax # noqa: E402
56103import jax .numpy as jnp # noqa: E402
57104import jumanji # noqa: E402
105+ import numpy as np # noqa: E402
106+ from absl .testing import absltest # noqa: E402
58107from jumanji .environments .routing .sokoban .generator import ( # noqa: E402
59108 SimpleSolveGenerator ,
60109)
0 commit comments