Commit Graph

9059 Commits

Author SHA1 Message Date
Jon Dufresne
4cd4adddc3 Improve handling of file resources
Follow Python's file object semantics. User code is responsible for
closing resources (usually through a context manager) in a deterministic
way.

To achieve this, remove __del__ functions. These functions used to
closed open file handlers in an attempt to silence Python
ResourceWarnings. However, using __del__ has the following drawbacks:

- __del__ isn't called until the object's reference count reaches 0.
  Therefore, resource handlers remain open or in use longer than
  necessary.

- The __del__ method isn't guaranteed to execute on system exit. See the
  Python documentation:

  https://docs.python.org/3/reference/datamodel.html#object.__del__

  > It is not guaranteed that __del__() methods are called for objects
  > that still exist when the interpreter exits.

- Exceptions that occur inside __del__ are ignored instead of raised.
  This has the potential of hiding bugs. This is also in the Python
  documentation:

  > Warning: Due to the precarious circumstances under which __del__()
  > methods are invoked, exceptions that occur during their execution
  > are ignored, and a warning is printed to sys.stderr instead.

Instead, always close resource handlers when they are no longer in use.
This will close the file handler at a specified point in the user's code
and not wait until the interpreter chooses to. It is always guaranteed
to run. And, if an exception occurs while closing the file handler, the
bug will not be ignored.

Now, when code receives a ResourceWarning, it will highlight an area
that is mishandling resources. It should not simply be silenced, but
fixed by closing resources with a context manager.

