xoscar 0.7.14__cp312-cp312-macosx_11_0_arm64.whl → 0.7.15__cp312-cp312-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
@@ -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
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xoscar
3
- Version: 0.7.14
3
+ Version: 0.7.15
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.14.dist-info/RECORD,,
2
- xoscar-0.7.14.dist-info/WHEEL,sha256=V1loQ6TpxABu1APUg0MoTRBOzSKT5xVc3skizX-ovCU,136
3
- xoscar-0.7.14.dist-info/top_level.txt,sha256=vYlqqY4Nys8Thm1hePIuUv8eQePdULVWMmt7lXtX_ZA,21
4
- xoscar-0.7.14.dist-info/METADATA,sha256=FSLexmYKLtKCPsl0FWyauloUQVcpL8yiv0zoJxZ-T-o,9190
1
+ xoscar-0.7.15.dist-info/RECORD,,
2
+ xoscar-0.7.15.dist-info/WHEEL,sha256=V1loQ6TpxABu1APUg0MoTRBOzSKT5xVc3skizX-ovCU,136
3
+ xoscar-0.7.15.dist-info/top_level.txt,sha256=vYlqqY4Nys8Thm1hePIuUv8eQePdULVWMmt7lXtX_ZA,21
4
+ xoscar-0.7.15.dist-info/METADATA,sha256=AeLz868mxqUYyxnF7SfNQKZu_3CHcXzS6TSiyoIMA8o,9190
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
@@ -10,16 +10,16 @@ xoscar/context.pxd,sha256=qKa0OyDPZtVymftSh447m-RzFZgmz8rGqQBa7qlauvc,725
10
10
  xoscar/batch.py,sha256=DpArS0L3WYJ_HVPG-6hSYEwoAFY1mY2-mlC4Jp5M_Dw,7872
11
11
  xoscar/nvutils.py,sha256=qmW4mKLU0WB2yCs198ccQOgLL02zB7Fsa-AotO3NOmg,20412
12
12
  xoscar/constants.py,sha256=QHHSREw6uWBBjQDCFqlNfTvBZgniJPGy42KSIsR8Fqw,787
13
- xoscar/core.cpython-312-darwin.so,sha256=gQgqUsrh54nu-BUE2mgvaO0FlEQWofqr_ucLbDt7UQM,413256
13
+ xoscar/core.cpython-312-darwin.so,sha256=Uh3QnxU2UeIdzmq047-swnObrFibRcke9eyFNF7_Xk0,413256
14
14
  xoscar/__init__.py,sha256=sy7Wtn2EuQZI0I4Az_MfsBVZm4G0DRj46qRyExgmnJk,1622
15
- xoscar/context.cpython-312-darwin.so,sha256=xewKE24t7fmvFfxBDxjMd5h-u8hubOI3hzk7FyZZ_lE,214096
15
+ xoscar/context.cpython-312-darwin.so,sha256=FTpymykGDR8J1Lb8kMzGN0BcsX_TNtofWDcAVTDWIH0,214096
16
16
  xoscar/api.py,sha256=zxNqOjGiTIKuAip9WJ0LOoM7yevD6P5rb-sLynpZ2Zo,14648
17
17
  xoscar/utils.py,sha256=MaKiW4Vphwhh8c0yoqN8G8hbJr1zXgpf49EdvmGc1ZU,16500
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
21
  xoscar/errors.py,sha256=wBlQOKsXf0Fc4skN39tDie0YZT-VIAuLNRgoDl2pZcA,1241
22
- xoscar/_utils.cpython-312-darwin.so,sha256=z6NismjRmjBMgChL9jDRCwA5ggD7nPi7QPuhIswcXug,170640
22
+ xoscar/_utils.cpython-312-darwin.so,sha256=EZul6GUTcKMCoFobkzpHxfznbHFSjzmJ0ZVOaV0A8v8,170640
23
23
  xoscar/core.pyx,sha256=phN-yYV0A0QI8WFi2jCu0nc4CnShTepfDi0V7ZrLYPY,22092
24
24
  xoscar/driver.py,sha256=498fowtJr6b3FE8FIOA_Tc1Vwx88nfZw7p0FxrML0h4,1372
25
25
  xoscar/profiling.py,sha256=BC5OF0HzSaXv8V7w-y-B8r5gV5DgxHFoTEIF6jCMioQ,8015
@@ -43,7 +43,7 @@ xoscar/serialization/exception.py,sha256=Jy8Lsk0z-VJyEUaWeuZIwkmxqaoB-nLKMa1D15C
43
43
  xoscar/serialization/pyfury.py,sha256=sifOnVMYoS82PzZEkzkfxesmMHei23k5UAUUKUyoOYQ,1163
