From 4bad7c5bbf5a1911524c0646bef8b6a03f83db5e Mon Sep 17 00:00:00 2001 From: David Michaels Date: Thu, 27 Jul 2023 11:25:16 -0400 Subject: [PATCH] Fix for MIME type ordering in renderers. --- CHANGELOG.rst | 5 ++++ poetry.lock | 48 ++++++++++++----------------------- pyproject.toml | 4 +-- scripts/macpoetry-install | 2 +- snovault/mime_types.py | 5 ++++ snovault/project/renderers.py | 9 +++++++ snovault/project_defs.py | 2 ++ snovault/renderers.py | 7 ++--- 8 files changed, 42 insertions(+), 40 deletions(-) create mode 100644 snovault/mime_types.py create mode 100644 snovault/project/renderers.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3bf69be77..6b07c4aaa 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,11 @@ snovault Change Log ---------- +9.1.0 +===== +* Fix for MIME type ordering in renderers.py (differs between cgap and fourfront). + + 9.0.0 ===== * Merge/unify ingestion and other code from cgap-portal and fourfront. diff --git a/poetry.lock b/poetry.lock index 204947874..5d3abddfe 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2047,41 +2047,25 @@ files = [ [[package]] name = "pyyaml" -version = "5.4.1" +version = "5.3.1" description = "YAML parser and emitter for Python" category = "main" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" +python-versions = "*" files = [ - {file = "PyYAML-5.4.1-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:3b2b1824fe7112845700f815ff6a489360226a5609b96ec2190a45e62a9fc922"}, - {file = "PyYAML-5.4.1-cp27-cp27m-win32.whl", hash = "sha256:129def1b7c1bf22faffd67b8f3724645203b79d8f4cc81f674654d9902cb4393"}, - {file = "PyYAML-5.4.1-cp27-cp27m-win_amd64.whl", hash = "sha256:4465124ef1b18d9ace298060f4eccc64b0850899ac4ac53294547536533800c8"}, - {file = "PyYAML-5.4.1-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:bb4191dfc9306777bc594117aee052446b3fa88737cd13b7188d0e7aa8162185"}, - {file = "PyYAML-5.4.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:6c78645d400265a062508ae399b60b8c167bf003db364ecb26dcab2bda048253"}, - {file = "PyYAML-5.4.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:4e0583d24c881e14342eaf4ec5fbc97f934b999a6828693a99157fde912540cc"}, - {file = "PyYAML-5.4.1-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:72a01f726a9c7851ca9bfad6fd09ca4e090a023c00945ea05ba1638c09dc3347"}, - {file = "PyYAML-5.4.1-cp36-cp36m-manylinux2014_s390x.whl", hash = "sha256:895f61ef02e8fed38159bb70f7e100e00f471eae2bc838cd0f4ebb21e28f8541"}, - {file = "PyYAML-5.4.1-cp36-cp36m-win32.whl", hash = "sha256:3bd0e463264cf257d1ffd2e40223b197271046d09dadf73a0fe82b9c1fc385a5"}, - {file = "PyYAML-5.4.1-cp36-cp36m-win_amd64.whl", hash = "sha256:e4fac90784481d221a8e4b1162afa7c47ed953be40d31ab4629ae917510051df"}, - {file = "PyYAML-5.4.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:5accb17103e43963b80e6f837831f38d314a0495500067cb25afab2e8d7a4018"}, - {file = "PyYAML-5.4.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:e1d4970ea66be07ae37a3c2e48b5ec63f7ba6804bdddfdbd3cfd954d25a82e63"}, - {file = "PyYAML-5.4.1-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:cb333c16912324fd5f769fff6bc5de372e9e7a202247b48870bc251ed40239aa"}, - {file = "PyYAML-5.4.1-cp37-cp37m-manylinux2014_s390x.whl", hash = "sha256:fe69978f3f768926cfa37b867e3843918e012cf83f680806599ddce33c2c68b0"}, - {file = "PyYAML-5.4.1-cp37-cp37m-win32.whl", hash = "sha256:dd5de0646207f053eb0d6c74ae45ba98c3395a571a2891858e87df7c9b9bd51b"}, - {file = "PyYAML-5.4.1-cp37-cp37m-win_amd64.whl", hash = "sha256:08682f6b72c722394747bddaf0aa62277e02557c0fd1c42cb853016a38f8dedf"}, - {file = "PyYAML-5.4.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:d2d9808ea7b4af864f35ea216be506ecec180628aced0704e34aca0b040ffe46"}, - {file = "PyYAML-5.4.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:8c1be557ee92a20f184922c7b6424e8ab6691788e6d86137c5d93c1a6ec1b8fb"}, - {file = "PyYAML-5.4.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:fd7f6999a8070df521b6384004ef42833b9bd62cfee11a09bda1079b4b704247"}, - {file = "PyYAML-5.4.1-cp38-cp38-manylinux2014_s390x.whl", hash = "sha256:bfb51918d4ff3d77c1c856a9699f8492c612cde32fd3bcd344af9be34999bfdc"}, - {file = "PyYAML-5.4.1-cp38-cp38-win32.whl", hash = "sha256:fa5ae20527d8e831e8230cbffd9f8fe952815b2b7dae6ffec25318803a7528fc"}, - {file = "PyYAML-5.4.1-cp38-cp38-win_amd64.whl", hash = "sha256:0f5f5786c0e09baddcd8b4b45f20a7b5d61a7e7e99846e3c799b05c7c53fa696"}, - {file = "PyYAML-5.4.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:294db365efa064d00b8d1ef65d8ea2c3426ac366c0c4368d930bf1c5fb497f77"}, - {file = "PyYAML-5.4.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:74c1485f7707cf707a7aef42ef6322b8f97921bd89be2ab6317fd782c2d53183"}, - {file = "PyYAML-5.4.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:d483ad4e639292c90170eb6f7783ad19490e7a8defb3e46f97dfe4bacae89122"}, - {file = "PyYAML-5.4.1-cp39-cp39-manylinux2014_s390x.whl", hash = "sha256:fdc842473cd33f45ff6bce46aea678a54e3d21f1b61a7750ce3c498eedfe25d6"}, - {file = "PyYAML-5.4.1-cp39-cp39-win32.whl", hash = "sha256:49d4cdd9065b9b6e206d0595fee27a96b5dd22618e7520c33204a4a3239d5b10"}, - {file = "PyYAML-5.4.1-cp39-cp39-win_amd64.whl", hash = "sha256:c20cfa2d49991c8b4147af39859b167664f2ad4561704ee74c1de03318e898db"}, - {file = "PyYAML-5.4.1.tar.gz", hash = "sha256:607774cbba28732bfa802b54baa7484215f530991055bb562efbed5b2f20a45e"}, + {file = "PyYAML-5.3.1-cp27-cp27m-win32.whl", hash = "sha256:74809a57b329d6cc0fdccee6318f44b9b8649961fa73144a98735b0aaf029f1f"}, + {file = "PyYAML-5.3.1-cp27-cp27m-win_amd64.whl", hash = "sha256:240097ff019d7c70a4922b6869d8a86407758333f02203e0fc6ff79c5dcede76"}, + {file = "PyYAML-5.3.1-cp35-cp35m-win32.whl", hash = "sha256:4f4b913ca1a7319b33cfb1369e91e50354d6f07a135f3b901aca02aa95940bd2"}, + {file = "PyYAML-5.3.1-cp35-cp35m-win_amd64.whl", hash = "sha256:cc8955cfbfc7a115fa81d85284ee61147059a753344bc51098f3ccd69b0d7e0c"}, + {file = "PyYAML-5.3.1-cp36-cp36m-win32.whl", hash = "sha256:7739fc0fa8205b3ee8808aea45e968bc90082c10aef6ea95e855e10abf4a37b2"}, + {file = "PyYAML-5.3.1-cp36-cp36m-win_amd64.whl", hash = "sha256:69f00dca373f240f842b2931fb2c7e14ddbacd1397d57157a9b005a6a9942648"}, + {file = "PyYAML-5.3.1-cp37-cp37m-win32.whl", hash = "sha256:d13155f591e6fcc1ec3b30685d50bf0711574e2c0dfffd7644babf8b5102ca1a"}, + {file = "PyYAML-5.3.1-cp37-cp37m-win_amd64.whl", hash = "sha256:73f099454b799e05e5ab51423c7bcf361c58d3206fa7b0d555426b1f4d9a3eaf"}, + {file = "PyYAML-5.3.1-cp38-cp38-win32.whl", hash = "sha256:06a0d7ba600ce0b2d2fe2e78453a470b5a6e000a985dd4a4e54e436cc36b0e97"}, + {file = "PyYAML-5.3.1-cp38-cp38-win_amd64.whl", hash = "sha256:95f71d2af0ff4227885f7a6605c37fd53d3a106fcab511b8860ecca9fcf400ee"}, + {file = "PyYAML-5.3.1-cp39-cp39-win32.whl", hash = "sha256:ad9c67312c84def58f3c04504727ca879cb0013b2517c85a9a253f0cb6380c0a"}, + {file = "PyYAML-5.3.1-cp39-cp39-win_amd64.whl", hash = "sha256:6034f55dab5fea9e53f436aa68fa3ace2634918e8b5994d82f3621c04ff5ed2e"}, + {file = "PyYAML-5.3.1.tar.gz", hash = "sha256:b8eac752c5e14d3eca0e6dd9199cd627518cb5ec06add0de9d32baeee6fe645d"}, ] [[package]] @@ -2947,4 +2931,4 @@ test = ["zope.testing"] [metadata] lock-version = "2.0" python-versions = ">=3.8.1,<3.10" -content-hash = "7e2fc0b62f4f41c4abb2c5383b7e5d6abf05f6a9890578af5b3231ee8ddbff68" +content-hash = "e1507ed8e8457685176b07b48ee59b6a788df263d507b2d96be144a6d48b8b68" diff --git a/pyproject.toml b/pyproject.toml index 1adbce250..4629e5e48 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dcicsnovault" -version = "9.0.0" +version = "9.0.0.1b1" # TODO: To become 9.1.0 description = "Storage support for 4DN Data Portals." authors = ["4DN-DCIC Team "] license = "MIT" @@ -123,7 +123,7 @@ pytest-timeout = ">=1.0.0" # 5.2 had soe bugs that were probably only in Python 2, but we require 5.2 here just in case. # Any narrowing beyond that is just to help 'poetry lock' converge faster. # And we only need .safe_load in testing, so we're moving this to dev dependencies. -kmp 22-Feb-2022 -PyYAML = ">=5.1,<5.5" +PyYAML = "5.3.1" "repoze.debug" = ">=1.0.2" wheel = ">=0.40.0" diff --git a/scripts/macpoetry-install b/scripts/macpoetry-install index d613df170..8ff5c1449 100755 --- a/scripts/macpoetry-install +++ b/scripts/macpoetry-install @@ -1,6 +1,6 @@ #!/bin/bash # For some reason on Mac M1 (as of July 2023) pyyaml install via poetry is problematic. -pip install pyyaml==5.4.1 +pip install pyyaml==5.3.1 CFLAGS="-I$(brew --prefix zlib)/include" LDFLAGS="-L$(brew --prefix zlib)/lib" poetry install diff --git a/snovault/mime_types.py b/snovault/mime_types.py new file mode 100644 index 000000000..f1c2fe15b --- /dev/null +++ b/snovault/mime_types.py @@ -0,0 +1,5 @@ +# Web browsers send an Accept request header for initial (e.g. non-AJAX) page requests +# which should contain 'text/html' +MIME_TYPE_HTML = 'text/html' +MIME_TYPE_JSON = 'application/json' +MIME_TYPE_LD_JSON = 'application/ld+json' diff --git a/snovault/project/renderers.py b/snovault/project/renderers.py new file mode 100644 index 000000000..fec947d94 --- /dev/null +++ b/snovault/project/renderers.py @@ -0,0 +1,9 @@ +# Renderers related functions which may be overriden by an implementing app, +# e.g. Foursight or CGAP portal, using the dcicutils project_utils mechanism. + +from ..mime_types import MIME_TYPE_HTML, MIME_TYPE_JSON, MIME_TYPE_LD_JSON + + +class SnovaultProjectRenderers: + def renderers_mime_types_supported(self): + return [MIME_TYPE_JSON, MIME_TYPE_HTML, MIME_TYPE_LD_JSON] diff --git a/snovault/project_defs.py b/snovault/project_defs.py index 35109d132..05907d261 100644 --- a/snovault/project_defs.py +++ b/snovault/project_defs.py @@ -4,6 +4,7 @@ from .project.authorization import SnovaultProjectAuthorization from .project.ingestion import SnovaultProjectIngestion from .project.loadxl import SnovaultProjectLoadxl +from .project.renderers import SnovaultProjectRenderers @C4ProjectRegistry.register("dcicsnovault") @@ -12,6 +13,7 @@ class SnovaultProject(SnovaultProjectAccessKey, SnovaultProjectAuthorization, SnovaultProjectIngestion, SnovaultProjectLoadxl, + SnovaultProjectRenderers, C4Project): NAMES = {"NAME": "snovault", "PYPI_NAME": "dcicsnovault"} ACCESSION_PREFIX = "SNO" diff --git a/snovault/renderers.py b/snovault/renderers.py index 15ae6bd53..125c64043 100644 --- a/snovault/renderers.py +++ b/snovault/renderers.py @@ -24,6 +24,7 @@ from subprocess_middleware.worker import TransformWorker from urllib.parse import urlencode from webob.cookies import Cookie +from .mime_types import MIME_TYPE_HTML, MIME_TYPE_JSON, MIME_TYPE_LD_JSON from .project_app import app_project from .util import content_type_allowed @@ -314,13 +315,9 @@ def canonical_redirect(event): # Web browsers send an Accept request header for initial (e.g. non-AJAX) page requests # which should contain 'text/html' -MIME_TYPE_HTML = 'text/html' -MIME_TYPE_JSON = 'application/json' -MIME_TYPE_LD_JSON = 'application/ld+json' - # Note: In cgap-portal, MIME_TYPE_JSON is at the head of this list. In fourfront, MIME_TYPE_HTML is. # The cgap-portal behavior might be a bug we should look at bringing into alignment. -kmp 29-Jan-2022 -MIME_TYPES_SUPPORTED = [MIME_TYPE_JSON, MIME_TYPE_HTML, MIME_TYPE_LD_JSON] +MIME_TYPES_SUPPORTED = app_project().renderers_mime_types_supported() MIME_TYPE_DEFAULT = MIME_TYPES_SUPPORTED[0] MIME_TYPE_TRIAGE_MODE = 'modern' # if this doesn't work, fall back to 'legacy'