openpreserve / jpylyzer

JP2 (JPEG 2000 Part 1) validator and properties extractor. Jpylyzer was specifically created to check that a JP2 file really conforms to the format's specifications. Additionally jpylyzer is able to extract technical characteristics.
http://jpylyzer.openpreservation.org/
Other
69 stars 28 forks source link

Detection of the lack of libraries (mmap and six) in Jython #154

Closed tledoux closed 4 years ago

tledoux commented 4 years ago

In order to use jpylyzer in Java using Jython, the use of the mmap library should be avoid. Indeed the mmap is not supported by Jython (see https://bugs.jython.org/issue1854873).

To simplify the detection for the lack of libraries in Jython, the ImportError exception is catch and a flag is set. When the mmap library is not available, files are directly read in memory (method used before the 1.14 version of jylyzer).

An example java program is provided to test.

Takes also care of the six library which doesn't work with Jython Correct some E302 pep8 warnings

tledoux commented 4 years ago

@bitsgalore, codacy complains about the import not at the top level but this is the whole point of the PR !!!

bitsgalore commented 4 years ago

Hi @tledoux, thanks for this pull request, this looks like a useful feature. If I remember correctly @anjackson suggested something similar several years ago, and I think there was even a pull request at some point, but from what I recall we never got round to including this for several reasons (this was a long time ago and I don't remember the specifics).

Anyway, as we're currently right in the middle of applying the final finishing touches to the 2.0.0 release (which is due later today!) I'm not merging this right away, but I'll have a look at this later, and then try to include it in the next (2.1.0) release.

tledoux commented 4 years ago

hi @bitsgalore, in order to make codacy and travis happy, I discover that imports can be surrounded by try except which automates the detection of the lack of libraries. The extra argument --nowrap is then not needed anymore in order to take care of that.

So now the PR is much more simple, it just addresses the problem of integrating jpylyzer with jython (issue I just discovered when trying to integrate the release candidate in our current workflow).

Feel free to grap it when appropriate.

PS : the proposal by @anjackson was different since he asks for a method to provide directly the bytes buffer since he already reads it in memory. I'm not sure this is a good idea in my case : reading the file in Java to pass it to python will just add one more layer of complexity, better just exchange strings.