blext
blext.blender
Run the Blender command in various useful ways.
ATTRIBUTE | DESCRIPTION |
---|---|
PATH_BLENDER_PYTHON_SCRIPTS |
Python source code to be executed inside of Blender.
This is shipped with
|
detect_blender_version
detect_blender_version(blender_exe: Path) -> BLVersion
Detect the version of Blender by running blender --version
.
Source code in blext/blender.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
run_blender
run_blender(
blender_exe: Path,
startup_script: Path | None = None,
factory_startup: bool = True,
headless: bool = False,
args: tuple[str, ...] = (),
env: frozendict[str, str] = _EMPTY_FROZENDICT,
capture: bool = True,
block: bool = True,
bufsize: int = 0,
) -> Popen[str] | Popen[bytes]
Run a Blender command.
Notes
Env Security: For security reasons, it may be desirable to use a minimal env
. Depending on the threat model, passing os.environ
may be sufficient, as this is generally not less secure than launching Blender normally.
Handling CTRL+C
: When block=False
, CTRL+C
(aka. KeyboardInterrupt
) will not automatically close the Blender subprocess.
Signal Handlers: This function does not register signal handlers.
When block=True
, CTRL+C
is handled with a try/except
that catches KeyboardInterrupt
.
The behavior of CTRL+C
while this function is running is as follows:
- When
block=True
,CTRL+C
will also exit the underlying Blender process. - When
block=False
,CTRL+C
must be manually handled.
PARAMETER | DESCRIPTION |
---|---|
blender_exe
|
Path to a valid Blender executable.
TYPE:
|
startup_script
|
Path to a Python script to run as Blender starts.
TYPE:
|
factory_startup
|
Temporarily reset Blender to factory settings.
TYPE:
|
headless
|
Run Blender without a user interface.
TYPE:
|
args
|
Extra CLI arguments to pass to the Blender command invocation.
TYPE:
|
env
|
Environment variables to set.
TYPE:
|
capture
|
Whether to capture
TYPE:
|
block
|
Wait for
TYPE:
|
bufsize
|
Passthrough to
TYPE:
|
Source code in blext/blender.py
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 |
|
run_extension
run_extension(
blender_exe: Path,
*,
path_zip: Path,
path_blend: Path | None = None,
headless: bool = False,
factory_startup: bool = True,
) -> None
Run a Blender extension inside of Blender.
Notes
Data is passed to the startup script via env vars:
- BLEXT_ZIP_PATH
: Path to the extension zipfile to install and run.
PARAMETER | DESCRIPTION |
---|---|
blender_exe
|
Path to a valid Blender executable.
TYPE:
|
path_zip
|
Extension zipfile to check.
TYPE:
|
path_blend
|
Optional
TYPE:
|
headless
|
Whether to run Blender without a UI.
TYPE:
|
factory_startup
|
Temporarily reset Blender to factory settings.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If an invalid zipfile path was given, or the extension failed to validate. |
Source code in blext/blender.py
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 |
|
validate_extension
validate_extension(
blender_exe: Path, *, path_zip: Path
) -> None
Run Blender's builtin validation procedure on a built extension zipfile.
PARAMETER | DESCRIPTION |
---|---|
blender_exe
|
Path to a valid Blender executable.
TYPE:
|
path_zip
|
Path to the extension zipfile to check.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If an invalid zipfile path was given, or the extension failed to validate. |
Source code in blext/blender.py
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 |
|
blext.pack
Packing and pre-packing of Blender extension zipfiles from a specification and raw files.
existing_prepacked_files
existing_prepacked_files(
all_files_to_prepack: frozendict[Path, Path]
| dict[Path, Path],
*,
path_zip_prepack: Path,
) -> frozenset[Path]
Determine which files do not need to be pre-packed again, since they already exist in a pre-packed zipfile.
PARAMETER | DESCRIPTION |
---|---|
all_files_to_prepack
|
Mapping from host files to files in the zip. All files specified here should be available in the final pre-packed zip.
TYPE:
|
path_zip_prepack
|
Path to an existing pre-packed zipfile. If no file exists, then all files are assumed to need pre-packing.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
frozenset[Path]
|
Set of files that need to be pre-packed. |
See Also
blext.pack.prepack_extension
: The output should be passed to this function, to perform the actual pre-packing.
Source code in blext/pack.py
30 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 66 |
|
pack_bl_extension
pack_bl_extension(
blext_spec: BLExtSpec,
*,
bl_version: BLVersion,
overwrite: bool = True,
path_zip_prepack: Path,
path_zip: Path,
path_pysrc: Path,
cb_update_status: Callable[
[str], list[None] | None
] = lambda *_: None,
) -> None
Pack all files needed by a Blender extension, into an installable .zip
.
Configuration data is sourced from paths
, which in turns sources much of its user-facing configuration from pyproject.toml
.
PARAMETER | DESCRIPTION |
---|---|
blext_spec
|
The extension specification to pack the zip file base on.
TYPE:
|
bl_version
|
The Blender version to pack into the zipfile.
TYPE:
|
overwrite
|
If packing to a zip file that already exists, replace it.
TYPE:
|
path_zip_prepack
|
Path to the prepacked zipfile.
TYPE:
|
path_zip
|
Path to the zipfile to pack.
TYPE:
|
path_pysrc
|
Path to the Python source code to pack as the extension package.
TYPE:
|
Source code in blext/pack.py
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 |
|
prepack_extension
prepack_extension(
files_to_prepack: frozendict[Path, Path]
| dict[Path, Path],
*,
path_zip_prepack: Path,
cb_pre_file_write: Callable[
[Path, Path], Any
] = lambda *_: None,
cb_post_file_write: Callable[
[Path, Path], Any
] = lambda *_: None,
) -> None
Pre-pack zipfile containing large files, but not the extension code.
Notes
Writing extension source code to a zipfile is very fast. However, when working with ex. wheel dependencies, large files can quickly dominate the build time.
Therefore, blext
first generates "pre-packed" zipfile extensions.
This takes awhile, but is only done once (and/or when a big file changes).
Then, blext
copies the pre-packed zip and adds the extension source code.
Since changing source code doesn't re-pack large files, iteration speed is preserved.
PARAMETER | DESCRIPTION |
---|---|
files_to_prepack
|
Mapping from host files to files in the zip. All files specified here will be packed.
TYPE:
|
path_zip_prepack
|
The zip file to pre-pack.
TYPE:
|
cb_pre_file_write
|
Called before each file is written to the zip. Defaults is no-op.
TYPE:
|
cb_post_file_write
|
Called after each file is written to the zip. Defaults is no-op.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
When not all wheels required by |
See Also
blext.pack.existing_prepacked_files
: Use to pre-filterfiles_to_prepack
, in order to only pack files that aren't already present.
Source code in blext/pack.py
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 |
|
blext.spec
Defines the Blender extension specification.
BLExtSpec
pydantic-model
Bases: BaseModel
Specifies a Blender extension.
This model allows pyproject.toml
to be the single source of truth for a Blender extension project.
Thus, this model is designed to be parsed entirely from a pyproject.toml
file, and in turn is capable of generating the Blender extension manifest file and more.
To the extent possible, appropriate standard pyproject.toml
fields are scraped for information relevant to a Blender extension. | None = None
This includes name, version, license, desired dependencies, homepage, and more.
Naturally, many fields are quite specific to Blender extensions, such as Blender version constraints, permissions, and extension tags.
For such options, the [tool.blext]
section is introduced.
ATTRIBUTE | DESCRIPTION |
---|---|
wheels_graph |
All wheels that might be usable by this extension.
|
release_profile |
Optional initialization settings and spec overrides. Overrides must be applied during construction.
TYPE:
|
id |
Unique identifying name of the extension.
TYPE:
|
name |
Pretty, user-facing name of the extension.
TYPE:
|
version |
The version of the extension.
TYPE:
|
tagline |
Short description of the extension.
TYPE:
|
maintainer |
Primary maintainer of the extension (name and email).
TYPE:
|
type |
Type of extension.
Currently, only
TYPE:
|
blender_version_min |
The minimum version of Blender that this extension supports.
TYPE:
|
blender_version_max |
The maximum version of Blender that this extension supports.
TYPE:
|
wheels |
Relative paths to wheels distributed with this extension. These should be installed by Blender alongside the extension. See https://docs.blender.org/manual/en/dev/extensions/python_wheels.html for more information.
TYPE:
|
permissions |
Permissions required by the extension.
TYPE:
|
tags |
Tags for categorizing the extension.
TYPE:
|
license |
License of the extension's source code.
TYPE:
|
copyright |
Copyright declaration of the extension.
TYPE:
|
website |
Homepage of the extension.
TYPE:
|
References
Fields:
-
bl_platforms
(frozenset[BLPlatform]
) -
deps
(BLExtDeps
) -
release_profile
(ReleaseProfile | None
) -
id
(str
) -
name
(str
) -
tagline
(str
) -
version
(SemanticVersion
) -
license
(SPDXLicense
) -
blender_version_min
(str
) -
blender_version_max
(str | None
) -
permissions
(FrozenDict[Literal['files', 'network', 'clipboard', 'camera', 'microphone'], str] | None
) -
copyright
(tuple[str, ...] | None
) -
maintainer
(str | None
) -
tags
(frozenset[str] | None
) -
website
(HttpUrl | None
)
Validators:
bl_versions
cached
property
bl_versions: frozenset[BLVersion]
All Blender versions supported by this extension.
Notes
blext
doesn't support official Blender versions released after a particular blext
version was published.
This is because blext
has no way of knowing critical information about such future releases, ex. the versions of vendored site-packages
dependencies.
Derived by comparing self.blender_version_min
and self.blender_version_max
to hard-coded Blender versions that have already been released, whose properties are known.
bl_versions_by_granular
cached
property
All Blender versions supported by this extension, indexed by the granular input version.
Notes
blext
doesn't support official Blender versions released after a particular blext
version was published.
This is because blext
has no way of knowing critical information about such future releases, ex. the versions of vendored site-packages
dependencies.
Derived by comparing self.blender_version_min
and self.blender_version_max
to hard-coded Blender versions that have already been released, whose properties are known.
bl_versions_by_wheel
cached
property
bl_versions_by_wheel: frozendict[
PyDepWheel, frozenset[BLVersion]
]
Blender versions by wheel.
is_universal
cached
property
is_universal: bool
Whether this extension is works on all platforms of all supported Blender versions.
Notes
Pure-Python extensions that only use pure-Python dependencies are considered "universal".
Once any non-pure-Python wheels are introduced, this condition may become very difficult to uphold, depending on which wheels are available for supported platforms.
wheels
cached
property
wheels: frozendict[BLVersion, frozenset[PyDepWheel]]
Python wheels by (smooshed) Blender version and Blender platform.
bl_manifest
bl_manifest(
bl_manifest_version: BLManifestVersion,
*,
bl_version: BLVersion,
) -> BLManifest
Export the Blender extension manifest.
Notes
Only fmt='toml'
results in valid contents of blender_manifest.toml
.
This is also the default.
Other formats are included to enable easier interoperability with other systems - not with Blender.
PARAMETER | DESCRIPTION |
---|---|
bl_manifest_version
|
The Blender manifest schema version to export to the appropriate filename.
TYPE:
|
bl_version
|
The Blender version to export a manifest schema for.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
BLManifest
|
String representing the Blender extension manifest. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
When |
Source code in blext/spec.py
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 |
|
cached_wheels
cached_wheels(
*,
path_wheels: Path,
bl_versions: frozenset[BLVersion] | None = None,
) -> frozenset[PyDepWheel]
Wheels that have already been correctly downloaded.
Source code in blext/spec.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 |
|
export_blender_manifest
export_blender_manifest(
bl_manifest_version: BLManifestVersion,
*,
bl_version: BLVersion,
fmt: Literal['json', 'toml'],
) -> str
Export the Blender extension manifest.
Notes
Only fmt='toml'
results in valid contents of blender_manifest.toml
.
This is also the default.
Other formats are included to enable easier interoperability with other systems - not with Blender.
PARAMETER | DESCRIPTION |
---|---|
fmt
|
String format to export Blender manifest to.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
String representing the Blender extension manifest. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
When |
Source code in blext/spec.py
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 |
|
export_extension_filenames
export_extension_filenames(
with_bl_version: bool = True,
with_bl_platforms: bool = True,
) -> frozendict[BLVersion, str]
Default filename of the extension zipfile.
Source code in blext/spec.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
|
from_proj_spec_dict
classmethod
from_proj_spec_dict(
proj_spec_dict: dict[str, Any],
*,
path_uv_exe: Path,
path_proj_spec: Path,
release_profile_id: StandardReleaseProfile | str | None,
) -> Self
Parse an extension spec from a dictionary.
Notes
-
The dictionary is presumed to be loaded directly from either a
pyproject.toml
file or inline script metadata. Therefore, please refer to thepyproject.toml
documentation for more on the dictionary's structure. -
This method aims to "show its work", in explaining exactly why parsing fails. To provide pleasant user feedback, print
ValueError
arguments as Markdown.
PARAMETER | DESCRIPTION |
---|---|
proj_spec_dict
|
Dictionary representation of a
TYPE:
|
path_proj_spec
|
Path to the file that defines the extension project.
TYPE:
|
release_profile_id
|
Identifier to deduce release profile settings with.
TYPE:
|
path_uv_exe
|
Optional overriden path to a
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the dictionary cannot be parsed to a complete |
Source code in blext/spec.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 |
|
from_proj_spec_path
classmethod
from_proj_spec_path(
path_proj_spec: Path,
*,
path_uv_exe: Path,
release_profile_id: StandardReleaseProfile | str | None,
) -> Self
Parse an extension specification from a compatible file.
PARAMETER | DESCRIPTION |
---|---|
path_proj_spec
|
Path to either a
TYPE:
|
release_profile_id
|
Identifier for the release profile.
TYPE:
|
path_uv_exe
|
Optional overriden path to a
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the |
Source code in blext/spec.py
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 |
|
missing_wheels
missing_wheels(
*,
path_wheels: Path,
bl_versions: frozenset[BLVersion] | None = None,
) -> frozenset[PyDepWheel]
Wheels that need to be downloaded, since they are not available / valid.
Source code in blext/spec.py
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
|
replace_bl_platforms
replace_bl_platforms(
bl_platforms: frozenset[BLPlatform],
) -> Self
Create a copy of this extension spec, with altered platform support.
Notes
By default, an extension specification defines a wide range of supported platforms.
Sometimes, it's important to consider the same extension defined only for a subset of platforms (for example, to build the extension only for Windows). This amounts to a "new extension", which can be generated using this method.
PARAMETER | DESCRIPTION |
---|---|
bl_platforms
|
The Blender platforms to support exclusively.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
A copy of |
Self
|
In practice, |
Source code in blext/spec.py
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 |
|
set_default_bl_platforms_to_universal
pydantic-validator
set_default_bl_platforms_to_universal(data: Any) -> Any
Set the default BLPlatforms to the largest common subset of platforms supported by given Blender versions.
Source code in blext/spec.py
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 |
|
validate_tags_against_bl_versions
pydantic-validator
validate_tags_against_bl_versions() -> Self
Validate that all extension tags can actually be parsed by all supported Blender versions.
Source code in blext/spec.py
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 |
|
wheel_paths_to_prepack
wheel_paths_to_prepack(
*, path_wheels: Path
) -> frozendict[BLVersion, frozendict[Path, Path]]
Wheel file paths that should be pre-packed.
Source code in blext/spec.py
491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
|