Skip to content

Commit

Permalink
Merge branch 'release/24.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
felliott committed Jan 3, 2024
2 parents b61d621 + d2f64bc commit 878881d
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
ChangeLog
*********

24.0.0 (2024-01-02)
===================
- Fix: Install ca-certificates-java in Dockerfile to fix image build.
- Fix: Support newer manifest locations for jamovi files (PR#369). (thanks, @jonathon-love!)
- Fix: Support new manifest type and location for JASP-stats files. (thanks, @JorisGoosen and
@RensDofferhoff!)

23.1.0 (2023-04-17)
===================
- Fix: Improve support for special characters in tabular renderer sheet names. (thanks, @aaxelb!)
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ RUN usermod -d /home www-data \
# -slim images strip man dirs, but java won't install unless this dir exists.
&& mkdir -p /usr/share/man/man1 \
&& apt-get update \
# HACK: work around bug in install java (dep of libreoffice)
&& apt-get install -y ca-certificates-java \
# mfr dependencies
&& apt-get install -y \
git \
Expand Down
14 changes: 10 additions & 4 deletions mfr/extensions/jamovi/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,20 @@ def _check_file(self, zip_file):
"""
# Extract manifest file content
try:
with zip_file.open('META-INF/MANIFEST.MF') as manifest_data:
manifest = manifest_data.read().decode('utf-8')
try:
# new manifest location
with zip_file.open('meta') as manifest_data:
manifest = manifest_data.read().decode('utf-8')
except KeyError:
# old manifest location
with zip_file.open('META-INF/MANIFEST.MF') as manifest_data:
manifest = manifest_data.read().decode('utf-8')
except KeyError:
raise jamovi_exceptions.JamoviFileCorruptError(
'{} Missing META-INF/MANIFEST.MF'.format(self.MESSAGE_FILE_CORRUPT),
'{} Missing manifest'.format(self.MESSAGE_FILE_CORRUPT),
extension=self.metadata.ext,
corruption_type='key_error',
reason='zip missing ./META-INF/MANIFEST.MF',
reason='zip missing manifest',
)

lines = manifest.split('\n')
Expand Down
62 changes: 57 additions & 5 deletions mfr/extensions/jasp/render.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os

from mako.lookup import TemplateLookup
Expand Down Expand Up @@ -67,16 +68,30 @@ def _check_file(self, zip_file):
"""
# Extract manifest file content
try:
with zip_file.open('META-INF/MANIFEST.MF') as manifest_data:
manifest = manifest_data.read().decode('utf-8')
try:
# new manifest location
with zip_file.open('manifest.json') as manifest_data:
manifest, flavor = manifest_data.read().decode('utf-8'), 'json'
except KeyError:
# old manifest location
with zip_file.open('META-INF/MANIFEST.MF') as manifest_data:
manifest, flavor = manifest_data.read().decode('utf-8'), 'java'
except KeyError:
raise exceptions.JaspFileCorruptError(
'{} Missing META-INF/MANIFEST.MF'.format(self.MESSAGE_FILE_CORRUPT),
'{} Missing manifest'.format(self.MESSAGE_FILE_CORRUPT),
extension=self.metadata.ext,
corruption_type='key_error',
reason='zip missing ./META-INF/MANIFEST.MF',
reason='zip missing manifest',
)

if flavor == 'java':
self._verify_java_manifest(manifest)
else:
self._verify_json_manifest(manifest)

return True

def _verify_java_manifest(self, manifest):
lines = manifest.split('\n')

# Search for Data-Archive-Version
Expand Down Expand Up @@ -121,4 +136,41 @@ def _check_file(self, zip_file):
reason='Data-Archive-Version ({}) not parsable.'.format(dataArchiveVersionStr),
)

return True
return

def _verify_json_manifest(self, manifest):

manifest_data = json.loads(manifest)

jasp_archive_version_str = manifest_data.get('jaspArchiveVersion', None)
if not jasp_archive_version_str:
raise exceptions.JaspFileCorruptError(
'{} jaspArchiveVersion not found.'.format(self.MESSAGE_FILE_CORRUPT),
extension=self.metadata.ext,
corruption_type='manifest_parse_error',
reason='jaspArchiveVersion not found.',
)