44
44
  xoscar/serialization/core.pxd,sha256=k4RoJgX5E5LGs4jdCQ7vvcn26MabXbrWoWhkO49X6YI,985
45
45
  xoscar/serialization/core.pyi,sha256=-pQARSj91rt3iU4ftWGFH6jYwsSKYCT_Ya7EJsaGEjg,1874
46
- xoscar/serialization/core.cpython-312-darwin.so,sha256=NDlbuuM6OQRGZdc77AP9IBrSO_xGPtwcfhtjGD9T6MQ,366520
46
+ xoscar/serialization/core.cpython-312-darwin.so,sha256=oXNcWVDPCdXgFKr84S0ly7bY4CczkCMrp8Z2jZzXlh0,366520
47
47
  xoscar/serialization/__init__.py,sha256=v76XC2OQLp-Yk4_U3_IVguEylMeyRw1UrkU_DPDMh0U,856
48
48
  xoscar/serialization/numpy.py,sha256=5Kem87CvpJmzUMp3QHk4WeHU30FoQWTJJP2SwIcaQG0,2919
49
49
  xoscar/serialization/cuda.py,sha256=iFUEnN4SiquBIhyieyOrfw3TnKnW-tU_vYgqOxO_DrA,3758
@@ -58,7 +58,7 @@ xoscar/backends/__init__.py,sha256=VHEBQcUWM5bj027W8EUf9PiJUAP7JoMrRw3Tsvy5ySw,6
58
58
  xoscar/backends/core.py,sha256=EH-fHlV9x3bnruEHaUtGYO7osKLfLJ4AQHtuzA_mr2g,10857
59
59
  xoscar/backends/context.py,sha256=XfDPG2eDhAhE6hWBEkEsHTnyyOYN9R3houlMjAL7BFw,16329
60
60
  xoscar/backends/router.py,sha256=MVl5naz-FYf-Wla7XRn3kRxOpWV0SjKDsKNluifVA8M,10532
61
- xoscar/backends/message.cpython-312-darwin.so,sha256=xu7nv0c8xle8IfxpmJh6NFtyqmf_cFHIKuFq8tEr4MI,368608
61
+ xoscar/backends/message.cpython-312-darwin.so,sha256=MGHbYaDSLkM-n_4CCcJgnxE69TLH-OISR7QqH6xUP4o,368608
62
62
  xoscar/backends/message.pyx,sha256=krGVtZ1YDaZX8yWhaNHwZiudQooLvcGlw6x3Sq7jxjE,19685
63
63
  xoscar/backends/pool.py,sha256=nrh8qobaukkjUOOOTR9t90i-wbXlgma3TNRjvwkwmcg,60528
64
64
  xoscar/backends/indigen/backend.py,sha256=znl_fZzWGEtLH8hZ9j9Kkf0fva25jEem2_KO7I1RVvc,1612
@@ -85,6 +85,7 @@ xoscar/aio/lru.py,sha256=rpXCqSLtPV5xnWtd6uDwQQFGgIPEgvmWEQDkPNUx9cM,6311
85
85
  xoscar/aio/parallelism.py,sha256=VSsjk8wP-Bw7tLeUsTyLVNgp91thjxEfE3pCrw_vF5Q,1293
86
86
  xoscar/aio/base.py,sha256=9j0f1piwfE5R5GIvV212vSD03ixdaeSzSSsO2kxJZVE,2249
87
87
  xoscar/virtualenv/__init__.py,sha256=65t9_X1DvbanNjFy366SiiWZrRTpa9SXWMXPmqayE-4,1117
88
- xoscar/virtualenv/core.py,sha256=MV1lbkixGl45REHS04uaPuqPKxyVbBmVnB_umuR_eWw,2957
89
- xoscar/virtualenv/utils.py,sha256=mL_uATHhj82xec0-0IZ6N8yI-laPAB4t8G3alPUGtPA,2439
90
- xoscar/virtualenv/uv.py,sha256=8fsZtUfMfSI1FZL7eLMfF-znG7fGVwshdERiHqSvems,11119
88
+ xoscar/virtualenv/core.py,sha256=Ij36UQaej9fFaz1PfqkEtL1ss8yBribXHcWT115kH-o,8098
89
+ xoscar/virtualenv/platform.py,sha256=3f5EQEXbq_sf4pRJ_0lg4y1V_22qadUdQjmVjIaZaoU,1403
90
+ xoscar/virtualenv/utils.py,sha256=qKHw7Gg0n3JuzKFjhBnftPq2QWlgNJLk1sGPr5GzamM,2875
91
+ xoscar/virtualenv/uv.py,sha256=bkFN2Vp6b2mz6YXpodH2plGIGBA-YUU4vE5p2j0mKkg,11046