Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 4 additions & 5 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on: push

jobs:
test:

runs-on: ubuntu-22.04
strategy:
matrix:
Expand All @@ -20,23 +19,23 @@ jobs:

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
with:
python-version: ${{ matrix.python-version }}

- name: Install OS Dependencies
run: |
sudo apt update
sudo apt install python3-dev
sudo apt-get install nco
sudo apt-get install nco
sudo apt-get install curl

- name: Install Poetry
run: |
pip install poetry==2.2

- name: Install project
run: |
poetry install

- name: Test with pytest
run: poetry run pytest
run: poetry run pytest
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM python:3.9-slim

RUN apt-get update && apt-get install -y \
nco \
curl
curl

COPY . /app
WORKDIR /app
Expand Down
12 changes: 10 additions & 2 deletions ncpartitioner/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
In cases of DDS and DAS, the file already exists; for data requests the filemust be created first.
"""

from posixpath import dirname
import subprocess
import os
from flask import redirect
Expand All @@ -11,15 +10,24 @@
logger = logging.getLogger(__name__)


def input_filepath(args):
"""Resolve the source file path for the current request."""
if "filepath" in args:
return os.path.join(args["filepath"], f"{args['basename']}.{args['extension']}")
return f"/{args['dirname']}/{args['basename']}.{args['extension']}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should this use os.path.join as well instead of an fstring for consistency?



def slice(args):
output_dir = os.getenv("OUTPUT_DIR")
thredds_base = os.getenv("THREDDS_HTTP_BASE")
source_filepath = input_filepath(args)

logger.info(f"Slicing file")
try:
subprocess.run(
[
"ncks",
"-4",
"-v",
f"{args['variable']}",
"-d",
Expand All @@ -28,7 +36,7 @@ def slice(args):
f"lat,{args['lat'][0]},{args['lat'][1]}",
"-d",
f"lon,{args['lon'][0]},{args['lon'][1]}",
f"/{args['dirname']}/{args['basename']}.{args['extension']}",
source_filepath,
os.path.join(
output_dir,
f"{args['basename']}_{args['timestamp']}.{args['extension']}",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sanitize.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_check_targets(targets, valid, error):
)
def test_check_ranges(args, valid, error):
args["basename"] = "tasmax"
dirname = "tests/data/"
dirname = "tests/data"
args["dirname"] = dirname
args["extension"] = "nc"

Expand Down
Loading