xoscar 0.7.14__cp311-cp311-macosx_10_9_x86_64.whl → 0.7.16__cp311-cp311-macosx_10_9_x86_64.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
@@ -14,10 +14,24 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
+ import ast
17
18
  import importlib
19
+ import operator
18
20
  from abc import ABC, abstractmethod
19
21
  from pathlib import Path
20
22
 
23
+ from packaging.markers import Marker, default_environment
24
+ from packaging.requirements import InvalidRequirement, Requirement
25
+ from packaging.version import Version
26
+
27
+ from .platform import (
28
+ check_cuda_available,
29
+ check_npu_available,
30
+ get_cuda_arch,
31
+ get_cuda_version,
32
+ )
33
+ from .utils import is_vcs_url
34
+
21
35
 
22
36
  class VirtualEnvManager(ABC):
23
37
  @classmethod
@@ -79,6 +93,13 @@ class VirtualEnvManager(ABC):
79
93
  else:
80
94
  processed.append(pkg)
81
95
 
96
+ # apply extended syntax including:
97
+ # - has_cuda: whether CUDA is available (bool)
98
+ # - cuda_version: CUDA version string, e.g. "12.1" (str)
99
+ # - cuda_arch: CUDA architecture string, e.g. "sm_80" (str)
100
+ # - has_npu: whether an NPU is available (bool)
101
+ processed = filter_requirements(processed)
102
+
82
103
  return processed
83
104
 
84
105
  @abstractmethod
@@ -96,3 +117,152 @@ class VirtualEnvManager(ABC):
96
117
  @abstractmethod
97
118
  def remove_env(self):
98
119
  pass
