Skip to content

Commit

Permalink
Merge branch 'main' into patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
stewartboogert authored Jan 13, 2025
2 parents d9c876b + 7365abc commit 75a6af6
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 33 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ repos:
args: ["--line-length", "100"]

- repo: https://github.com/asottile/blacken-docs
rev: "1.18.0"
rev: "1.19.1"
hooks:
- id: blacken-docs
additional_dependencies: [black==23.3.0]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.6.9"
rev: "v0.8.6"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]

- repo: https://github.com/mgedmin/check-manifest
rev: "0.49"
rev: "0.50"
hooks:
- id: check-manifest
stages: [manual]
Expand Down Expand Up @@ -76,7 +76,7 @@ repos:
types_or: [yaml, markdown, html, css, scss, javascript, json]

- repo: https://github.com/kynan/nbstripout
rev: "0.7.1"
rev: "0.8.1"
hooks:
- id: nbstripout
args:
Expand All @@ -87,7 +87,7 @@ repos:
]

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: "v19.1.1"
rev: "v19.1.6"
hooks:
- id: clang-format
types_or: [c++, c, cuda]
6 changes: 3 additions & 3 deletions src/pyg4ometry/analysis/flukaData.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,14 @@ def read_stats(self, fd):
for det in self.detector:
data = fortran_read(fd)

