|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
| 3 | +import sys |
3 | 4 | from pathlib import Path
|
4 | 5 |
|
5 | 6 | import numpy as np
|
6 | 7 | from numpy.typing import ArrayLike
|
7 | 8 |
|
8 |
| -from ._common import num_nodes_per_cell, warn |
| 9 | +from ._common import error, num_nodes_per_cell |
9 | 10 | from ._exceptions import ReadError, WriteError
|
10 | 11 | from ._files import is_buffer
|
11 | 12 | from ._mesh import CellBlock, Mesh
|
|
15 | 16 | _writer_map = {}
|
16 | 17 |
|
17 | 18 |
|
18 |
| -def register_format(format_name: str, extensions: list[str], reader, writer_map): |
| 19 | +def register_format( |
| 20 | + format_name: str, extensions: list[str], reader, writer_map |
| 21 | +) -> None: |
19 | 22 | for ext in extensions:
|
20 | 23 | if ext not in extension_to_filetypes:
|
21 | 24 | extension_to_filetypes[ext] = []
|
22 | 25 | extension_to_filetypes[ext].append(format_name)
|
23 | 26 |
|
24 | 27 | if reader is not None:
|
25 | 28 | reader_map[format_name] = reader
|
| 29 | + |
26 | 30 | _writer_map.update(writer_map)
|
27 | 31 |
|
28 | 32 |
|
@@ -86,19 +90,22 @@ def _read_file(path: Path, file_format: str | None):
|
86 | 90 | raise ReadError(f"File {path} not found.")
|
87 | 91 |
|
88 | 92 | if file_format:
|
89 |
| - file_formats = [file_format] |
| 93 | + possible_file_formats = [file_format] |
90 | 94 | else:
|
91 | 95 | # deduce possible file formats from extension
|
92 |
| - file_formats = _filetypes_from_path(path) |
| 96 | + possible_file_formats = _filetypes_from_path(path) |
93 | 97 |
|
94 |
| - for file_format in file_formats: |
| 98 | + for file_format in possible_file_formats: |
95 | 99 | if file_format not in reader_map:
|
96 | 100 | raise ReadError(f"Unknown file format '{file_format}' of '{path}'.")
|
97 | 101 |
|
98 | 102 | try:
|
99 | 103 | return reader_map[file_format](str(path))
|
100 | 104 | except ReadError:
|
101 |
| - warn(f"Failed to read {path} as {file_format}") |
| 105 | + pass |
| 106 | + |
| 107 | + error(f"Couldn't read file {path} as either of {', '.join(possible_file_formats)}") |
| 108 | + sys.exit(1) |
102 | 109 |
|
103 | 110 |
|
104 | 111 | def write_points_cells(
|
|
0 commit comments