[SCM] Core functionality for performing astronomy and astrophysics with Python branch, debian, updated. ff6b091e542c2ba417803270ae69e83953abc983
Ole Streicher
debian at liska.ath.cx
Tue Apr 30 09:06:02 UTC 2013
The following commit has been merged in the debian branch:
commit ff6b091e542c2ba417803270ae69e83953abc983
Author: Ole Streicher <debian at liska.ath.cx>
Date: Tue Apr 30 11:05:57 2013 +0200
Fix FTBS (unit test failure) on HURD
diff --git a/debian/changelog b/debian/changelog
index 91255d3..abcac4e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+python-astropy (0.2.1-1~exp7) experimental; urgency=low
+
+ * Fix FTBS (unit test failure) on HURD
+
+ -- Ole Streicher <debian at liska.ath.cx> Tue, 30 Apr 2013 10:36:01 +0200
+
python-astropy (0.2.1-1~exp6) experimental; urgency=low
* Fix FTBS (unit test failure) on MIPS
diff --git a/debian/patches/fix_hurd_ftbs.patch b/debian/patches/fix_hurd_ftbs.patch
new file mode 100644
index 0000000..24f783f
--- /dev/null
+++ b/debian/patches/fix_hurd_ftbs.patch
@@ -0,0 +1,179 @@
+Author: "Erik M. Bray" <embray at stsci.edu>
+Date: Mon, 29 Apr 2013 21:47:46 -0400
+Description: Check for mmap and flush()
+ If opening a file in a writeable mode a warning is raised and mmap is
+ disabled even if it was explicitly asked for. This is done through a
+ new check that mmap.flush() is available--this check is performed on all
+ platforms and should require minimal overhead but we'll see... (the
+ check is only performed the first time an attempt is made to open a file
+ in writeable mode)
+--- a/astropy/io/fits/file.py
++++ b/astropy/io/fits/file.py
+@@ -4,6 +4,7 @@
+ from __future__ import with_statement
+
+ import gzip
++import mmap
+ import os
+ import sys
+ import tempfile
+@@ -48,6 +49,9 @@
+ Represents a FITS file on disk (or in some other file-like object).
+ """
+
++ # See self._test_mmap
++ _mmap_available = None
++
+ def __init__(self, fileobj=None, mode='readonly', memmap=False):
+ if fileobj is None:
+ self.__file = None
+@@ -123,8 +127,13 @@
+ self.size = self.__file.tell()
+ self.__file.seek(pos)
+
+- if self.memmap and not isfile(self.__file):
+- self.memmap = False
++ if self.memmap:
++ if not isfile(self.__file):
++ self.memmap = False
++ elif not self.readonly and not self._test_mmap():
++ # Test mmap.flush--see
++ # https://github.com/astropy/astropy/issues/968
++ self.memmap = False
+
+ def __repr__(self):
+ return '<%s.%s %s>' % (self.__module__, self.__class__.__name__,
+@@ -352,3 +361,43 @@
+ self.__file = fileobj_open(self.name, PYTHON_MODES[mode])
+ # Make certain we're back at the beginning of the file
+ self.__file.seek(0)
++
++ def _test_mmap(self):
++ """Tests that mmap, and specifically mmap.flush works. This may
++ be the case on some uncommon platforms (see
++ https://github.com/astropy/astropy/issues/968).
++
++ If mmap.flush is found not to work, ``self.memmap = False`` is
++ se and a warning is issued.
++ """
++
++ if self._mmap_available is not None:
++ return self._mmap_available
++
++ tmpfd, tmpname = tempfile.mkstemp()
++ try:
++ # Windows does not allow mappings on empty files
++ os.write(tmpfd, b' ')
++ os.fsync(tmpfd)
++ try:
++ mm = mmap.mmap(tmpfd, 1, access=mmap.ACCESS_WRITE)
++ except mmap.error as e:
++ warnings.warn('Failed to create mmap: %s; mmap use will be '
++ 'disabled' % str(e))
++ _File._mmap_available = False
++ return False
++ try:
++ mm.flush()
++ except mmap.error:
++ warnings.warn('mmap.flush is unavailable on this platform; '
++ 'using mmap in writeable mode will be disabled')
++ _File._mmap_available = False
++ return False
++ finally:
++ mm.close()
++ finally:
++ os.close(tmpfd)
++ os.remove(tmpname)
++
++ _File._mmap_available = True
++ return True
+--- a/astropy/io/fits/tests/test_core.py
++++ b/astropy/io/fits/tests/test_core.py
+@@ -2,7 +2,9 @@
+
+ import gzip
+ import io
++import mmap
+ import os
++import shutil
+ import warnings
+ import zipfile
+
+@@ -14,6 +16,7 @@
+ from . import FitsTestCase
+ from .util import ignore_warnings
+ from ..convenience import _getext
++from ..file import _File
+
+
+ class TestCore(FitsTestCase):
+@@ -473,6 +476,41 @@
+
+ assert old_mode == os.stat(filename).st_mode
+
++ def test_mmap_unwriteable(self):
++ """Regression test for https://github.com/astropy/astropy/issues/968
++
++ Temporarily patches mmap.mmap to exhibit platform-specific bad
++ behavior.
++ """
++
++ class MockMmap(mmap.mmap):
++ def flush(self):
++ raise mmap.error('flush is broken on this platform')
++
++ old_mmap = mmap.mmap
++ mmap.mmap = MockMmap
++
++ # Force the mmap test to be rerun
++ _File._mmap_available = None
++
++ try:
++ # TODO: Use self.copy_file once it's merged into Astropy
++ shutil.copy(self.data('test0.fits'), self.temp('test0.fits'))
++ with warnings.catch_warnings(record=True) as w:
++ with fits.open(self.temp('test0.fits'), mode='update',
++ memmap=True) as h:
++ h[1].data[0, 0] = 999
++
++ assert len(w) == 1
++ assert 'mmap.flush is unavailable' in str(w[0].message)
++
++ # Double check that writing without mmap still worked
++ with fits.open(self.temp('test0.fits')) as h:
++ assert h[1].data[0, 0] == 999
++ finally:
++ mmap.mmap = old_mmap
++ _File._mmap_available = None
++
+ def _make_gzip_file(self, filename='test0.fits.gz'):
+ gzfile = self.temp(filename)
+ with open(self.data('test0.fits'), 'rb') as f:
+--- a/CHANGES.rst
++++ b/CHANGES.rst
+@@ -40,6 +40,9 @@
+ - Fixed a bug in fitsdiff that reported two header keywords contaning NaN
+ as having different values.
+
++ - Fixed an obscure issue that can occur on systems that don't have flush to
++ memory-mapped files implemented (namely GNU Hurd). [#968]
++
+ - ``astropy.io.votable``
+
+ - Fixed links to the ``astropy.io.votable`` documentation in the VOTable
+--- a/docs/known_issues.rst
++++ b/docs/known_issues.rst
+@@ -66,3 +66,13 @@
+ fail.
+
+ The solution is to use a more recent version of Numpy.
++
++mmap support on GNU Hurd
++------------------------
++
++On Hurd and possibly other platforms ``flush()`` on memory-mapped files is not
++implemented, so writing changes to a mmap'd file may not be reliable and is
++this disabled. Attempting to open a file in writeable mode with mmap will
++result in a warning (and mmap will be disabled on the file automatically).
++
++See: https://github.com/astropy/astropy/issues/968
diff --git a/debian/patches/series b/debian/patches/series
index 0e3c2c5..cce875f 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,3 +1,3 @@
fix_bigendian_ftbs.patch
-
fix_mips_ftbs.patch
+fix_hurd_ftbs.patch
--
Core functionality for performing astronomy and astrophysics with Python
More information about the debian-science-commits
mailing list