Skip to content

Commit

Permalink
Merge pull request #137 from pauldmccarthy/mnt/filenotfound
Browse files Browse the repository at this point in the history
MNT: Raise FileNotFoundError on non-existent path
  • Loading branch information
pauldmccarthy authored Aug 29, 2023
2 parents 43b53cd + 52f6794 commit bc878bb
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 11 deletions.
6 changes: 4 additions & 2 deletions .ci/download_zlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
#
set -e

curl -o zlib.tar.gz https://www.zlib.net/zlib-1.2.13.tar.gz
ZLIB_VERSION=1.3

curl -o zlib.tar.gz https://www.zlib.net/zlib-${ZLIB_VERSION}.tar.gz

tar -xzf zlib.tar.gz

ZLIB_HOME=$(pwd)/zlib-1.2.13
ZLIB_HOME=$(pwd)/zlib-${ZLIB_VERSION}

# if windows, turn /drive/path/to/zlib into
# drive:/path/to/zlib.
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/master.yaml → .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# This workflow runs the full set of of indexed_gzip
# unit tests on a range of different versions of Python,
# and on different operating systems and architectures.
# It is run on pushes to the master branch.
# It is run on pushes to the main branch.


on:
push:
branches:
- master
- main


defaults:
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# `indexed_gzip` changelog


## 1.8.4 (August 30th 2023)


* Change the `IndexedGzipFile` class to raise a `FileNotFoundError` instead
of a `ValueError`, when a path to a non-existent file is provided (#137).


## 1.8.3 (July 25th 2023)


* Another adjustment to package build process (#135).



## 1.8.2 (July 25th 2023)


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# indexed_gzip


[![PyPi version](https://img.shields.io/pypi/v/indexed_gzip.svg)](https://pypi.python.org/pypi/indexed_gzip/) [![Anaconda version](https://anaconda.org/conda-forge/indexed_gzip/badges/version.svg)](https://anaconda.org/conda-forge/indexed_gzip/)![Test status](https://github.com/pauldmccarthy/indexed_gzip/actions/workflows/master.yaml/badge.svg)
[![PyPi version](https://img.shields.io/pypi/v/indexed_gzip.svg)](https://pypi.python.org/pypi/indexed_gzip/) [![Anaconda version](https://anaconda.org/conda-forge/indexed_gzip/badges/version.svg)](https://anaconda.org/conda-forge/indexed_gzip/)![Test status](https://github.com/pauldmccarthy/indexed_gzip/actions/workflows/main.yaml/badge.svg)


*Fast random access of gzip files in Python*
Expand Down
2 changes: 1 addition & 1 deletion indexed_gzip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
"""


__version__ = '1.8.3'
__version__ = '1.8.4'
11 changes: 7 additions & 4 deletions indexed_gzip/indexed_gzip.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ cdef class _IndexedGzipFile:
# a segmentation fault on linux. So
# let's check before that happens.
if (filename is not None) and (not op.isfile(filename)):
raise ValueError('File {} does not exist'.format(filename))
raise DoesNotExistError('File {} does not exist'.format(filename))

mode = 'rb'
own_file = fileobj is None
Expand Down Expand Up @@ -1119,22 +1119,19 @@ class NotCoveredError(ValueError):
this error will only occur on attempts to call the ``seek`` method
with ``whence=SEEK_END``, where the index has not been completely built.
"""
pass


class ZranError(IOError):
"""Exception raised by the :class:`_IndexedGzipFile` when the ``zran``
library signals an error.
"""
pass


class CrcError(OSError):
"""Exception raised by the :class:`_IndexedGzipFile` when a CRC/size
validation check fails, which suggests that the GZIP data might be
corrupt.
"""
pass


class NoHandleError(ValueError):
Expand All @@ -1144,6 +1141,12 @@ class NoHandleError(ValueError):
"""


class DoesNotExistError(ValueError, FileNotFoundError):
"""Exception raised by the :class:`_IndexedGzipFile` when it is passed
a path to a file that does not exist.
"""


class ZRAN_ERRORS(object):
"""Contains text versions of all error codes emitted by zran.c. """
ZRAN_BUILD = {
Expand Down
5 changes: 5 additions & 0 deletions indexed_gzip/tests/ctest_indexed_gzip.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ def test_init_failure_cases(concat, drop):
with pytest.raises(ValueError):
f = igzip._IndexedGzipFile(drop_handles=drop)

# Doesn't exist
with pytest.raises(FileNotFoundError):
f = igzip._IndexedGzipFile(filename='no_file.gz',
drop_handles=drop)

# can only specify one of filename/fid
with pytest.raises(ValueError):
with open(testfile, mode='rb'):
Expand Down

0 comments on commit bc878bb

Please sign in to comment.