# Check that the file is new enough (contains preview content)
jasp_archive_version = LooseVersion(jasp_archive_version_str)
try:
if jasp_archive_version < self.MINIMUM_VERSION:
minimum_version = self.MINIMUM_VERSION.vstring
data_archive_version = jasp_archive_version.vstring
raise exceptions.JaspVersionError(
'This JASP file was created with an older data archive '
'version ({}) and cannot be previewed. Minimum data archive '
'version is {}.'.format(data_archive_version, minimum_version),
extension=self.metadata.ext,
actual_version=data_archive_version,
required_version=minimum_version,
)
except TypeError:
raise exceptions.JaspFileCorruptError(
'{} jaspArchiveVersion not parsable.'.format(self.MESSAGE_FILE_CORRUPT),
extension=self.metadata.ext,
corruption_type='manifest_parse_error',
reason='jaspArchiveVersion ({}) not parsable.'.format(jasp_archive_version_str),
)

return
2 changes: 1 addition & 1 deletion mfr/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '23.1.0'
__version__ = '24.0.0'
Binary file not shown.
File renamed without changes.
17 changes: 13 additions & 4 deletions tests/extensions/jamovi/test_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ def metadata():
'http://wb.osf.io/file/jamovi.omv?token=1337')

@pytest.fixture
def ok_path():
return os.path.join(BASE_PATH, 'ok.omv')
def ok_new_manifest_path():
return os.path.join(BASE_PATH, 'ok-new-manifest.omv')

@pytest.fixture
def ok_old_manifest_path():
return os.path.join(BASE_PATH, 'ok-old-manifest.omv')

@pytest.fixture
def ok_with_image_path():
Expand Down Expand Up @@ -63,8 +67,8 @@ def extension():
return '.omv'

@pytest.fixture
def renderer(metadata, ok_path, url, assets_url, export_url):
return JamoviRenderer(metadata, ok_path, url, assets_url, export_url)
def renderer(metadata, ok_new_manifest_path, url, assets_url, export_url):
return JamoviRenderer(metadata, ok_new_manifest_path, url, assets_url, export_url)


class TestCodeJamoviRenderer:
Expand All @@ -73,6 +77,11 @@ def test_render_jamovi(self, renderer):
body = renderer.render()
assert '<div style="word-wrap: break-word; overflow: auto;" class="mfrViewer">' in body

def test_render_jamovi_old_manifest(self, metadata, ok_old_manifest_path, url, assets_url, export_url):
renderer = JamoviRenderer(metadata, ok_old_manifest_path, url, assets_url, export_url)
body = renderer.render()
assert '<div style="word-wrap: break-word; overflow: auto;" class="mfrViewer">' in body

def test_render_jamovi_with_image(self, metadata, ok_with_image_path, url, assets_url,
export_url):
renderer = JamoviRenderer(metadata, ok_with_image_path, url, assets_url, export_url)
Expand Down
Binary file added tests/extensions/jasp/files/ok-new-manifest.jasp
Binary file not shown.
File renamed without changes.
17 changes: 13 additions & 4 deletions tests/extensions/jasp/test_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ def metadata():
return ProviderMetadata('JASP', '.jasp', 'application/octet-stream', '1234', 'http://wb.osf.io/file/JASP.jasp?token=1234')

@pytest.fixture
def ok_path():
return os.path.join(os.path.dirname(os.path.abspath(__file__)), 'files', 'ok.jasp')
def ok_old_manifest_path():
return os.path.join(os.path.dirname(os.path.abspath(__file__)), 'files', 'ok-old-manifest.jasp')

@pytest.fixture
def ok_new_manifest_path():
return os.path.join(os.path.dirname(os.path.abspath(__file__)), 'files', 'ok-new-manifest.jasp')

@pytest.fixture
def not_a_zip_file_path():
Expand Down Expand Up @@ -60,8 +64,8 @@ def extension():


@pytest.fixture
def renderer(metadata, ok_path, url, assets_url, export_url):
return JASPRenderer(metadata, ok_path, url, assets_url, export_url)
def renderer(metadata, ok_new_manifest_path, url, assets_url, export_url):
return JASPRenderer(metadata, ok_new_manifest_path, url, assets_url, export_url)


class TestCodeJASPRenderer:
Expand All @@ -70,6 +74,11 @@ def test_render_JASP(self, renderer):
body = renderer.render()
assert '<div style="word-wrap: break-word; overflow: auto;" class="mfrViewer">' in body

def test_render_JASP_old_manifest(self, metadata, ok_old_manifest_path, url, assets_url, export_url):
renderer = JASPRenderer(metadata, ok_old_manifest_path, url, assets_url, export_url)
body = renderer.render()
assert '<div style="word-wrap: break-word; overflow: auto;" class="mfrViewer">' in body

def test_render_JASP_not_a_zip_file(self, metadata, not_a_zip_file_path, url, assets_url, export_url):
try:
renderer = JASPRenderer(metadata, not_a_zip_file_path, url, assets_url, export_url)
Expand Down

0 comments on commit 878881d

Please sign in to comment.