120
+
121
+
122
+ def get_env() -> dict[str, str | bool]:
123
+ env = default_environment().copy()
124
+ # Your custom env vars here, e.g.:
125
+ env.update(
126
+ {
127
+ "has_cuda": check_cuda_available(),
128
+ "cuda_version": get_cuda_version(),
129
+ "cuda_arch": get_cuda_arch(),
130
+ "has_npu": check_npu_available(),
131
+ }
132
+ )
133
+ return env
134
+
135
+
136
+ STANDARD_ENV_VARS = set(default_environment().keys())
137
+
138
+
139
+ def is_custom_marker(marker_str: str) -> bool:
140
+ try:
141
+ marker = Marker(marker_str)
142
+ except Exception:
143
+ return True
144
+
145
+ def traverse_markers(node):
146
+ if isinstance(node, tuple):
147
+ env_var = node[0]
148
+ if env_var not in STANDARD_ENV_VARS:
149
+ return True
150
+ return False
151
+ elif isinstance(node, list):
152
+ return any(traverse_markers(child) for child in node)
153
+ return False
154
+
155
+ return traverse_markers(marker._markers)
156
+
157
+
158
+ def eval_custom_marker(marker_str: str, env: dict) -> bool:
159
+ ops = {
160
+ ast.Eq: operator.eq,
161
+ ast.NotEq: operator.ne,
162
+ ast.Lt: operator.lt,
163
+ ast.LtE: operator.le,
164
+ ast.Gt: operator.gt,
165
+ ast.GtE: operator.ge,
166
+ ast.And: lambda a, b: a and b,
167
+ ast.Or: lambda a, b: a or b,
168
+ ast.Not: operator.not_,
169
+ }
170
+
171
+ def normalize_value(val):
172
+ # Normalize for boolean
173
+ if isinstance(val, str):
174
+ if val.lower() == "true":
175
+ return True
176
+ if val.lower() == "false":
177
+ return False
178
+
179
+ # Normalize for version-like fields
180
+ if isinstance(val, str):
181
+ if val.count(".") >= 1 and all(
182
+ part.isdigit() for part in val.split(".") if part
183
+ ):
184
+ return Version(val)
185
+
186
+ return val
187
+
188
+ def maybe_parse_cuda_arch(val):
189
+ if isinstance(val, str) and val.startswith("sm_"):
190
+ try:
191
+ return int(val[3:])
192
+ except ValueError:
193
+ return val
194
+ return val
195
+
196
+ def _eval(node):
197
+ if isinstance(node, ast.BoolOp):
198
+ left = _eval(node.values[0])
199
+ for right_node in node.values[1:]:
200
+ right = _eval(right_node)
201
+ op = ops[type(node.op)]
202
+ left = op(left, right)
203
+ return left
204
+
205
+ elif isinstance(node, ast.UnaryOp) and isinstance(node.op, ast.Not):
206
+ return not _eval(node.operand)
207
+
208
+ elif isinstance(node, ast.Compare):
209
+ left = _eval(node.left)
210
+ left = maybe_parse_cuda_arch(normalize_value(left))
211
+
212
+ for op_node, right_expr in zip(node.ops, node.comparators):
213
+ right = _eval(right_expr)
214
+ right = maybe_parse_cuda_arch(normalize_value(right))
215
+
216
+ op_func = ops[type(op_node)]
217
+ if not op_func(left, right):
218
+ return False
219
+ left = right # for chained comparisons
220
+
221
+ return True
222
+
223
+ elif isinstance(node, ast.Name):
224
+ return normalize_value(env.get(node.id))
225
+
226
+ elif isinstance(node, ast.Constant):
227
+ return node.value
228
+
229
+ elif isinstance(node, ast.Str): # Python <3.8
230
+ return node.s
231
+
232
+ else:
233
+ raise ValueError(f"Unsupported expression: {ast.dump(node)}")
234
+
235
+ tree = ast.parse(marker_str, mode="eval")
236
+ return _eval(tree.body)
237
+
238
+
239
+ def filter_requirements(requirements: list[str]) -> list[str]:
240
+ """
241
+ Filter requirements by evaluating markers in given env.
242
+ If env is None, use get_env().
243
+ """
244
+ env = get_env()
245
+ result = []
246
+ for req_str in requirements:
247
+ if is_vcs_url(req_str):
248
+ result.append(req_str)
249
+ elif ";" in req_str:
250
+ req_part, marker_part = req_str.split(";", 1)
251
+ marker_part = marker_part.strip()
252
+ try:
253
+ req = Requirement(req_str)
254
+ if req.marker is None or req.marker.evaluate(env):
255
+ result.append(f"{req.name}{req.specifier}")
256
+ continue
257
+ except InvalidRequirement:
258
+ if is_custom_marker(marker_part):
259
+ if eval_custom_marker(marker_part, env):
260
+ req = Requirement(req_part.strip())
261
+ result.append(str(req))
262
+ else:
263
+ raise
264
+ else:
265
+ req = Requirement(req_str.strip())
266
+ result.append(str(req))
267
+
268
+ return result
@@ -0,0 +1,53 @@
1
+ # Copyright 2022-2025 XProbe Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from typing import Optional
16
+
17
+
18
+ def check_cuda_available() -> bool:
19
+ try:
20
+ import torch
21
+
22
+ return torch.cuda.is_available()
23
+ except (ImportError, AttributeError):
24
+ return False
25
+
26
+
27
+ def get_cuda_version() -> Optional[str]:
28
+ try:
29
+ import torch
30
+
31
+ return torch.version.cuda # e.g. '12.1'
32
+ except (ImportError, AttributeError):
33
+ return None
34
+
35
+
36
+ def get_cuda_arch() -> Optional[str]:
37
+ try:
38
+ import torch
39
+
40
+ major, minor = torch.cuda.get_device_capability()
41
+ return f"sm_{major}{minor}" # e.g. 'sm_80'
42
+ except (ImportError, AttributeError):
43
+ return None
44
+
45
+
46
+ def check_npu_available() -> bool:
47
+ try:
48
+ import torch
49
+ import torch_npu # noqa: F401
50
+
51
+ return torch.npu.is_available()
52
+ except ImportError:
53
+ return False
@@ -82,3 +82,19 @@ def run_subprocess_with_logger(
82
82
  process.wait()
83
83
  for t in threads:
84
84
  t.join()
85
+
86
+
87
+ def is_vcs_url(spec_str: str) -> bool:
88
+ """
89
+ Check if the given spec string is a VCS URL.
90
+
91
+ Supports common VCS schemes like git+, svn+, hg+, bzr+, and HTTP/HTTPS URLs.
92
+
93
+ Args:
94
+ spec_str (str): The package spec string.
95
+
96
+ Returns:
97
+ bool: True if it's a VCS URL, False otherwise.
98
+ """
99
+ vcs_prefixes = ("git+", "http://", "https://", "svn+", "hg+", "bzr+")
100
+ return spec_str.startswith(vcs_prefixes)
xoscar/virtualenv/uv.py CHANGED
@@ -30,7 +30,7 @@ from packaging.requirements import Requirement
30
30
  from packaging.version import Version
31
31
 
32
32
  from .core import VirtualEnvManager
33
- from .utils import run_subprocess_with_logger
33
+ from .utils import is_vcs_url, run_subprocess_with_logger
34
34
 
35
35
  UV_PATH = os.getenv("XOSCAR_UV_PATH")
36
36
  SKIP_INSTALLED = bool(int(os.getenv("XOSCAR_VIRTUAL_ENV_SKIP_INSTALLED", "0")))
@@ -163,9 +163,7 @@ class UVVirtualEnvManager(VirtualEnvManager):
163
163
 
164
164
  for spec_str in specs:
165
165
  # skip git+xxx
166
- if spec_str.startswith(
167
- ("git+", "http://", "https://", "svn+", "hg+", "bzr+")
168
- ):
166
+ if is_vcs_url(spec_str):
169
167
  keep.append(spec_str)
170
168
  continue
171
169
 
@@ -241,6 +239,9 @@ class UVVirtualEnvManager(VirtualEnvManager):
241
239
  return
242
240
 
243
241
  packages = self.process_packages(packages)
242
+ if not packages:
243
+ return
244
+
244
245
  log = kwargs.pop("log", False)
245
246
  skip_installed = kwargs.pop("skip_installed", SKIP_INSTALLED)
246
247
  uv_path = self._get_uv_path()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xoscar
3
- Version: 0.7.14
3
+ Version: 0.7.16
4
4
  Summary: Python actor framework for heterogeneous computing.
5
5
  Home-page: http://github.com/xorbitsai/xoscar
6
6
  Author: Qin Xuye
@@ -1,9 +1,9 @@
1
- xoscar-0.7.14.dist-info/RECORD,,
2
- xoscar-0.7.14.dist-info/WHEEL,sha256=9JW_xs4qhQPk0BxaQRvBEJlozFusVYXbUecyREdMua0,138
3
- xoscar-0.7.14.dist-info/top_level.txt,sha256=vYlqqY4Nys8Thm1hePIuUv8eQePdULVWMmt7lXtX_ZA,21
4
- xoscar-0.7.14.dist-info/METADATA,sha256=bTouvWumRWQDRY1ApYh9XVZ7HthHSUa8ctv-___IW6U,9135
1
+ xoscar-0.7.16.dist-info/RECORD,,
2
+ xoscar-0.7.16.dist-info/WHEEL,sha256=9JW_xs4qhQPk0BxaQRvBEJlozFusVYXbUecyREdMua0,138
3
+ xoscar-0.7.16.dist-info/top_level.txt,sha256=vYlqqY4Nys8Thm1hePIuUv8eQePdULVWMmt7lXtX_ZA,21
4
+ xoscar-0.7.16.dist-info/METADATA,sha256=Yt5bo1VSoHeKy8IPnhVlorXbAkW0Cdws6o4VJZG5Y2E,9135
5
5
  xoscar/_utils.pyx,sha256=frgVQ5xGp92jBKc4PsPmjOlVsXlKeHWtTOAMfHmBaII,7380
6
- xoscar/_utils.cpython-311-darwin.so,sha256=9dgbnAEiBP6JTRKFSb92g9n8Pvv5RP6X87lofpOZ_fE,163280
6
+ xoscar/_utils.cpython-311-darwin.so,sha256=DoUAhw768YeQdV2V1CDprhLy1J5kbzhU1hUIxwGrVeU,163224
7
7
  xoscar/backend.py,sha256=is436OPkZfSpQXaoqTRVta5eoye_pp45RFgCstAk2hU,1850
8
8
  xoscar/core.pxd,sha256=I_C2ka7XryyGnnAVXUVm8xfS1gtIrCs6X-9rswgOcUU,1317
9
9
  xoscar/_version.py,sha256=ClSPrUjgGRGHIkVMQV9XQnkQ-n0akJMnq_rh819nqFE,23719
@@ -14,11 +14,11 @@ xoscar/constants.py,sha256=QHHSREw6uWBBjQDCFqlNfTvBZgniJPGy42KSIsR8Fqw,787
14
14
  xoscar/__init__.py,sha256=sy7Wtn2EuQZI0I4Az_MfsBVZm4G0DRj46qRyExgmnJk,1622
15
15
  xoscar/api.py,sha256=zxNqOjGiTIKuAip9WJ0LOoM7yevD6P5rb-sLynpZ2Zo,14648
16
16
  xoscar/utils.py,sha256=MaKiW4Vphwhh8c0yoqN8G8hbJr1zXgpf49EdvmGc1ZU,16500
17
- xoscar/context.cpython-311-darwin.so,sha256=ACYXRSdWIxbm4RIewPUZ9syNEsXIYIq0h36BnLr0i_0,201688
17
+ xoscar/context.cpython-311-darwin.so,sha256=uQGxaP9I1yi0o9_SeUujTC0qL-N3P9AYaiLq-iw43Mo,201176
18
18
  xoscar/debug.py,sha256=9Z8SgE2WaKYQcyDo-5-DxEJQ533v7kWjrvCd28pSx3E,5069
19
19
  xoscar/libcpp.pxd,sha256=DJqBxLFOKL4iRr9Kale5UH3rbvPRD1x5bTSOPHFpz9I,1147
20
20
  xoscar/context.pyx,sha256=8CdgPnWcE9eOp3N600WgDQ03MCi8P73eUOGcfV7Zksg,10942
21
- xoscar/core.cpython-311-darwin.so,sha256=d3IyD8qnlbyJw0uRDlRLb1Ks8FWx8rewfTVtxDslMT8,416456
21
+ xoscar/core.cpython-311-darwin.so,sha256=-M1bg2Qr-KACDFxvs9ohSVHx2buruvtYTMp6tKLCBGs,416088
22
22
  xoscar/errors.py,sha256=wBlQOKsXf0Fc4skN39tDie0YZT-VIAuLNRgoDl2pZcA,1241
23
23
  xoscar/core.pyx,sha256=phN-yYV0A0QI8WFi2jCu0nc4CnShTepfDi0V7ZrLYPY,22092
24
24
  xoscar/driver.py,sha256=498fowtJr6b3FE8FIOA_Tc1Vwx88nfZw7p0FxrML0h4,1372
@@ -46,10 +46,10 @@ xoscar/serialization/numpy.py,sha256=5Kem87CvpJmzUMp3QHk4WeHU30FoQWTJJP2SwIcaQG0
46
46
  xoscar/serialization/cuda.py,sha256=iFUEnN4SiquBIhyieyOrfw3TnKnW-tU_vYgqOxO_DrA,3758
47
47
  xoscar/serialization/scipy.py,sha256=yOEi0NB8cqQ6e2UnCZ1w006RsB7T725tIL-DM_hNcsU,2482
48
48
  xoscar/serialization/aio.py,sha256=5DySPgDxU43ec7_5Ct44-Oqt7YNSJBfuf8VdQgQlChA,4731
49
- xoscar/serialization/core.cpython-311-darwin.so,sha256=MHCtIBDrTKopKvEPnZdkZR1qMR3aEE-B7vs5mc-y0uE,394264
49
+ xoscar/serialization/core.cpython-311-darwin.so,sha256=WxoeDAcocoGOA9mwMwEnvCMveeQnqmCGmTgOQXnAbQo,393808
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-311-darwin.so,sha256=gCxwtSYk7lJykaxlTtvGG2MtfRFikFwu0-JrdBchgyY,374728
52
+ xoscar/backends/message.cpython-311-darwin.so,sha256=Reuxv8pHds6EDfiP_b_9k21UtdmKqi_eEx7j7nlZ_ig,374680
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,7 @@ 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=MV1lbkixGl45REHS04uaPuqPKxyVbBmVnB_umuR_eWw,2957
86
- xoscar/virtualenv/utils.py,sha256=mL_uATHhj82xec0-0IZ6N8yI-laPAB4t8G3alPUGtPA,2439
87
- xoscar/virtualenv/uv.py,sha256=8fsZtUfMfSI1FZL7eLMfF-znG7fGVwshdERiHqSvems,11119
85
+ xoscar/virtualenv/core.py,sha256=Ij36UQaej9fFaz1PfqkEtL1ss8yBribXHcWT115kH-o,8098
86
+ xoscar/virtualenv/platform.py,sha256=3f5EQEXbq_sf4pRJ_0lg4y1V_22qadUdQjmVjIaZaoU,1403
87
+ xoscar/virtualenv/utils.py,sha256=qKHw7Gg0n3JuzKFjhBnftPq2QWlgNJLk1sGPr5GzamM,2875
88
+ xoscar/virtualenv/uv.py,sha256=VBw045LN8gYMLgjaazt7-tnwBveWr7YYE2zjDsL18h0,11091