xoscar 0.7.11__cp39-cp39-macosx_11_0_arm64.whl → 0.7.13__cp39-cp39-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of xoscar might be problematic. Click here for more details.

Binary file
Binary file
Binary file
xoscar/virtualenv/core.py CHANGED
@@ -29,7 +29,13 @@ class VirtualEnvManager(ABC):
29
29
  self.env_path = env_path.resolve()
30
30
 
31
31
  @abstractmethod
32
- def create_env(self, python_path: Path | None = None) -> None:
32
+ def exists_env(self) -> bool:
33
+ pass
34
+
35
+ @abstractmethod
36
+ def create_env(
37
+ self, python_path: Path | None = None, exists: str = "ignore"
38
+ ) -> None:
33
39
  pass
34
40
 
35
41
  @abstractmethod
xoscar/virtualenv/uv.py CHANGED
@@ -16,17 +16,24 @@ from __future__ import annotations
16
16
 
17
17
  import logging
18
18
  import os
19
+ import re
19
20
  import shutil
20
21
  import subprocess
21
22
  import sys
22
23
  import sysconfig
24
+ import tempfile
25
+ from importlib.metadata import distributions
23
26
  from pathlib import Path
24
27
  from typing import Optional
25
28
 
29
+ from packaging.requirements import Requirement
30
+ from packaging.version import Version
31
+
26
32
  from .core import VirtualEnvManager
27
33
  from .utils import run_subprocess_with_logger
28
34
 
29
35
  UV_PATH = os.getenv("XOSCAR_UV_PATH")
36
+ SKIP_INSTALLED = bool(int(os.getenv("XOSCAR_VIRTUAL_ENV_SKIP_INSTALLED", "0")))
30
37
  logger = logging.getLogger(__name__)
31
38
 
32
39
 
@@ -46,7 +53,8 @@ class UVVirtualEnvManager(VirtualEnvManager):
46
53
  return True
47
54
  return shutil.which("uv") is not None
48
55
 
49
- def create_env(self, python_path: Path | None = None) -> None:
56
+ @staticmethod
57
+ def _get_uv_path() -> str:
50
58
  if (uv_path := UV_PATH) is None:
51
59
  try:
52
60
  from uv import find_uv_bin
@@ -55,7 +63,46 @@ class UVVirtualEnvManager(VirtualEnvManager):
55
63
  except (ImportError, FileNotFoundError):
56
64
  logger.warning("Fail to find uv bin, use system one")
57
65
  uv_path = "uv"
66
+ return uv_path
67
+
68
+ def exists_env(self) -> bool:
69
+ """Check if virtual environment already exists."""
70
+ return self.env_path.exists() and (self.env_path / "pyvenv.cfg").exists()
71
+
72
+ def create_env(
73
+ self, python_path: Path | None = None, exists: str = "ignore"
74
+ ) -> None:
75
+ """
76
+ Create virtual environment.
77
+
78
+ Args:
79
+ python_path: Path to Python interpreter to use
80
+ exists: How to handle existing environment:
81
+ - "ignore": Skip creation if environment already exists (default)
82
+ - "error": Raise error if environment exists
83
+ - "clear": Remove existing environment and create new one
84
+ """
85
+ if self.exists_env():
86
+ if exists == "error":
87
+ raise FileExistsError(
88
+ f"Virtual environment already exists at {self.env_path}"
89
+ )
90
+ elif exists == "ignore":
91
+ logger.info(
92
+ f"Virtual environment already exists at {self.env_path}, skipping creation"
93
+ )
94
+ return
95
+ elif exists == "clear":
96
+ logger.info(f"Removing existing virtual environment at {self.env_path}")
97
+ self.remove_env()
98
+ else:
99
+ raise ValueError(
100
+ f"Invalid exists option: {exists}. Must be one of: error, clear, ignore"
101
+ )
102
+
103
+ uv_path = self._get_uv_path()
58
104
  cmd = [uv_path, "venv", str(self.env_path), "--system-site-packages"]
105
+
59
106
  if python_path:
60
107
  cmd += ["--python", str(python_path)]
61
108
  elif _is_in_pyinstaller():
@@ -67,6 +114,112 @@ class UVVirtualEnvManager(VirtualEnvManager):
67
114
  logger.info("Creating virtualenv via command: %s", cmd)
