Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install dependencies
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ jobs:
python-version: [3.8]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Cache pip
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('poetry.lock') }}-${ GITHUB_REF }
Expand Down Expand Up @@ -45,14 +45,14 @@ jobs:
python-version: [3.8]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Cache pip
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('docs/source/requirements.txt') }}-${ GITHUB_REF }
Expand Down
17 changes: 12 additions & 5 deletions kw6/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ class Config:
arbitrary_types_allowed = True

@staticmethod
def from_file_like(file: Any, header_file: Optional[Any] = None) -> "Reader":
def from_file_like(
file: Any,
header_file: Optional[Any] = None,
raise_on_version_mismatch: bool = True,
) -> "Reader":
"""
Create a Reader instance from a file-like object.

Expand All @@ -56,7 +60,7 @@ def from_file_like(file: Any, header_file: Optional[Any] = None) -> "Reader":
ValueError: If the file version is unexpected.
"""
version = file.read(settings.N_BYTES_VERSION).decode().strip()
if version != "KW6FileClassVer1.0":
if version != "KW6FileClassVer1.0" and raise_on_version_mismatch:
raise ValueError(f"Unexpected file version {version}")

initial_position_header = PositionHeader.from_stream_(file)
Expand All @@ -81,7 +85,9 @@ def from_file_like(file: Any, header_file: Optional[Any] = None) -> "Reader":

@staticmethod
def from_path(
path: Union[str, Path], header_path: Optional[Union[str, Path]] = None
path: Union[str, Path],
header_path: Optional[Union[str, Path]] = None,
raise_on_version_mismatch: bool = True,
) -> "Reader":
"""
Create a Reader instance from a file path.
Expand All @@ -97,8 +103,9 @@ def from_path(
header_path = Path(header_path) if isinstance(header_path, str) else header_path

return Reader.from_file_like(
path.open("rb"),
None if header_path is None else header_path.open("rb"),
file=path.open("rb"),
header_file=None if header_path is None else header_path.open("rb"),
raise_on_version_mismatch=raise_on_version_mismatch,
)

def __iter__(self) -> Iterable[Position]:
Expand Down