data = _struct.unpack("=%df" % (len(data) // 4), data)
data = _struct.unpack(f"={len(data) // 4}f", data)
det.total = data[0]
det.totalError = data[1]

det.error = []
for i in range(6):
data = fortran_read(fd)
det.error.append(_struct.unpack("=%df" % (len(data) // 4), data))
det.error.append(_struct.unpack(f"={len(data) // 4}f", data))

def read_header(self, fd):
pos = fd.tell()
Expand Down Expand Up @@ -424,7 +424,7 @@ def read_event(self, fd, ievent=0):
etrack = edum
wtrack = wdum
data = fortran_read(fd)
data = list(_struct.unpack("=%df" % (3 * (ntrack + 1) + mtrack + 1), data))
data = list(_struct.unpack(f"={3 * (ntrack + 1) + mtrack + 1}f", data))
self.track_data.append(data)
# energy
elif ndum == 0:
Expand Down
22 changes: 11 additions & 11 deletions src/pyg4ometry/fluka/body.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
"""Set of classes for FLUKA bodies."""

__all__ = [
"RPP",
"ARB",
"BOX",
"SPH",
"ELL",
"PLA",
"QUA",
"RAW",
"RCC",
"REC",
"RPP",
"SPH",
"TRC",
"ELL",
"WED",
"RAW",
"ARB",
"XCC",
"XEC",
"XYP",
"XZP",
"YZP",
"PLA",
"XCC",
"YCC",
"ZCC",
"XEC",
"YEC",
"YZP",
"ZCC",
"ZEC",
"QUA",
]

from math import degrees
Expand Down
11 changes: 5 additions & 6 deletions src/pyg4ometry/freecad/Reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,7 @@ def recurseObjectTree(self, obj):

if obj.TypeId == "App::Part": # mapped to logical volume, group objects mapped to physical
_log.info(
"freecad.reader.recurseObjectTree> App::Part label=%s grouplen=%d placement=%s"
% (obj.Label, len(obj.Group), obj.Placement)
f"freecad.reader.recurseObjectTree> App::Part label={obj.Label} grouplen={len(obj.Group)} placement={obj.Placement}"
)

bSolid = pyg4ometry.geant4.solid.Box(
Expand Down Expand Up @@ -515,18 +514,18 @@ def WriteSMeshFile(mesh, filename):
wind = mesh[1]

f.write("# part 1 - node list\n")
f.write("%i 3 0 0 \n" % (len(verts)))
f.write(f"{len(verts)} 3 0 0 \n")
iv = 0
for v in verts:
f.write("%i %f %f %f\n" % (iv, v[0], v[1], v[2]))
f.write(f"{iv} {v[0]} {v[1]} {v[2]}\n")
iv = iv + 1

f.write("# part 2 - facet list\n")
f.write("%i 0\n" % (len(wind)))
f.write(f"{len(wind)} 0\n")

iw = 0
for w in wind:
f.write("3 %i %i %i\n" % (w[0], w[1], w[2]))
f.write(f"3 {w[0]} {w[1]} {w[2]}\n")

f.write("# part 3 - hole list\n")
f.write("0\n")
Expand Down
6 changes: 2 additions & 4 deletions src/pyg4ometry/geant4/LogicalVolume.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,7 @@ def checkOverlaps(
# bounding meshes collide, so check full mesh properly
interMesh = transformedMeshes[i].intersect(transformedMeshes[j])
_log.info(
"LogicalVolume.checkOverlaps> full daughter-daughter intersection test: %d %d %d %d"
% (i, j, interMesh.vertexCount(), interMesh.polygonCount())
f"LogicalVolume.checkOverlaps> full daughter-daughter intersection test: {i} {j} {interMesh.vertexCount()} {interMesh.polygonCount()}"
)
if interMesh.vertexCount() != 0:
nOverlapsDetected[0] += 1
Expand Down Expand Up @@ -785,8 +784,7 @@ def checkOverlaps(

interMesh = transformedMeshes[i].subtract(self.mesh.localmesh)
_log.info(
"LogicalVolume.checkOverlaps> daughter container %d %d %d"
% (i, interMesh.vertexCount(), interMesh.polygonCount())
f"LogicalVolume.checkOverlaps> daughter container {i} {interMesh.vertexCount()} {interMesh.polygonCount()}"
)

if interMesh.vertexCount() != 0:
Expand Down
6 changes: 2 additions & 4 deletions src/pyg4ometry/geant4/ReplicaVolume.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ def _checkInternalOverlaps(self, debugIO=False, nOverlapsDetected=[0]):

interMesh = tempMeshes[i].subtract(self.motherVolume.mesh.localboundingmesh)
_log.info(
"ReplicaVolume.checkOverlaps> daughter container %d %d %d"
% (i, interMesh.vertexCount(), interMesh.polygonCount())
f"ReplicaVolume.checkOverlaps> daughter container {i} {interMesh.vertexCount()} {interMesh.polygonCount()}"
)

if interMesh.vertexCount() != 0:
Expand All @@ -123,8 +122,7 @@ def _checkInternalOverlaps(self, debugIO=False, nOverlapsDetected=[0]):
# bounding meshes collide, so check full mesh properly
interMesh = tempMeshes[i].intersect(tempMeshes[j])
_log.info(
"ReplicaVolume.checkOverlaps> full daughter-daughter intersection test: %d %d %d %d"
% (i, j, interMesh.vertexCount(), interMesh.polygonCount())
f"ReplicaVolume.checkOverlaps> full daughter-daughter intersection test: {i} {j} {interMesh.vertexCount()} {interMesh.polygonCount()}"
)
if interMesh.vertexCount() != 0:
nOverlapsDetected[0] += 1
Expand Down
2 changes: 2 additions & 0 deletions tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from optparse import OptParseError
import os
import pytest
import sys

_skip_root_tests = False
try:
Expand Down Expand Up @@ -195,6 +196,7 @@ def test_cli_load_stl(testdata):
_cli.main(["-i", testdata["stl/dog.stl"]], testing=True)


@pytest.mark.skipif(sys.platform == "linux", reason="Test not supported on Linux")
def test_cli_load_stp(testdata):
_cli.main(["-i", testdata["step/1_BasicSolids_Bodies.step"]], testing=True)

Expand Down
18 changes: 18 additions & 0 deletions tests/pyoce/test_pyoce.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys
import pytest
import pyg4ometry as _pyg4


Expand All @@ -19,61 +21,75 @@ def commonCode(fileName, mats={}, skip=[], mesh={}):
return r


@pytest.mark.skipif(sys.platform == "linux", reason="Test not supported on Linux")
def test_1_BasicSolids_Bodies(testdata):
commonCode(testdata["step/1_BasicSolids_Bodies.step"])


@pytest.mark.skipif(sys.platform == "linux", reason="Test not supported on Linux")
def test_2_BasicSolids_Components(testdata):
commonCode(testdata["step/2_BasicSolids_Components.step"])


@pytest.mark.skipif(sys.platform == "linux", reason="Test not supported on Linux")
def test_3_BasicSolids_Components_Copied(testdata):
commonCode(testdata["step/3_BasicSolids_Components_Copied.step"])


@pytest.mark.skipif(sys.platform == "linux", reason="Test not supported on Linux")
def test_4_BasicSolids_Components_ManyBodies(testdata):
commonCode(testdata["step/4_BasicSolids_Components_ManyBodies.step"])


@pytest.mark.skipif(sys.platform == "linux", reason="Test not supported on Linux")
def test_5_BasicSolids_Components_NestedComponents(testdata):
commonCode(testdata["step/5_BasicSolids_Components_NestedComponents.step"])


@pytest.mark.skipif(sys.platform == "linux", reason="Test not supported on Linux")
def test_6_SolidFromSketch(testdata):
commonCode(testdata["step/6_SolidFromSketch.step"])


@pytest.mark.skipif(sys.platform == "linux", reason="Test not supported on Linux")
def test_7_Booleans(testdata):
commonCode(testdata["step/7_Booleans.step"])


@pytest.mark.skipif(sys.platform == "linux", reason="Test not supported on Linux")
def test_8_rotationTest(testdata):
commonCode(testdata["step/8_rotationTest.step"])


@pytest.mark.skipif(sys.platform == "linux", reason="Test not supported on Linux")
def test_9_AshTray(testdata):
commonCode(testdata["step/9_AshTray.step"])


@pytest.mark.skipif(sys.platform == "linux", reason="Test not supported on Linux")
def test_10_SectorBendSmall(testdata):
commonCode(testdata["step/10_SectorBendSmall.step"])


@pytest.mark.skipif(sys.platform == "linux", reason="Test not supported on Linux")
def test_11_Material(testdata):
mats = {"0:1:1:1:1": "G4_H", "0:1:1:1:4": "G4_He"}
commonCode(testdata["step/10_SectorBendSmall.step"], mats=mats)


@pytest.mark.skipif(sys.platform == "linux", reason="Test not supported on Linux")
def test_12_Skip(testdata):
skip = ["0:1:1:1:4"]
commonCode(testdata["step/10_SectorBendSmall.step"], skip=skip)


@pytest.mark.skipif(sys.platform == "linux", reason="Test not supported on Linux")
def test_13_Mesh(testdata):
mesh = {"0:1:1:1:2": (0.05, 0.05)}
commonCode(testdata["step/10_SectorBendSmall.step"], mesh=mesh)


@pytest.mark.skipif(sys.platform == "linux", reason="Test not supported on Linux")
def test_14_MonolithicConversion(testdata):
r = _pyg4.pyoce.Reader(str(testdata["step/1_BasicSolids_Bodies.step"]))
ls = r.freeShapes()
Expand All @@ -83,6 +99,7 @@ def test_14_MonolithicConversion(testdata):
_pyg4.convert.oceShape_Geant4_Tessellated("world", worldShape, greg)


@pytest.mark.skipif(sys.platform == "linux", reason="Test not supported on Linux")
def test_15_xcaf(testdata):
# create application
app = _pyg4.pyoce.XCAFApp.XCAFApp_Application.GetApplication()
Expand All @@ -105,6 +122,7 @@ def test_15_xcaf(testdata):
# w.WriteFile("output.step")


@pytest.mark.skipif(sys.platform == "linux", reason="Test not supported on Linux")
def test_16_CurveAndSurface_Extraction(testdata):
from pyg4ometry.pyoce.TopAbs import TopAbs_ShapeEnum
from pyg4ometry.pyoce.TopExp import TopExp_Explorer
Expand Down

0 comments on commit 75a6af6

Please sign in to comment.