Skip to content

Commit e250336

Browse files
committed
Simplify vendored flatbuffers - use upstream as-is
- Simplify update-flatbuffers to just copy files (like zlmdb) - Remove _git_version.py and version() function - Rely on upstream's __version__ in _version.py - Vendored files are excluded from ruff via pyproject.toml Note: This work was completed with AI assistance (Claude Code).
1 parent 03e2e15 commit e250336

File tree

21 files changed

+2438
-3021
lines changed

21 files changed

+2438
-3021
lines changed

justfile

Lines changed: 4 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,140 +1285,11 @@ bump-flatbuffers:
12851285
echo " 3. git commit -m 'Bump vendored flatbuffers to ${LATEST_TAG}'"
12861286

12871287
# Update vendored flatbuffers Python runtime from git submodule
1288-
# Copies files, runs ruff autoformat, and adds version() function
12891288
update-flatbuffers:
1290-
#!/usr/bin/env python3
1291-
import shutil
1292-
import subprocess
1293-
import textwrap
1294-
from pathlib import Path
1295-
1296-
src_dir = Path("deps/flatbuffers/python/flatbuffers")
1297-
dst_dir = Path("src/autobahn/flatbuffers")
1298-
1299-
if not src_dir.exists():
1300-
print(f"ERROR: Flatbuffers submodule not found at {src_dir}")
1301-
print("Run: git submodule update --init --recursive")
1302-
raise SystemExit(1)
1303-
1304-
# Get git version from submodule
1305-
result = subprocess.run(
1306-
["git", "describe", "--tags", "--always"],
1307-
cwd="deps/flatbuffers",
1308-
capture_output=True, text=True, timeout=10
1309-
)
1310-
git_version = result.stdout.strip() if result.returncode == 0 else "unknown"
1311-
print(f"==> Updating vendored flatbuffers from submodule ({git_version})...")
1312-
1313-
# Remove old vendored copy and copy fresh
1314-
if dst_dir.exists():
1315-
shutil.rmtree(dst_dir)
1316-
shutil.copytree(src_dir, dst_dir)
1317-
1318-
# Generate _git_version.py
1319-
git_version_py = textwrap.dedent(f"""\
1320-
# Copyright 2014 Google Inc. All rights reserved.
1321-
#
1322-
# Licensed under the Apache License, Version 2.0 (the "License");
1323-
# you may not use this file except in compliance with the License.
1324-
# You may obtain a copy of the License at
1325-
#
1326-
# http://www.apache.org/licenses/LICENSE-2.0
1327-
#
1328-
# Unless required by applicable law or agreed to in writing, software
1329-
# distributed under the License is distributed on an "AS IS" BASIS,
1330-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1331-
# See the License for the specific language governing permissions and
1332-
# limitations under the License.
1333-
1334-
# Git version from deps/flatbuffers submodule.
1335-
# This file is generated by: just update-flatbuffers
1336-
# The version is captured via `git describe --tags --always` in the submodule.
1337-
#
1338-
# Format: "v25.9.23" (tagged release) or "v25.9.23-2-g95053e6a" (post-tag)
1339-
1340-
__git_version__ = "{git_version}"
1341-
""")
1342-
(dst_dir / "_git_version.py").write_text(git_version_py)
1343-
1344-
# Generate __init__.py with version() function
1345-
init_py = textwrap.dedent('''\
1346-
# Copyright 2014 Google Inc. All rights reserved.
1347-
#
1348-
# Licensed under the Apache License, Version 2.0 (the "License");
1349-
# you may not use this file except in compliance with the License.
1350-
# You may obtain a copy of the License at
1351-
#
1352-
# http://www.apache.org/licenses/LICENSE-2.0
1353-
#
1354-
# Unless required by applicable law or agreed to in writing, software
1355-
# distributed under the License is distributed on an "AS IS" BASIS,
1356-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1357-
# See the License for the specific language governing permissions and
1358-
# limitations under the License.
1359-
1360-
import re
1361-
1362-
from . import util
1363-
from ._git_version import __git_version__
1364-
from ._version import __version__
1365-
from .builder import Builder
1366-
from .compat import range_func as compat_range
1367-
from .table import Table
1368-
1369-
1370-
def version() -> tuple[int, int, int, int | None, str | None]:
1371-
"""
1372-
Return the exact git version of the vendored FlatBuffers runtime.
1373-
1374-
Handles:
1375-
1376-
1. "v25.9.23" -> (25, 9, 23, None, None) # Release (Named Tag, CalVer Year.Month.Day)
1377-
2. "v25.9.23-71" -> (25, 9, 23, 71, None) # 71 commits ahead of the Release v25.9.23
1378-
3. "v25.9.23-71-g19b2300f" -> (25, 9, 23, 71, "19b2300f") # dito, with Git commit hash
1379-
"""
1380-
1381-
# Pattern explanation:
1382-
# ^v : Start of string, literal 'v'
1383-
# (\\d+)\\.(\\d+)\\.(\\d+) : Groups 1,2,3 - Major.Minor.Patch (Required)
1384-
#
1385-
# (?: ... )? : Non-capturing group (grouping only, not saved), optional '?'
1386-
# -(\\d+) : Literal hyphen, Group 4 (Commits)
1387-
#
1388-
# (?: ... )? : Non-capturing group, optional '?'
1389-
# -g : Literal hyphen and 'g' (separator)
1390-
# ([0-9a-f]+) : Group 5 (Hash)
1391-
1392-
pattern = r"^v(\\d+)\\.(\\d+)\\.(\\d+)(?:-(\\d+))?(?:-g([0-9a-f]+))?$"
1393-
1394-
match = re.match(pattern, __git_version__)
1395-
1396-
if match:
1397-
major, minor, patch, commits, commit_hash = match.groups()
1398-
1399-
# Convert commits to int if present, else None
1400-
commits_int = int(commits) if commits else None
1401-
1402-
return (int(major), int(minor), int(patch), commits_int, commit_hash)
1403-
1404-
# Fallback if regex fails entirely (returns 0.0.0 to satisfy type hint)
1405-
return (0, 0, 0, None, None)
1406-
''')
1407-
(dst_dir / "__init__.py").write_text(init_py)
1408-
1409-
# Run ruff autoformat on vendored files
1410-
try:
1411-
print("==> Running ruff format on vendored files...")
1412-
subprocess.run(["ruff", "format", str(dst_dir)], check=False)
1413-
subprocess.run(["ruff", "check", "--fix", str(dst_dir)], check=False)
1414-
except FileNotFoundError:
1415-
print("WARNING: ruff not found, skipping autoformat")
1416-
1417-
print(f"✓ Flatbuffers vendor updated in {dst_dir}")
1418-
print()
1419-
print("Next steps:")
1420-
print(" 1. git add deps/flatbuffers src/autobahn/flatbuffers")
1421-
print(f" 2. git commit -m 'Update vendored flatbuffers to {git_version}'")
1289+
echo "==> Updating vendored flatbuffers from submodule..."
1290+
rm -rf ./src/autobahn/flatbuffers
1291+
cp -R deps/flatbuffers/python/flatbuffers ./src/autobahn/flatbuffers
1292+
echo "✓ Flatbuffers vendor updated in src/autobahn/flatbuffers"
14221293

