blext.pydeps
blext.pydeps.blext_deps
Tools for managing wheel-based dependencies.
BLExtDeps
Bases: BaseModel
All Python dependencies needed by a Blender extension.
pydeps_graph
cached
property
pydeps_graph: DiGraph
Dependency-graph representation of self.pydeps
.
from_uv_lock
classmethod
from_uv_lock(
uv_lock: frozendict[str, Any],
*,
module_name: str,
min_glibc_version: tuple[int, int] | None = None,
min_macos_version: tuple[int, int] | None = None,
valid_python_tags: frozenset[str] | None = None,
valid_abi_tags: frozenset[str] | None = None,
) -> Self
Create from a uv.lock
file.
PARAMETER | DESCRIPTION |
---|---|
uv_lock
|
Result of parsing a
TYPE:
|
module_name
|
Name of the top-level Python module, which depends on everything else.
Should be identical to:
- Script Extensions: The module name without
TYPE:
|
Source code in blext/pydeps/blext_deps.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
|
pydeps_by
pydeps_by(
*,
pkg_name: str,
bl_version: BLVersion,
bl_platform: BLPlatform,
err_msgs: dict[BLPlatform, list[str]],
) -> frozendict[str, PyDep]
All Python dependencies needed by the given Python environment.
Source code in blext/pydeps/blext_deps.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
wheels_by
wheels_by(
*,
pkg_name: str,
bl_version: BLVersion,
bl_platforms: frozenset[BLPlatform],
) -> frozenset[PyDepWheel]
All wheels needed for a Blender extension.
Notes
Computed from self.validated_graph
.
Source code in blext/pydeps/blext_deps.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|
blext.pydeps.download
Tools for managing wheel-based dependencies.
download_wheel
download_wheel(
wheel_url: str,
wheel_path: Path,
*,
wheel: PyDepWheel,
cb_update_wheel_download: Callable[
[PyDepWheel, Path, int], list[None] | None
] = lambda *_: None,
cb_finish_wheel_download: Callable[
[PyDepWheel, Path], list[None] | None
] = lambda *_: None,
) -> None
Download a Python wheel.
Notes
This function is designed to be run in a background thread.
PARAMETER | DESCRIPTION |
---|---|
wheel_url
|
URL to download the wheel from.
TYPE:
|
wheel_path
|
Path to download the wheel to.
TYPE:
|
wheel
|
The wheel spec to be downloaded.
TYPE:
|
cb_update_wheel_download
|
Callback to trigger whenever more data has been downloaded.
TYPE:
|
cb_finish_wheel_download
|
Callback to trigger whenever a wheel has finished downloading.
TYPE:
|
Source code in blext/pydeps/download.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
download_wheels
download_wheels(
wheels: frozenset[PyDepWheel],
*,
path_wheels: Path,
cb_start_wheel_download: Callable[
[PyDepWheel, Path], Any
] = lambda *_: None,
cb_update_wheel_download: Callable[
[PyDepWheel, Path, int], Any
] = lambda *_: None,
cb_finish_wheel_download: Callable[
[PyDepWheel, Path], Any
] = lambda *_: None,
) -> None
Download universal and binary wheels for all platforms defined in pyproject.toml
.
Each blender-supported platform requires specifying a valid list of PyPi platform constraints. These will be used as an allow-list when deciding which binary wheels may be selected for ex. 'mac'.
It is recommended to start with the most compatible platform tags, then work one's way up to the newest. Depending on how old the compatibility should stretch, one may have to omit / manually compile some wheels.
There is no exhaustive list of valid platform tags - though this should get you started: - https://stackoverflow.com/questions/49672621/what-are-the-valid-values-for-platform-abi-and-implementation-for-pip-do - Examine https://pypi.org/project/pillow/#files for some widely-supported tags.
PARAMETER | DESCRIPTION |
---|---|
wheels
|
Wheels to download.
TYPE:
|
path_wheels
|
Folder within which to download wheels to.
TYPE:
|
cb_start_wheel_download
|
Callback to trigger when starting a wheel download.
TYPE:
|
cb_update_wheel_download
|
Callback to trigger when a wheel download should update.
TYPE:
|
cb_finish_wheel_download
|
Callback to trigger when a wheel download has finished.
TYPE:
|
Source code in blext/pydeps/download.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
blext.pydeps.pydep
Implements PyDep
and `PyDepMarker.
PyDep
Bases: BaseModel
A Python dependency.
select_wheel
select_wheel(
*,
bl_platform: BLPlatform,
min_glibc_version: tuple[int, int],
min_macos_version: tuple[int, int],
valid_python_tags: frozenset[str],
valid_abi_tags: frozenset[str],
err_msgs: dict[BLPlatform, list[str]],
target_descendants: frozenset[str],
) -> PyDepWheel | None
Select the best wheel to satisfy this dependency.
Source code in blext/pydeps/pydep.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
blext.pydeps.pydep_marker
Implements PyDep
and `PyDepMarker.
PyDepMarker
Bases: BaseModel
A platform-specific criteria for installing a particular wheel.
marker
cached
property
marker: Marker
Parsed marker whose evaluate()
method checks it against a Python environment.
is_valid_for
is_valid_for(
*,
pkg_name: str,
bl_version: BLVersion,
bl_platform: BLPlatform,
) -> bool
Whether this marker will evaluate True
under the targeted Python environment.
Notes
pkg_name
is included, since the way that uv
encodes conflicts between extra
s is to add the package name, like so:
- extra-11-simple-proj-bl-4-3
- extra-11-simple-proj-bl-4-4
- extra-{len(pkg_name)}-{pkg_name}-{pymarker_extra}
Presumably, this prevents name-conflicts.
PARAMETER | DESCRIPTION |
---|---|
pkg_name
|
The name of the root package, defined with standard
TYPE:
|
bl_version
|
The Blender version to check validity for.
TYPE:
|
bl_platform
|
The Blender platform to check validity for.
TYPE:
|
See Also
extyp.BLVersion.pymarker_encoded_package_extra
: For more information about how and why uv
-generated extra
s require pkg_name
to be known.
Source code in blext/pydeps/pydep_marker.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
blext.pydeps.pydep_wheel
Defines an abstraction for a Blender extension wheel.
PyDepWheel
Bases: BaseModel
Representation of a Python dependency.
abi_tags
cached
property
abi_tags: frozenset[str]
The ABI tags of the wheel.
build
cached
property
build: str | None
The build-tag of the project represented by the wheel, if any.
filename
cached
property
filename: str
Parse the filename of the wheel file.
glibc_versions
cached
property
glibc_versions: frozendict[str, tuple[int, int] | None]
Minimum GLIBC versions supported by this wheel.
Notes
- The smallest available GLIBC version indicates the minimum GLIBC support for this wheel.
- Non-
manylinux
platform tags will always map toNone
.
macos_versions
cached
property
macos_versions: frozendict[str, tuple[int, int] | None]
Minimum MacOS versions supported by this wheel.
Notes
- The smallest available MacOS version indicates the minimum GLIBC support for this wheel.
- Non-
macosx
platform tags will always map toNone
.
platform_tags
cached
property
platform_tags: frozenset[str]
The platform tags of the wheel.
Notes
Legacy manylinux
tags (such as 2014
) are normalized to their
explicit PEP600
equivalents (ex. 2014 -> 2_17
).
This is done to avoid irregularities in how glibc
versions are parsed
for manylinux
wheels in later methods.
See Also
PEP600
: https://peps.python.org/pep-0600/
pretty_bl_platforms
cached
property
pretty_bl_platforms: str
Retrieve prettified, unfiltered bl_platforms
for this wheel.
project
cached
property
project: str
The name of the project represented by the wheel.
Name is normalized to use '_' instead of '-'.
python_tags
cached
property
python_tags: frozenset[str]
The Python tags of the wheel.
sort_key_preferred_linux
cached
property
sort_key_preferred_linux: int
Priority to assign to this wheel when selecting one of several Linux wheels.
Notes
Higher values will be chosen over lower values. The value should be deterministic from the platform tags.
sort_key_preferred_mac
cached
property
sort_key_preferred_mac: int
Priority to assign to this wheel when selecting one of several MacOS wheels.
Notes
Higher values will be chosen over lower values. The value should be deterministic from the platform tags.
sort_key_preferred_windows
cached
property
sort_key_preferred_windows: int
Priority to assign to this wheel when selecting one of several Windows wheels.
Notes
Higher values will be chosen over lower values. The value should be deterministic from the platform tags.
sort_key_size
cached
property
sort_key_size: int
Priority to assign to this wheel sorting by size.
Notes
- Higher values will sort later in the list.
- When
self.size is None
, then the "size" will be set to 0.
version
cached
property
version: str
The version of the project represented by the wheel.
windows_versions
cached
property
windows_versions: frozendict[str, Literal['win32'] | None]
Windows ABI versions supported by this wheel.
Notes
- In terms of ABI, there is only one on Windows:
win32
. - Non-
win
platform tags will always map toNone
.
is_download_valid
is_download_valid(wheel_path: Path) -> bool
Check whether a downloaded file is, in fact, this wheel.
Notes
Implemented by comparing the file hash to the expected hash.
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the hash digest of |
Source code in blext/pydeps/pydep_wheel.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
|
works_with_abi_tags
works_with_abi_tags(valid_abi_tags: frozenset[str]) -> bool
Does this wheel work with a runtime that supports abi_tags
?
Notes
- It is very strongly recommended to always pass
"none"
as one of theabi_tags
, since this is the ABI tag of pure-Python wheels. - This method doesn't guarantee directly that the wheel will run. It only guarantees that there is no mismatch in Python ABI tags between what the environment supports, and what the wheel supports.
PARAMETER | DESCRIPTION |
---|---|
valid_abi_tags
|
List of ABI tags supported by a runtime environment.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether the Python tags of the environment, and the wheel, are compatible. |
Source code in blext/pydeps/pydep_wheel.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
|
works_with_platform
works_with_platform(
*,
bl_platform: BLPlatform,
min_glibc_version: tuple[int, int] | None,
min_macos_version: tuple[int, int] | None,
) -> bool
Whether this wheel ought to run on the given platform.
PARAMETER | DESCRIPTION |
---|---|
bl_platform
|
The Blender platform that the wheel would be run on.
TYPE:
|
min_glibc_version
|
The minimum version of
TYPE:
|
min_macos_version
|
The minimum version of
TYPE:
|
Notes
extyp.BLPlatform
only denotes a partial set of compatibility constraints,
namely, particular OS / CPU architecture combinations.
It does not a sufficient set of compatibility constraints to be able to say, for instance, "this wheel will work with any Linux version of Blender".
A version of Blender versions comes with a Python runtime environment that imposes very important constraints such as: - Supported Python tags. - Supported ABI tags.
To deduce final wheel compatibility, both the BLPlatform and the information derived from the Blender version must be checked.
Source code in blext/pydeps/pydep_wheel.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
|
works_with_python_tags
works_with_python_tags(
valid_python_tags: frozenset[str],
) -> bool
Does this wheel work with a runtime that supports python_tags
?
Notes
This method doesn't guarantee directly that the wheel will run. It only guarantees that there is no mismatch in Python tags between what the environment supports, and what the wheel supports.
PARAMETER | DESCRIPTION |
---|---|
valid_python_tags
|
List of Python tags supported by a runtime environment.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether the Python tags of the environment, and the wheel, are compatible. |
Source code in blext/pydeps/pydep_wheel.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
|
blext.pydeps.uv
Tools for managing wheel-based dependencies.
parse_requirements_txt
parse_requirements_txt(
path_uv_lock: Path,
*,
path_uv_exe: Path | None = None,
include_hashes: bool = False,
include_dev: bool = False,
include_editable: bool = False,
include_comment_header: bool = False,
) -> tuple[str, ...]
Get Python dependencies of a project as lines of a requirements.txt
file.
Notes
- Runs
uv export
with various options, under the hood. - Always runs with
--locked
, to ensure thatuv.lock
is unaltered by this function.
PARAMETER | DESCRIPTION |
---|---|
path_uv_lock
|
Where to generate the
TYPE:
|
path_uv_exe
|
Path to the
TYPE:
|
include_hashes
|
Include specific allowed wheel hashes in the generated
TYPE:
|
include_dev
|
Include dependencies marked as "development only".
TYPE:
|
include_editable
|
Include "editable" dependencies, for instance from local filesystem paths.
TYPE:
|
include_comment_header
|
Include a comment describing how
TYPE:
|
Source code in blext/pydeps/uv.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
parse_uv_lock
parse_uv_lock(
path_uv_lock: Path,
*,
path_uv_exe: Path,
force_update: bool = True,
) -> frozendict[str, Any]
Parse a uv.lock
file.
Notes
A uv.lock
file contains the platform-independent dependency resolution for a Python project managed with uv
.
By working directly with uv
's lockfiles, accessing data such as size, hash, and download URLs for wheels may be done in a lightweight manner, ex. without the need for a venv
.
PARAMETER | DESCRIPTION |
---|---|
path_uv_lock
|
Path to the
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
frozendict[str, Any]
|
The dictionary parsed from |
Source code in blext/pydeps/uv.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
update_uv_lock
update_uv_lock(
path_uv_lock: Path, *, path_uv_exe: Path
) -> None
Run uv lock
within a uv
project, which generates / update the lockfile uv.lock
.
PARAMETER | DESCRIPTION |
---|---|
path_uv_lock
|
Where to generate the
TYPE:
|
path_uv_exe
|
Path to the
TYPE:
|
Source code in blext/pydeps/uv.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|