68
115
  subprocess.run(cmd, check=True)
69
116
 
117
+ def _resolve_install_plan(
118
+ self, specs: list[str], pinned: dict[str, str]
119
+ ) -> list[str]:
120
+ """
121
+ Run uv --dry-run with pinned constraints and return
122
+ a list like ['package==version', ...].
123
+ """
124
+ with tempfile.NamedTemporaryFile("w+", delete=True) as f:
125
+ for name, ver in pinned.items():
126
+ f.write(f"{name}=={ver}\n")
127
+ f.flush() # make sure content is on disk
128
+
129
+ cmd = [
130
+ self._get_uv_path(),
131
+ "pip",
132
+ "install",
133
+ "-p",
134
+ str(self.env_path),
135
+ "--dry-run",
136
+ "--constraint",
137
+ f.name,
138
+ *specs,
139
+ ]
140
+ result = subprocess.run(cmd, check=True, text=True, capture_output=True)
141
+
142
+ # the temp file is automatically deleted here
143
+ deps = [
144
+ f"{m.group(1)}=={m.group(2)}"
145
+ for line in result.stderr.splitlines()
146
+ if (m := re.match(r"^\+ (\S+)==(\S+)$", line.strip()))
147
+ ]
148
+ return deps
149
+
150
+ @staticmethod
151
+ def _split_specs(
152
+ specs: list[str], installed: dict[str, str]
153
+ ) -> tuple[list[str], dict[str, str]]:
154
+ """
155
+ Split the given requirement specs into:
156
+ - to_resolve: specs that need to be passed to the resolver (unsatisfied ones)
157
+ - pinned: already satisfied specs, used for constraint to lock their versions
158
+ """
159
+ to_resolve: list[str] = []
160
+ pinned: dict[str, str] = {}
161
+
162
+ for spec_str in specs:
163
+ req = Requirement(spec_str)
164
+ name = req.name.lower()
165
+ cur_ver = installed.get(name)
166
+
167
+ if cur_ver is None:
168
+ # Package not installed, needs resolution
169
+ to_resolve.append(spec_str)
170
+ continue
171
+
172
+ if not req.specifier:
173
+ # No version constraint, already satisfied
174
+ pinned[name] = cur_ver
175
+ continue
176
+
177
+ try:
178
+ if Version(cur_ver) in req.specifier:
179
+ # Version satisfies the specifier, pin it
180
+ pinned[name] = cur_ver
181
+ else:
182
+ # Version does not satisfy, needs resolution
183
+ to_resolve.append(spec_str)
184
+ except Exception:
185
+ # Parsing error, be conservative and resolve it
186
+ to_resolve.append(spec_str)
187
+
188
+ return to_resolve, pinned
189
+
190
+ def _filter_packages_not_installed(self, packages: list[str]) -> list[str]:
191
+ """
192
+ Filter out packages that are already installed with the same version.
193
+ """
194
+
195
+ # all the installed packages in system site packages
196
+ installed = {
197
+ dist.metadata["Name"].lower(): dist.version
198
+ for dist in distributions()
199
+ if dist.metadata and "Name" in dist.metadata
200
+ }
201
+
202
+ # exclude those packages that satisfied in system site packages
203
+ to_resolve, pinned = self._split_specs(packages, installed)
204
+ if not to_resolve:
205
+ logger.debug("All requirement specifiers satisfied by system packages.")
206
+ return []
207
+
208
+ resolved = self._resolve_install_plan(to_resolve, pinned)
209
+ logger.debug(f"Resolved install list: {resolved}")
210
+ if not resolved:
211
+ # no packages to install
212
+ return []
213
+
214
+ final = []
215
+ for item in resolved:
216
+ name, version = item.split("==")
217
+ key = name.lower()
218
+ if key not in installed or installed[key] != version:
219
+ final.append(item)
220
+ logger.debug(f"Filtered install list: {final}")
221
+ return final
222
+
70
223
  def install_packages(self, packages: list[str], **kwargs):
