Compare commits

...

3 Commits
main ... v1.20

Author SHA1 Message Date
Sybren A. Stüvel
6eee0f502b Bump version to 1.20 and mark it as released today 2025-08-25 11:49:01 +02:00
Andrej730
79c8589bfc Add additional annotations to avoid typing issues (#92897)
BlendFileBlock attributes:

Explicit annotation on BlendFileBlock are needed because otherwise
e.g. `block.add_old` type was imprecisely inferred from the
assignments as `int | Any`, where `Any` comes from `.unpack` returning
`tuple[Any, ...]`.

Ideally unpack should be somehow connected to the returned types, but
this solution should work for now just to avoid typing errors.

dna_io - add some missing annotations:

Some annotations were needed to ensure `block.code` will be inferred
as `bytes` and not `bytes | Unknown`.

Reviewed-on: https://projects.blender.org/blender/blender-asset-tracer/pulls/92897
Reviewed-by: Sybren A. Stüvel <sybren@blender.org>
2025-07-28 15:32:57 +02:00
Andrej730
899f361fcf README - code example to use Python syntax highlighting (#92894)
Added explicit code block  for Python syntax highlighting.

Reviewed-on: https://projects.blender.org/blender/blender-asset-tracer/pulls/92894
2025-07-28 15:01:00 +02:00
7 changed files with 53 additions and 45 deletions

View File

@ -3,7 +3,7 @@
This file logs the changes that are actually interesting to users (new features, This file logs the changes that are actually interesting to users (new features,
changed functionality, fixed bugs). changed functionality, fixed bugs).
# Version 1.20 (in development) # Version 1.20 (2025-07-11)
- Add support for Blender 5.0 compositor node trees ([16c208bc8e13](https://projects.blender.org/blender/blender-asset-tracer/commit/16c208bc8e130c8b1233bdb411ecabdab19af3c5)). - Add support for Blender 5.0 compositor node trees ([16c208bc8e13](https://projects.blender.org/blender/blender-asset-tracer/commit/16c208bc8e130c8b1233bdb411ecabdab19af3c5)).
- Make it possible to run BAT with `python -m blender_asset_tracer` ([6c42d06f0590](https://projects.blender.org/blender/blender-asset-tracer/commit/6c42d06f05909d4ac2096e84557d19dd93382f3a)). - Make it possible to run BAT with `python -m blender_asset_tracer` ([6c42d06f0590](https://projects.blender.org/blender/blender-asset-tracer/commit/6c42d06f05909d4ac2096e84557d19dd93382f3a)).

View File

@ -75,49 +75,51 @@ Mypy likes to see the return type of `__init__` methods explicitly declared as `
BAT can be used as a Python library to inspect the contents of blend files, without having to BAT can be used as a Python library to inspect the contents of blend files, without having to
open Blender itself. Here is an example showing how to determine the render engine used: open Blender itself. Here is an example showing how to determine the render engine used:
#!/usr/bin/env python3.7 ```python
import json #!/usr/bin/env python3.7
import sys import json
from pathlib import Path import sys
from pathlib import Path
from blender_asset_tracer import blendfile from blender_asset_tracer import blendfile
from blender_asset_tracer.blendfile import iterators from blender_asset_tracer.blendfile import iterators
if len(sys.argv) != 2: if len(sys.argv) != 2:
print(f'Usage: {sys.argv[0]} somefile.blend', file=sys.stderr) print(f'Usage: {sys.argv[0]} somefile.blend', file=sys.stderr)
sys.exit(1) sys.exit(1)
bf_path = Path(sys.argv[1]) bf_path = Path(sys.argv[1])
bf = blendfile.open_cached(bf_path) bf = blendfile.open_cached(bf_path)
# Get the first window manager (there is probably exactly one). # Get the first window manager (there is probably exactly one).
window_managers = bf.find_blocks_from_code(b'WM') window_managers = bf.find_blocks_from_code(b'WM')
assert window_managers, 'The Blend file has no window manager' assert window_managers, 'The Blend file has no window manager'
window_manager = window_managers[0] window_manager = window_managers[0]
# Get the scene from the first window. # Get the scene from the first window.
windows = window_manager.get_pointer((b'windows', b'first')) windows = window_manager.get_pointer((b'windows', b'first'))
for window in iterators.listbase(windows): for window in iterators.listbase(windows):
scene = window.get_pointer(b'scene') scene = window.get_pointer(b'scene')
break break
# BAT can only return simple values, so it can't return the embedded # BAT can only return simple values, so it can't return the embedded
# struct 'r'. 'r.engine' is a simple string, though. # struct 'r'. 'r.engine' is a simple string, though.
engine = scene[b'r', b'engine'].decode('utf8') engine = scene[b'r', b'engine'].decode('utf8')
xsch = scene[b'r', b'xsch'] xsch = scene[b'r', b'xsch']
ysch = scene[b'r', b'ysch'] ysch = scene[b'r', b'ysch']
size = scene[b'r', b'size'] / 100.0 size = scene[b'r', b'size'] / 100.0
render_info = { render_info = {
'engine': engine, 'engine': engine,
'frame_pixels': { 'frame_pixels': {
'x': int(xsch * size), 'x': int(xsch * size),
'y': int(ysch * size), 'y': int(ysch * size),
}, },
} }
json.dump(render_info, sys.stdout, indent=4, sort_keys=True) json.dump(render_info, sys.stdout, indent=4, sort_keys=True)
print() print()
```
To understand the naming of the properties, look at Blender's `DNA_xxxx.h` files with struct To understand the naming of the properties, look at Blender's `DNA_xxxx.h` files with struct
definitions. It is those names that are accessed via `blender_asset_tracer.blendfile`. The definitions. It is those names that are accessed via `blender_asset_tracer.blendfile`. The
@ -171,6 +173,6 @@ index-servers =
pip install twine pip install twine
poetry build poetry build
poetry run twine check dist/blender_asset_tracer-1.19.tar.gz dist/blender_asset_tracer-1.19-*.whl poetry run twine check dist/blender_asset_tracer-1.20.tar.gz dist/blender_asset_tracer-1.20-*.whl
poetry run twine upload -r bat dist/blender_asset_tracer-1.19.tar.gz dist/blender_asset_tracer-1.19-*.whl poetry run twine upload -r bat dist/blender_asset_tracer-1.20.tar.gz dist/blender_asset_tracer-1.20-*.whl
``` ```

View File

@ -20,4 +20,4 @@
# <pep8 compliant> # <pep8 compliant>
__version__ = "1.19" __version__ = "1.20"

View File

@ -447,6 +447,12 @@ class BlendFileBlock:
old_structure = struct.Struct(b"4sI") old_structure = struct.Struct(b"4sI")
"""old blend files ENDB block structure""" """old blend files ENDB block structure"""
# Explicitly annotate to avoid `Any` from `.unpack()`.
size: int
addr_old: int
sdna_index: int
count: int
def __init__(self, bfile: BlendFile) -> None: def __init__(self, bfile: BlendFile) -> None:
self.bfile = bfile self.bfile = bfile

View File

@ -204,17 +204,17 @@ class EndianIO:
return fileobj.write(to_write) return fileobj.write(to_write)
@classmethod @classmethod
def read_bytes0(cls, fileobj, length): def read_bytes0(cls, fileobj: typing.IO[bytes], length: int) -> bytes:
data = fileobj.read(length) data = fileobj.read(length)
return cls.read_data0(data) return cls.read_data0(data)
@classmethod @classmethod
def read_data0_offset(cls, data, offset): def read_data0_offset(cls, data: bytes, offset: int) -> bytes:
add = data.find(b"\0", offset) - offset add = data.find(b"\0", offset) - offset
return data[offset : offset + add] return data[offset : offset + add]
@classmethod @classmethod
def read_data0(cls, data): def read_data0(cls, data: bytes) -> bytes:
add = data.find(b"\0") add = data.find(b"\0")
if add < 0: if add < 0:
return data return data

View File

@ -24,9 +24,9 @@ copyright = '2018, Sybren A. Stüvel'
author = 'Sybren A. Stüvel' author = 'Sybren A. Stüvel'
# The short X.Y version # The short X.Y version
version = '1.19' version = '1.20'
# The full version, including alpha/beta/rc tags # The full version, including alpha/beta/rc tags
release = '1.19' release = '1.20'
# -- General configuration --------------------------------------------------- # -- General configuration ---------------------------------------------------

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "blender-asset-tracer" name = "blender-asset-tracer"
version = "1.19" version = "1.20"
homepage = 'https://developer.blender.org/project/profile/79/' homepage = 'https://developer.blender.org/project/profile/79/'
description = "BAT parses Blend files and produces dependency information. After installation run `bat --help`" description = "BAT parses Blend files and produces dependency information. After installation run `bat --help`"