All warnings that were emitted during tests have been cleaned up. To
enable warnings, I passed the `-Wa` CLI option to Python. This exposed
some mishandling of resources in ImageFile.__init__() and
SpiderImagePlugin.loadImageSeries(), they too were fixed.
2019-10-12 08:27:17 -07:00
Hugo van Kemenade
6595ce1609
Merge pull request #4081 from hugovk/test-with-github-actions
Test Linux and macOS with GitHub Actions
2019-10-12 13:07:28 +03:00
Hugo
a4d7861e34 Turn fail-fast off, so one failed job doesn't cancel others 2019-10-12 12:14:49 +03:00
Hugo
707c9910ab Install OS dependencies without checking version number 2019-10-12 10:49:26 +03:00
Hugo
cf8f8b1743 Drop support for EOL Python 2.7 2019-10-12 10:49:26 +03:00
Hugo
01373b4ed9 Add Codecov token to config 2019-10-12 10:49:26 +03:00
Hugo
ac5642dc76 Split script.sh into build.sh and test.sh 2019-10-12 10:49:26 +03:00
Hugo
7c7c53fbb6 Test macOS with GitHub Actions 2019-10-12 10:49:26 +03:00
Hugo
e595ddbaa1 Test with GitHub Actions 2019-10-12 10:49:26 +03:00
Andrew Murray
078a767b77
Merge pull request #4133 from hugovk/dont-test-2.7
CI: Stop testing Python 2.7
2019-10-12 17:56:32 +11:00
Hugo van Kemenade
23c3891b81
Merge pull request #4084 from nulano/gha-win
Test Windows with GitHub Actions
2019-10-11 22:16:45 +03:00
Hugo van Kemenade
f0c08ad565
Merge branch 'master' into gha-win 2019-10-11 19:24:48 +03:00
Hugo
faa1d1f326 Stop testing Python 2.7 2019-10-11 19:05:20 +03:00
Hugo van Kemenade
7fad924ac0
Merge pull request #4132 from radarhere/orientation
Added orientation note
2019-10-11 18:42:13 +03:00
Hugo van Kemenade
8225642745
Merge pull request #4131 from radarhere/badges
Added GitHub Actions badges
2019-10-11 18:41:05 +03:00
Andrew Murray
a8c07e3d5f Added orientation note [ci skip] 2019-10-11 22:40:31 +11:00
Andrew Murray
f2abab474d Added GitHub Actions badges [ci skip] 2019-10-11 22:04:21 +11:00
Hugo van Kemenade
8c94f01842
Merge pull request #4126 from radarhere/python38
Added Python 3.8 rc1 to AppVeyor
2019-10-09 23:50:23 +03:00
Andrew Murray
1c493fb4fa Added Python 3.8 rc1 2019-10-10 06:31:18 +11:00
Andrew Murray
7e980d7613
Merge pull request #4066 from hugovk/test-docker-with-github-actions
Test Docker with GitHub Actions
2019-10-09 21:16:42 +11:00
nulano
a0a5601689
Merge branch 'master' into gha-win 2019-10-08 12:56:43 +01:00
Hugo van Kemenade
4c172ae266
Updated ImageOps documentation (#4125)
Updated ImageOps documentation
2019-10-08 13:44:40 +03:00
Andrew Murray
fab0205abc Updated documentation [ci skip] 2019-10-08 21:12:15 +11:00
Hugo
fc4dbf8484 Test Docker with GitHub Actions 2019-10-08 11:26:08 +03:00
Hugo van Kemenade
a59c1b7cea
Merge pull request #4122 from jdufresne/imports
Move several imports to the top-level of the file
2019-10-08 10:13:39 +03:00
Jon Dufresne
64032061c0 Move several imports to the top-level of the file
This better follows PEP 8 style guide:

https://www.python.org/dev/peps/pep-0008/#imports

> Imports are always put at the top of the file, just after any module
> comments and docstrings, and before module globals and constants.

This also avoids duplicate import code within the same file.
2019-10-07 06:28:36 -07:00
Hugo van Kemenade
127b322194
Test Qt5 (#4120)
Test Qt5
2019-10-07 14:27:48 +03:00
Hugo van Kemenade
fe855ab999
Merge pull request #4121 from jdufresne/bytes
Use bytes literals instead of bytes(str)
2019-10-07 08:38:39 +03:00
Jon Dufresne
922f55c265 Use bytes literals instead of bytes(str)
Bytes literals are available on all supported Python versions. Rather
than convert strings literals to bytes at runtime, simply use a bytes
literal.
2019-10-06 19:26:55 -07:00
Andrew Murray
bbfa8bc1ca Updated CHANGES.rst [ci skip] 2019-10-07 13:07:36 +11:00
Andrew Murray
c3822de70d Test Qt5 2019-10-07 12:41:33 +11:00
Andrew Murray
e8cf9a6bc1
Merge pull request #4108 from hugovk/rm-deprecated-qt
Drop support for EOL PyQt4 and PySide
2019-10-07 12:35:56 +11:00
Hugo van Kemenade
bb4656928c
Remove duplicate cleanup in test_decompression_bomb.py (#4119)
Remove duplicate cleanup in test_decompression_bomb.py
2019-10-06 22:16:35 +03:00
Jon Dufresne
c50a309a10 Remove duplicate cleanup in test_decompression_bomb.py
The same cleanup is done in the teardDown() method. There is no need to
do it a 2nd time.
2019-10-06 10:24:48 -07:00
Hugo van Kemenade
ac563f77ad
Merge pull request #4118 from radarhere/backticks
Use double backticks
2019-10-06 12:03:49 +03:00
Hugo van Kemenade
068fd7b6f4
Merge pull request #4117 from radarhere/formats
Clarified image format documentation
2019-10-06 09:02:52 +03:00
Hugo van Kemenade
3ec2fbd572
Merge pull request #37 from radarhere/rm-deprecated-qt
Do not install qt4
2019-10-06 08:57:00 +03:00
Andrew Murray
6fe2df01cd Do not install qt4 2019-10-06 15:38:56 +11:00
Andrew Murray
e0d67a1f9f Use double backticks [ci skip] 2019-10-06 14:39:10 +11:00
Andrew Murray
ecb3a30487 Clarified documentation [ci skip] 2019-10-06 13:52:58 +11:00
Andrew Murray
732eb7223f
Merge branch 'master' into rm-deprecated-qt 2019-10-06 13:35:38 +11:00
Andrew Murray
6a83d5b239
Merge pull request #4114 from radarhere/tiff_size
Removed deprecated setting of TIFF image sizes
2019-10-05 02:33:08 +10:00
Hugo van Kemenade
0a8f029971
Merge pull request #4113 from radarhere/version
Removed outdated VERSION comment
2019-10-03 22:56:12 +03:00
Hugo van Kemenade
d479572158
Changed condition to use DEBUG as a boolean (#4112)
Changed condition to use DEBUG as a boolean
2019-10-03 15:38:46 +03:00
Andrew Murray
d6ae0a99a7 Removed deprecated setting of TIFF image sizes 2019-10-03 22:12:28 +10:00
Hugo van Kemenade
7821b34924
Merge branch 'master' into rm-deprecated-qt 2019-10-03 14:14:00 +03:00
Andrew Murray
3cd7d9e4a2 Removed outdated VERSION comment 2019-10-03 20:54:55 +10:00
Andrew Murray
6238f07d8c Updated CHANGES.rst [ci skip] 2019-10-03 20:53:54 +10:00
Andrew Murray
f61af2fed0
Merge pull request #4107 from hugovk/rm-deprecated-PILLOW_VERSION
Remove deprecated PILLOW_VERSION
2019-10-03 20:52:48 +10:00
Andrew Murray
1e6eac40fc Changed condition to use DEBUG as a boolean 2019-10-03 20:23:49 +10:00