14231294
# Build wheel only (usage: `just build cpy314`)
14241295
build venv="": (install-build-tools venv)

src/autobahn/flatbuffers/__init__.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import re
16-
1715
from . import util
18-
from ._git_version import __git_version__
1916
from ._version import __version__
2017
from .builder import Builder
2118
from .compat import range_func as compat_range
2219
from .table import Table
23-
24-
25-
def version() -> tuple[int, int, int, int | None, str | None]:
26-
"""
27-
Return the exact git version of the vendored FlatBuffers runtime.
28-
29-
Handles:
30-
31-
1. "v25.9.23" -> (25, 9, 23, None, None) # Release (Named Tag, CalVer Year.Month.Day)
32-
2. "v25.9.23-71" -> (25, 9, 23, 71, None) # 71 commits ahead of the Release v25.9.23
33-
3. "v25.9.23-71-g19b2300f" -> (25, 9, 23, 71, "19b2300f") # dito, with Git commit hash
34-
"""
35-
36-
# Pattern explanation:
37-
# ^v : Start of string, literal 'v'
38-
# (\d+)\.(\d+)\.(\d+) : Groups 1,2,3 - Major.Minor.Patch (Required)
39-
#
40-
# (?: ... )? : Non-capturing group (grouping only, not saved), optional '?'
41-
# -(\d+) : Literal hyphen, Group 4 (Commits)
42-
#
43-
# (?: ... )? : Non-capturing group, optional '?'
44-
# -g : Literal hyphen and 'g' (separator)
45-
# ([0-9a-f]+) : Group 5 (Hash)
46-
47-
pattern = r"^v(\d+)\.(\d+)\.(\d+)(?:-(\d+))?(?:-g([0-9a-f]+))?$"
48-
49-
match = re.match(pattern, __git_version__)
50-
51-
if match:
52-
major, minor, patch, commits, commit_hash = match.groups()
53-
54-
# Convert commits to int if present, else None
55-
commits_int = int(commits) if commits else None
56-
57-
return (int(major), int(minor), int(patch), commits_int, commit_hash)
58-
59-
# Fallback if regex fails entirely (returns 0.0.0 to satisfy type hint)
60-
return (0, 0, 0, None, None)

src/autobahn/flatbuffers/_git_version.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)