diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 527401d..10643e6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c1d67bd..c85db9e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 } @@ -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 } diff --git a/kw6/reader.py b/kw6/reader.py index 1146122..f548095 100644 --- a/kw6/reader.py +++ b/kw6/reader.py @@ -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. @@ -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) @@ -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. @@ -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]: