Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Job output transform #548

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
07a27e7
Transformer Implementation
OlivGruwe Jun 7, 2023
3c1ef15
Transformer Implementation
OlivGruwe Jun 7, 2023
6d23b4c
Transformer Implementation +
OlivGruwe Jun 12, 2023
d85aa30
Transformer Implementation
OlivGruwe Jun 12, 2023
b02bb01
Transformer Implementation
OlivGruwe Jun 12, 2023
d7c727f
Transformer Implementation
OlivGruwe Jun 12, 2023
b3b4f52
Transformer Implementation
OlivGruwe Jun 12, 2023
dcde84e
Correction Txt -> Pdf
OlivGruwe Jul 3, 2023
d6b8c6c
Merge branch 'master' of github.com:crim-ca/weaver into job_output_tr…
Nazim-crim Sep 24, 2024
b3048bb
Fixing naming typos
Nazim-crim Sep 24, 2024
a23519e
Adding libpangocairo to dockerfile
Nazim-crim Sep 24, 2024
ee9c208
Fixing import and linting
Nazim-crim Sep 25, 2024
a8d4473
Fixing docker call and removing unused code
Nazim-crim Sep 26, 2024
574314c
Removing transformer route and test in job, fixing makefile
Nazim-crim Sep 26, 2024
0304b3a
Adding swagger and endpoint definition to support outputId and resultId
Nazim-crim Sep 26, 2024
4cf0e80
Adding in config output and result service
Nazim-crim Oct 1, 2024
81721dd
Fixing test to use transformer resource path
Nazim-crim Oct 11, 2024
e66c582
Fix transform function any to pdf and any to html for transform test …
Nazim-crim Oct 11, 2024
34cd699
Fix import lint
Nazim-crim Oct 11, 2024
fe71427
fixing some linting
Nazim-crim Oct 15, 2024
71f6f96
Adding get job output route
Nazim-crim Oct 15, 2024
34ddd87
Fxing more linting
Nazim-crim Oct 15, 2024
5fe2af0
Merge branch 'master' of github.com:crim-ca/weaver into job_output_tr…
Nazim-crim Oct 15, 2024
9fedeb7
Remove duplicate code from merge
Nazim-crim Oct 15, 2024
13d3d17
Update get job output to use get_job_results_single and refactor tran…
Nazim-crim Oct 15, 2024
bc14eac
fix docstring
Nazim-crim Oct 15, 2024
a837ff0
Fixing wps api test
Nazim-crim Oct 25, 2024
037a8a4
Fix test and transform to use conversion list and content type from f…
Nazim-crim Oct 28, 2024
a658579
Merge branch 'master' of github.com:crim-ca/weaver into job_output_tr…
Nazim-crim Oct 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ DOCKER_REPO ?= pavics/weaver
# guess OS (Linux, Darwin,...)
OS_NAME := $(shell uname -s 2>/dev/null || echo "unknown")
CPU_ARCH := $(shell uname -m 2>/dev/null || uname -p 2>/dev/null || echo "unknown")
SUDO ?=

# conda
CONDA_CMD ?= __EMPTY__
Expand Down Expand Up @@ -228,10 +229,10 @@ conda-env-export: ## export the conda environment
install: install-all ## alias for 'install-all' target

.PHONY: install-run
install-run: conda-install install-sys install-pkg install-raw ## install requirements and application to run locally
install-run: conda-install install-sys install-pkg install-raw install-dev install-transform ## install requirements and application to run locally

.PHONY: install-all
install-all: conda-install install-sys install-pkg install-pip install-dev ## install application with all dependencies
install-all: conda-install install-sys install-pkg install-pip install-dev install-transform ## install application with all dependencies

.PHONY: install-doc
install-doc: install-pip ## install documentation dependencies
Expand Down Expand Up @@ -274,7 +275,7 @@ install-raw: ## install without any requirements or dependencies (suppose everyt
install-npm: ## install npm package manager and dependencies if they cannot be found
@[ -f "$(shell which npm)" ] || ( \
echo "Binary package manager npm not found. Attempting to install it."; \
apt-get install npm \
$(SUDO) apt-get install npm \
)

.PHONY: install-npm-stylelint
Expand All @@ -291,6 +292,16 @@ install-npm-remarklint: install-npm ## install remark-lint dependency for 'chec
npm install --save-dev \
)

.PHONY: install-transform
install-transform: install-cairo-dependencies # install-transform dependencies

.PHONY: install-cairo-dependencies
install-cairo-dependencies: ## install required dependencies for Transformer
@[ -f "$(shell which cairo)" ] || ( \
echo "Binary package manager cairo not found. Attempting to install it."; \
$(SUDO) apt-get install libpangocairo-1.0-0 \
)

.PHONY: install-dev-npm
install-dev-npm: install-npm install-npm-remarklint install-npm-remarklint ## install all npm development dependencies

Expand Down Expand Up @@ -833,6 +844,7 @@ docker-clean: ## remove all built docker images (only matching current/latest v
docker rmi -f "$(APP_NAME):latest" || true
docker rmi -f "$(APP_NAME):base" || true


## -- Launchers targets --------------------------------------------------------------------------------------------- ##

.PHONY: start
Expand Down
2 changes: 1 addition & 1 deletion config/weaver.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,4 @@ level = NOTSET
formatter = generic

[formatter_generic]
format = [%(asctime)s] %(levelname)-8.8s [%(threadName)s][%(name)s] %(message)s
format = [%(asctime)s] %(levelname)-8.8s [%(threadName)s][%(name)s] %(message)s
1 change: 1 addition & 0 deletions docker/Dockerfile-base
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
g++ \
git \
nodejs \
libpangocairo-1.0-0 \
&& pip install --no-cache-dir --upgrade -r requirements-sys.txt \
&& pip install --no-cache-dir -r requirements.txt \
&& pip install --no-cache-dir -e ${APP_DIR} \
Expand Down
10 changes: 10 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,13 @@ typing_extensions
WebTest
wsgiproxy
WSGIProxy2

# transformer
fpdf
Pillow
pandas
cairosvg
multipagetiff
# gdal
rasterio
python-magic
Comment on lines +45 to +53
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Makefile refers to a requirements-trfm.txt file. Those should be moved into that file. It can then be embedded in this file using -r requirements-trfm.txt (as done in the top).

12 changes: 12 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ gunicorn>=22
# even more reduced dependency constraints (https://github.com/vinitkumar/json2xml/pull/195)
json2xml==4.1.0
jsonschema>=3.0.1

# FIXME: kombu for pymongo>=4 not yet released as 5.3.0 (only pre-releases available)
# - https://github.com/crim-ca/weaver/issues/386
# - https://github.com/celery/kombu/pull/1536
Expand Down Expand Up @@ -124,5 +125,16 @@ urllib3==1.26.19 ; python_version < "3.10" # pyup: ignore
urlmatch
xmltodict
webob
werkzeug>2

# transformer
fpdf
Pillow
pandas
cairosvg
multipagetiff
# gdal
rasterio
python-magic
werkzeug>=3.0.3,<3.1
zipp>=3.19.1 # not directly required, pinned by Snyk to avoid a vulnerability
39 changes: 19 additions & 20 deletions tests/functional/test_wps_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -4325,8 +4325,6 @@ def test_execute_single_output_multipart_accept_link(self):
},
}

# FIXME: implement (https://github.com/crim-ca/weaver/pull/548)
@pytest.mark.xfail(reason="not implemented")
def test_execute_single_output_multipart_accept_alt_format(self):
"""
Validate the returned contents combining an ``Accept`` header as ``multipart`` and a ``format`` in ``outputs``.
Expand Down Expand Up @@ -4381,23 +4379,25 @@ def test_execute_single_output_multipart_accept_alt_format(self):
output_json_as_yaml = yaml.safe_dump({"data": "test"})
results_body = self.fix_result_multipart_indent(f"""
--{boundary}
Content-Disposition: attachment; name="output_json"; filename="result.yml"
Content-Type: {ContentType.APP_YAML}
Content-Location: {out_url}/{job_id}/output_json/result.yml
Content-ID: <output_json@{job_id}>
Content-Length: 12
Content-Length: 11

{output_json_as_yaml}
--{boundary}--
""")
results_text = self.remove_result_multipart_variable(results.text)
assert results.content_type.startswith(ContentType.MULTIPART_MIXED)
assert results_text == results_body
for line1, line2 in zip(results_text.splitlines(), results_body.splitlines()):
assert line1 == line2
outputs = self.app.get(f"/jobs/{job_id}/outputs", params={"schema": JobInputsOutputsSchema.OGC_STRICT})
assert outputs.content_type.startswith(ContentType.APP_JSON)
assert outputs.json["outputs"] == {
"output_data": "test",
"output_json": {
"href": f"{out_url}/{job_id}/output_json/output.yml",
"type": ContentType.APP_YAML,
"href": f"{out_url}/{job_id}/output_json/result.json",
"type": ContentType.APP_JSON,
},
}

Expand All @@ -4407,8 +4407,6 @@ def test_execute_single_output_multipart_accept_alt_format(self):
assert result_json.content_type == ContentType.APP_JSON
assert result_json.text == "{\"data\":\"test\"}"

# FIXME: implement (https://github.com/crim-ca/weaver/pull/548)
@pytest.mark.xfail(reason="not implemented")
def test_execute_single_output_response_document_alt_format_yaml(self):
proc = "EchoResultsTester"
p_id = self.fully_qualified_test_process_name(proc)
Expand Down Expand Up @@ -4457,27 +4455,29 @@ def test_execute_single_output_response_document_alt_format_yaml(self):
output_json_as_yaml = yaml.safe_dump({"data": "test"})
results_body = self.fix_result_multipart_indent(f"""
--{boundary}
Content-Disposition: attachment; name="output_json"; filename="result.yml"
Content-Type: {ContentType.APP_YAML}
Content-Location: {out_url}/{job_id}/output_json/result.yml
Content-ID: <output_json@{job_id}>
Content-Length: 12
Content-Length: 11

{output_json_as_yaml}
--{boundary}--
""")
results_text = self.remove_result_multipart_variable(results.text)
assert results.content_type.startswith(ContentType.MULTIPART_MIXED)
assert results_text == results_body
for line1, line2 in zip(results_text.splitlines(), results_body.splitlines()):
assert line1 == line2

outputs = self.app.get(f"/jobs/{job_id}/outputs", params={"schema": JobInputsOutputsSchema.OGC_STRICT})
assert outputs.content_type.startswith(ContentType.APP_JSON)
assert outputs.json["outputs"] == {
"output_data": "test",
"output_json": {
"href": f"{out_url}/{job_id}/output_json/output.yml",
"type": ContentType.APP_YAML,
"href": f"{out_url}/{job_id}/output_json/result.json",
"type": ContentType.APP_JSON,
},
}

# FIXME: implement (https://github.com/crim-ca/weaver/pull/548)
# validate the results can be obtained with the "real" representation
result_json = self.app.get(f"/jobs/{job_id}/results/output_json", headers=self.json_headers)
assert result_json.status_code == 200, f"Failed with: [{resp.status_code}]\nReason:\n{resp.json}"
Expand Down Expand Up @@ -4548,12 +4548,11 @@ def test_execute_single_output_response_document_alt_format_json_raw_literal(sel
},
}

# FIXME: add check of direct request of output (https://github.com/crim-ca/weaver/pull/548)
# validate the results can be obtained with the "real" representation
# result_json = self.app.get(f"/jobs/{job_id}/results/output_json", headers=self.json_headers)
# assert result_json.status_code == 200, f"Failed with: [{resp.status_code}]\nReason:\n{resp.json}"
# assert result_json.content_type == ContentType.APP_JSON
# assert result_json.json == {"data": "test"}
result_json = self.app.get(f"/jobs/{job_id}/results/output_json", headers=self.json_headers)
assert result_json.status_code == 200, f"Failed with: [{resp.status_code}]\nReason:\n{resp.json}"
assert result_json.content_type == ContentType.APP_JSON
assert result_json.json == {"data": "test"}

def test_execute_single_output_response_document_default_format_json_special(self):
"""
Expand Down
3 changes: 3 additions & 0 deletions tests/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from weaver.typedefs import JSON

RESOURCES_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), ""))
TRANSFORM_PATH = os.path.join(RESOURCES_PATH, "transform")
EXAMPLES_PATH = os.path.join(WEAVER_MODULE_DIR, "wps_restapi/examples")
FUNCTIONAL_APP_PKG = os.path.abspath(os.path.join(RESOURCES_PATH, "../functional/application-packages"))

Expand Down Expand Up @@ -62,6 +63,8 @@
TEST_REMOTE_SERVER_URL, WPS_NO_INPUTS_ID
)

WPS_transform_RESSOURCES = os.path.join(RESOURCES_PATH, "transform")


def _load_path(file_path, text=False, xml=False):
# type: (str, bool, bool) -> Union[JSON, xml_util.XML, str]
Expand Down
Loading
Loading