Skip to content

Commit 78638ae

Browse files
committed
Switch to uv and ruff
1 parent b5427f5 commit 78638ae

8 files changed

Lines changed: 345 additions & 68 deletions

File tree

.github/workflows/pipeline.yaml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,20 @@ jobs:
1010
runs-on: ${{ matrix.os }}
1111
steps:
1212
- uses: actions/checkout@v4
13-
- uses: actions/setup-python@v5
13+
- uses: astral-sh/setup-uv@v6
1414
with:
1515
python-version: ${{ matrix.pyversion }}
1616
- name: Run Tests
17-
run: |
18-
python -m pip install -e .[test]
19-
python -m pytest
17+
run: uv run pytest
2018
build:
2119
runs-on: ubuntu-latest
2220
steps:
2321
- uses: actions/checkout@v4
24-
- uses: actions/setup-python@v5
22+
- uses: astral-sh/setup-uv@v6
2523
with:
2624
python-version: 3.9
2725
- name: Build package
28-
run: |
29-
python -m pip install -e .
30-
python -m pip install --upgrade build
31-
python -m build
26+
run: uv build
3227
- name: Publish package
3328
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
3429
uses: pypa/gh-action-pypi-publish@release/v1

README.md

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,14 @@ This is a simple viewer (like `pview`) to view glTF (or any other file format su
7575

7676
## Running Tests
7777

78-
First install `panda3d-gltf` in editable mode along with `test` extras:
79-
80-
```bash
81-
pip install -e .[test]
82-
```
83-
84-
Then run the test suite with `pytest`:
85-
8678
```bash
87-
pytest
79+
uv run pytest
8880
```
8981

9082
## Building Wheels
9183

92-
Install `build`:
93-
94-
```bash
95-
pip install --upgrade build
96-
```
97-
98-
and run:
99-
10084
```bash
101-
python -m build
85+
uv build
10286
```
10387

10488
## License

gltf/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import panda3d.core as p3d
2-
31
from .version import __version__
42
from ._converter import GltfSettings
53
from ._loader import load_model

gltf/_converter.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
from __future__ import annotations
2-
31
import base64
42
import collections
53
import itertools
64
import os
75
import math
86
import struct
97
import urllib.parse
10-
import pprint # pylint: disable=unused-import
118

129
from dataclasses import dataclass
1310

14-
from panda3d.core import * # pylint: disable=wildcard-import
11+
from panda3d.core import *
1512
import panda3d.core as p3d
1613
try:
1714
from panda3d import bullet
1815
HAVE_BULLET = True
1916
except ImportError:
2017
HAVE_BULLET = False
21-
from direct.stdpy.file import open # pylint: disable=redefined-builtin
18+
from direct.stdpy.file import open # noqa: A004
2219

2320
from ._converter_maps import (
2421
ATTRIB_CONTENT_MAP,
@@ -111,8 +108,8 @@ def get_lerp_factor(currtime: float, lasttime: float, nexttime: float) -> float:
111108
class CharInfo:
112109
character: p3d.Character
113110
nodepath: p3d.NodePath
114-
jvtmap: 'dict[int, p3d.JointVertexTransform]'
115-
cvsmap: 'dict[tuple[int, str], p3d.CharacterVertexSlider]'
111+
jvtmap: dict[int, p3d.JointVertexTransform]
112+
cvsmap: dict[tuple[int, str], p3d.CharacterVertexSlider]
116113

117114
def __init__(self, name: str):
118115
self.character = p3d.Character(name)
@@ -121,9 +118,7 @@ def __init__(self, name: str):
121118
self.cvsmap = {}
122119

123120

124-
class Converter():
125-
126-
121+
class Converter:
127122
def __init__(
128123
self,
129124
filepath,
@@ -253,7 +248,7 @@ def add_node(root, gltf_scene, nodeid):
253248
charinfo = self.characters.get(skinid, None)
254249
scene_extras = get_extras(gltf_scene)
255250
node_name = gltf_node.get('name', 'node'+str(nodeid))
256-
if nodeid in self._joint_nodes and not nodeid in self.skeletons:
251+
if nodeid in self._joint_nodes and nodeid not in self.skeletons:
257252
# Handle non-joint children of joints, but don't add joints themselves
258253
for child_nodeid in gltf_node.get('children', []):
259254
add_node(root, gltf_scene, child_nodeid)
@@ -482,8 +477,10 @@ def load_buffer(self, buffid, gltf_buffer):
482477
uri = gltf_buffer['uri']
483478
if uri == '_glb_bin' and buffid == 0:
484479
buff_data = gltf_buffer['_glb_bin']
485-
elif uri.startswith('data:application/octet-stream;base64') or \
486-
uri.startswith('data:application/gltf-buffer;base64'):
480+
elif uri.startswith((
481+
'data:application/octet-stream;base64',
482+
'data:application/gltf-buffer;base64',
483+
)):
487484
buff_data = gltf_buffer['uri'].split(',')[1]
488485
buff_data = base64.b64decode(buff_data)
489486
elif uri.endswith('.bin'):
@@ -538,8 +535,7 @@ def get_buffer_from_accessor(self, gltf_data, accid, unpack=True):
538535

539536
if unpack:
540537
return list(map(convertfn, struct.iter_unpack(f'<{formatstr}', buffdata)))
541-
else:
542-
return buffdata
538+
return buffdata
543539

544540
def get_texture_stage(self, slot_name, texmode, texcoord):
545541
texcoord = str(texcoord)
@@ -916,14 +912,17 @@ def load_primitive(self, geom_node, gltf_primitive, gltf_mesh, gltf_data):
916912
accessors = sorted(accessors, key=lambda x: x['bufferView'])
917913
data_copies = []
918914
is_skinned = 'JOINTS_0' in mesh_attribs
919-
calc_normals = not 'NORMAL' in mesh_attribs
920-
calc_tangents = not 'TANGENT' in mesh_attribs
915+
calc_normals = 'NORMAL' not in mesh_attribs
916+
calc_tangents = 'TANGENT' not in mesh_attribs
921917
normalize_weights = False
922918

923-
for buffview, accs in itertools.groupby(accessors, key=lambda x: x['bufferView']):
919+
for buffview, accs_unsorted in itertools.groupby(accessors, key=lambda x: x['bufferView']):
924920
buffview = gltf_data['bufferViews'][buffview]
925-
accs = sorted(accs, key=lambda x: x.get('byteOffset', 0))
926-
is_interleaved = len(accs) > 1 and accs[1].get('byteOffset', 0) < buffview['byteStride']
921+
accs = sorted(accs_unsorted, key=lambda x: x.get('byteOffset', 0))
922+
is_interleaved = (
923+
len(accs) > 1
924+
and accs[1].get('byteOffset', 0) < buffview['byteStride']
925+
)
927926

928927
varray = GeomVertexArrayFormat()
929928
for acc in accs:
@@ -1585,18 +1584,18 @@ def calculate_frame_value(frame, path):
15851584

15861585
if interpolation_mode == 'STEP':
15871586
return output_buff[lastidx]
1588-
elif interpolation_mode == 'LINEAR':
1587+
1588+
if interpolation_mode == 'LINEAR':
15891589
nexttime = input_buff[nextidx]
15901590
lasttime = input_buff[lastidx]
15911591
lerpfactor = get_lerp_factor(currtime, lasttime, nexttime)
15921592

15931593
if path == 'rotation':
15941594
return slerp(output_buff[lastidx], output_buff[nextidx], lerpfactor)
15951595
return vlerp(output_buff[lastidx], output_buff[nextidx], lerpfactor)
1596-
else:
1597-
return RuntimeError(
1598-
f'Unrecognized interpolation mode ({interpolation_mode}) found on {bone_name}:{path}'
1599-
)
1596+
raise RuntimeError(
1597+
f'Unrecognized interpolation mode ({interpolation_mode}) found on {bone_name}:{path}'
1598+
)
16001599

16011600
for i in range(num_frames):
16021601
frame_translation = calculate_frame_value(i, 'translation')
@@ -1709,7 +1708,7 @@ def create_channels(parent, nodeid, target_names, default_weights):
17091708
+ target_weights[nextidx] * lerpfactor
17101709
)
17111710
else:
1712-
return RuntimeError(
1711+
raise RuntimeError(
17131712
f'Unrecognized interpolation mode ({interpolation_mode}) found on {target_name}'
17141713
)
17151714

@@ -1866,8 +1865,9 @@ def load_physics_bullet(self, node_name, geomnode, shape_type, bounding_box, rad
18661865
mass = 1.0 if gltf_rigidbody is None else gltf_rigidbody.get('mass', 1.0)
18671866
phynode.set_mass(mass)
18681867
return phynode
1869-
else:
1870-
print(f"Could not create collision shape for object ({node_name})")
1868+
1869+
print(f"Could not create collision shape for object ({node_name})")
1870+
return None
18711871

18721872
def load_physics_builtin(self, node_name, geomnode, shape_type, bounding_box, radius, height, intangible):
18731873
phynode = CollisionNode(node_name)
@@ -1975,5 +1975,6 @@ def load_physics_builtin(self, node_name, geomnode, shape_type, bounding_box, ra
19751975

19761976
if phynode.solids:
19771977
return phynode
1978-
else:
1979-
print(f"Could not create collision shape for object ({node_name})")
1978+
1979+
print(f"Could not create collision shape for object ({node_name})")
1980+
return None

gltf/_loader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ def load_model(file_path, gltf_settings=None):
1616

1717
def _config_var_for_type(var_type):
1818
return {
19-
'str': p3d.ConfigVariableString,
20-
'bool': p3d.ConfigVariableBool,
21-
'int': p3d.ConfigVariableInt,
19+
str: p3d.ConfigVariableString,
20+
bool: p3d.ConfigVariableBool,
21+
int: p3d.ConfigVariableInt,
2222
}.get(var_type, None)
2323

2424

gltf/parseutils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ def is_glb_file(filepath):
66
with open(filepath, 'rb') as glbfile:
77
if glbfile.read(4) == b'glTF':
88
return True
9-
else:
10-
return False
9+
return False
1110

1211

1312
def parse_glb_data(data):

pyproject.toml

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ dependencies = [
2424
"panda3d >= 1.10.8",
2525
"panda3d-simplepbr >= 0.6",
2626
]
27-
requires-python = ">= 3.8"
27+
requires-python = ">= 3.9"
2828

2929
[project.urls]
3030
homepage = "https://github.com/Moguri/panda3d-gltf"
3131

32-
[project.optional-dependencies]
33-
test = ["pytest", "pylint~=3.1.0", "pytest-pylint"]
32+
[dependency-groups]
33+
dev = [
34+
"pytest",
35+
"ruff>=0.12.9",
36+
"pytest-ruff",
37+
]
3438

3539
[project.scripts]
3640
gltf2bam = "gltf.cli:main"
@@ -48,5 +52,48 @@ packages = ["gltf"]
4852
[tool.setuptools.dynamic]
4953
version = {attr = "gltf.version.__version__"}
5054

55+
[tool.ruff.lint]
56+
extend-select = [
57+
#"ALL",
58+
"E",
59+
"F",
60+
"YTT",
61+
"ASYNC",
62+
"BLE",
63+
"B",
64+
"A",
65+
"C4",
66+
"PIE",
67+
"PT",
68+
"RSE",
69+
"RET",
70+
"SLF",
71+
"SLOT",
72+
"N",
73+
"PERF",
74+
"PLC",
75+
"PLE",
76+
"PLW",
77+
"UP",
78+
"FURB",
79+
# Try to enable these later
80+
#"S",
81+
#"I",
82+
#"COM",
83+
#"PTH",
84+
#"TRY",
85+
#"SIM",
86+
#"FBT",
87+
#"RUF",
88+
]
89+
ignore = [
90+
"E501", # Line too long
91+
"E731", # Do not assign a lambda expression, use a def
92+
# Fix these
93+
"F403", # 'from module import *' used; unable to detect undefined names
94+
"F405", # Name may be undefined, or defined from star imports: *
95+
"PLW2901", # loop variable overwritten by assignment target
96+
]
97+
5198
[tool.pytest.ini_options]
52-
addopts = "--pylint"
99+
addopts = "--ruff"

0 commit comments

Comments
 (0)