71
224
  """
72
225
  Install packages into the virtual environment using uv.
@@ -75,22 +228,36 @@ class UVVirtualEnvManager(VirtualEnvManager):
75
228
  if not packages:
76
229
  return
77
230
 
78
- # extend the ability of pip
79
- # maybe replace #system_torch# to the real version
80
231
  packages = self.process_packages(packages)
81
232
  log = kwargs.pop("log", False)
233
+ skip_installed = kwargs.pop("skip_installed", SKIP_INSTALLED)
234
+ uv_path = self._get_uv_path()
235
+
236
+ if skip_installed:
237
+ packages = self._filter_packages_not_installed(packages)
238
+ if not packages:
239
+ logger.info("All required packages are already installed.")
240
+ return
241
+
242
+ cmd = [
243
+ uv_path,
244
+ "pip",
245
+ "install",
246
+ "-p",
247
+ str(self.env_path),
248
+ "--color=always",
249
+ "--no-deps",
250
+ ] + packages
251
+ else:
252
+ cmd = [
253
+ uv_path,
254
+ "pip",
255
+ "install",
256
+ "-p",
257
+ str(self.env_path),
258
+ "--color=always",
259
+ ] + packages
82
260
 
83
- uv_path = UV_PATH or "uv"
84
- cmd = [
85
- uv_path,
86
- "pip",
87
- "install",
88
- "-p",
89
- str(self.env_path),
90
- "--color=always",
91
- ] + packages
92
-
93
- # Handle known pip-related kwargs
94
261
  if "index_url" in kwargs and kwargs["index_url"]:
95
262
  cmd += ["-i", kwargs["index_url"]]
96
263
  param_and_option = [
@@ -100,12 +267,13 @@ class UVVirtualEnvManager(VirtualEnvManager):
100
267
  ]
101
268
  for param, option in param_and_option:
102
269
  if param in kwargs and kwargs[param]:
103
- param_value = kwargs[param]
104
- if isinstance(param_value, list):
105
- for it in param_value:
106
- cmd += [option, it]
107
- else:
108
- cmd += [option, param_value]
270
+ val = kwargs[param]
271
+ cmd += (
272
+ [option, val]
273
+ if isinstance(val, str)
274
+ else [opt for v in val for opt in (option, v)]
275
+ )
276
+
109
277
  if kwargs.get("no_build_isolation", False):
110
278
  cmd += ["--no-build-isolation"]
111
279
 
@@ -118,8 +286,7 @@ class UVVirtualEnvManager(VirtualEnvManager):
118
286
  self._install_process = process
119
287
  returncode = process.returncode
120
288
 
121
- self._install_process = None # install finished, clear reference
122
-
289
+ self._install_process = None
123
290
  if returncode != 0:
124
291
  raise subprocess.CalledProcessError(returncode, cmd)
125
292
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xoscar
3
- Version: 0.7.11
3
+ Version: 0.7.13
4
4
  Summary: Python actor framework for heterogeneous computing.
5
5
  Home-page: http://github.com/xorbitsai/xoscar
6
6
  Author: Qin Xuye
@@ -1,7 +1,7 @@
1
- xoscar-0.7.11.dist-info/RECORD,,
2
- xoscar-0.7.11.dist-info/WHEEL,sha256=Z5iiTeA1Kq3SZjXuZqO8kPXm4OCIFNqgCso-TxxW5Uk,135
3
- xoscar-0.7.11.dist-info/top_level.txt,sha256=vYlqqY4Nys8Thm1hePIuUv8eQePdULVWMmt7lXtX_ZA,21
4
- xoscar-0.7.11.dist-info/METADATA,sha256=PDSZhxwM8g2RzmkuPLu6aynwy5WrFKV1jyv8XVkUY_4,9135
1
+ xoscar-0.7.13.dist-info/RECORD,,
2
+ xoscar-0.7.13.dist-info/WHEEL,sha256=Z5iiTeA1Kq3SZjXuZqO8kPXm4OCIFNqgCso-TxxW5Uk,135
3
+ xoscar-0.7.13.dist-info/top_level.txt,sha256=vYlqqY4Nys8Thm1hePIuUv8eQePdULVWMmt7lXtX_ZA,21
4
+ xoscar-0.7.13.dist-info/METADATA,sha256=PZcHK2IMvzLoUnkOdtZIsdN1rBpex1nGjiYPx9Qn5-8,9135
5
5
  xoscar/_utils.pyx,sha256=frgVQ5xGp92jBKc4PsPmjOlVsXlKeHWtTOAMfHmBaII,7380
6
6
  xoscar/backend.py,sha256=is436OPkZfSpQXaoqTRVta5eoye_pp45RFgCstAk2hU,1850
7
7
  xoscar/core.pxd,sha256=I_C2ka7XryyGnnAVXUVm8xfS1gtIrCs6X-9rswgOcUU,1317
@@ -12,18 +12,18 @@ xoscar/nvutils.py,sha256=qmW4mKLU0WB2yCs198ccQOgLL02zB7Fsa-AotO3NOmg,20412
12
12
  xoscar/constants.py,sha256=QHHSREw6uWBBjQDCFqlNfTvBZgniJPGy42KSIsR8Fqw,787
13
13
  xoscar/__init__.py,sha256=sy7Wtn2EuQZI0I4Az_MfsBVZm4G0DRj46qRyExgmnJk,1622
14
14
  xoscar/api.py,sha256=zxNqOjGiTIKuAip9WJ0LOoM7yevD6P5rb-sLynpZ2Zo,14648
15
- xoscar/core.cpython-39-darwin.so,sha256=BS6mjUO9pOJ4tQXhg7llfV6XsKQNMvCJ0MjwQqImbnc,410344
15
+ xoscar/core.cpython-39-darwin.so,sha256=r14zf5Gkdv3zpDFKnOhZ5nlc3E7uXFsB9lIQsELPOeU,410344
16
16
  xoscar/utils.py,sha256=MaKiW4Vphwhh8c0yoqN8G8hbJr1zXgpf49EdvmGc1ZU,16500
17
17
  xoscar/debug.py,sha256=9Z8SgE2WaKYQcyDo-5-DxEJQ533v7kWjrvCd28pSx3E,5069
18
18
  xoscar/libcpp.pxd,sha256=DJqBxLFOKL4iRr9Kale5UH3rbvPRD1x5bTSOPHFpz9I,1147
19
19
  xoscar/context.pyx,sha256=8CdgPnWcE9eOp3N600WgDQ03MCi8P73eUOGcfV7Zksg,10942
20
20
  xoscar/errors.py,sha256=wBlQOKsXf0Fc4skN39tDie0YZT-VIAuLNRgoDl2pZcA,1241
21
- xoscar/_utils.cpython-39-darwin.so,sha256=IMAg5sEasJ_ggTFph9NsnY5u0r395-WnDMEwiGYwq_s,169832
21
+ xoscar/_utils.cpython-39-darwin.so,sha256=r8U7wHOYeA23VuzMVy4fneNZbYCIX6TQtRLaGitOUi8,169832
22
22
  xoscar/core.pyx,sha256=phN-yYV0A0QI8WFi2jCu0nc4CnShTepfDi0V7ZrLYPY,22092
23
23
  xoscar/driver.py,sha256=498fowtJr6b3FE8FIOA_Tc1Vwx88nfZw7p0FxrML0h4,1372
24
24
  xoscar/profiling.py,sha256=BC5OF0HzSaXv8V7w-y-B8r5gV5DgxHFoTEIF6jCMioQ,8015
25
25
  xoscar/_utils.pxd,sha256=5KYAL3jfPdejsHnrGGT2s--ZUX5SXznQWpHVSno429k,1157
26
- xoscar/context.cpython-39-darwin.so,sha256=HHNOmXMHb04aAzQSjUD9zvd1RLA1JRjY_j0QioOdS2I,211936
26
+ xoscar/context.cpython-39-darwin.so,sha256=7WcnT5MIN9QaddIb1siUMSKQZmbvOLeTd4QtyUps4SY,211936
27
27
  xoscar/metrics/__init__.py,sha256=9Badi7rxYikGm2dQiNCrj9GgMRBxwuR3JaEKcFZmfak,705
28
28
  xoscar/metrics/api.py,sha256=BBlMIFvVAGVfrtpeJ1YlH9Tqhy9OzGavwvGyeHcQ0Tk,8856
29
29
  xoscar/metrics/backends/__init__.py,sha256=h_JgzSqV5lP6vQ6XX_17kE4IY4BRnvKta_7VLQAL1ms,581
@@ -43,13 +43,13 @@ xoscar/serialization/pyfury.py,sha256=sifOnVMYoS82PzZEkzkfxesmMHei23k5UAUUKUyoOY
43
43
  xoscar/serialization/core.pxd,sha256=k4RoJgX5E5LGs4jdCQ7vvcn26MabXbrWoWhkO49X6YI,985
44
44
  xoscar/serialization/__init__.py,sha256=v76XC2OQLp-Yk4_U3_IVguEylMeyRw1UrkU_DPDMh0U,856
45
45
  xoscar/serialization/numpy.py,sha256=5Kem87CvpJmzUMp3QHk4WeHU30FoQWTJJP2SwIcaQG0,2919
46
- xoscar/serialization/core.cpython-39-darwin.so,sha256=Q84hkh8yxGWAM3WQEgFzevALYErD1Td_kS_7zGEt6iY,380328
46
+ xoscar/serialization/core.cpython-39-darwin.so,sha256=E9ebmY9ejLtwS5NCm0mbJCiYgPHKOyzqr1hkzoGK5BU,380328
47
47
  xoscar/serialization/cuda.py,sha256=iFUEnN4SiquBIhyieyOrfw3TnKnW-tU_vYgqOxO_DrA,3758
48
48
  xoscar/serialization/scipy.py,sha256=yOEi0NB8cqQ6e2UnCZ1w006RsB7T725tIL-DM_hNcsU,2482
49
49
  xoscar/serialization/aio.py,sha256=5DySPgDxU43ec7_5Ct44-Oqt7YNSJBfuf8VdQgQlChA,4731
50
50
  xoscar/serialization/core.pyx,sha256=bjR-zXGm9qersk7kYPzpjpMIxDl_Auur4BCubRfKmfA,29626
51
51
  xoscar/serialization/mlx.py,sha256=tRu_7o6RizdRhbr88EasHrZtShimAsLy3pIEO-by29o,2118
52
- xoscar/backends/message.cpython-39-darwin.so,sha256=4l50YK0sb6FcONDJmoRZjSF1FLzFAd0b8bNTWvTvX_g,365904
52
+ xoscar/backends/message.cpython-39-darwin.so,sha256=LUu3hsBYPtcUqn2DZPb9AHSbVajp3mputZRdKkgimbU,365904
53
53
  xoscar/backends/config.py,sha256=4tZMiXAMMS8qQ4SX_LjONLtSQVfZTx3m-IK3EqbkYdk,5375
54
54
  xoscar/backends/allocate_strategy.py,sha256=tC1Nbq2tJohahUwd-zoRYHEDX65wyuX8tmeY45uWj_w,4845
55
55
  xoscar/backends/__init__.py,sha256=VHEBQcUWM5bj027W8EUf9PiJUAP7JoMrRw3Tsvy5ySw,643
@@ -82,6 +82,6 @@ xoscar/aio/lru.py,sha256=rpXCqSLtPV5xnWtd6uDwQQFGgIPEgvmWEQDkPNUx9cM,6311
82
82
  xoscar/aio/parallelism.py,sha256=VSsjk8wP-Bw7tLeUsTyLVNgp91thjxEfE3pCrw_vF5Q,1293
83
83
  xoscar/aio/base.py,sha256=9j0f1piwfE5R5GIvV212vSD03ixdaeSzSSsO2kxJZVE,2249
84
84
  xoscar/virtualenv/__init__.py,sha256=65t9_X1DvbanNjFy366SiiWZrRTpa9SXWMXPmqayE-4,1117
85
- xoscar/virtualenv/core.py,sha256=qHKqI6R92SN0_OWVAX1xy9wJiZr-r0VfLHTskZtZE4U,2851
85
+ xoscar/virtualenv/core.py,sha256=MV1lbkixGl45REHS04uaPuqPKxyVbBmVnB_umuR_eWw,2957
86
86
  xoscar/virtualenv/utils.py,sha256=mL_uATHhj82xec0-0IZ6N8yI-laPAB4t8G3alPUGtPA,2439
87
- xoscar/virtualenv/uv.py,sha256=ef7InUP0VwPJe-ssZpWCMDN69lEp4aIRFtEgVff82eI,4884
87
+ xoscar/virtualenv/uv.py,sha256=OjaHgIR2pOySaLbsnFELOYkX4Y5QZLSm2yqyLApPbdo,10668