From 0ce010e9e5772b55d6e2d98bbff2fad1e323d5bc Mon Sep 17 00:00:00 2001 From: Sunny Mak Date: Tue, 11 Jun 2024 18:13:00 +0000 Subject: [PATCH 1/3] Initial code for merge CSV cloud function. Also, refactor github workflows. --- ...n-app.yml => climateiq_data_export_cf.yml} | 10 +++-- .../workflows/climateiq_merge_output_cf.yml | 45 +++++++++++++++++++ .../climateiq_merge_output_cf/main.py | 7 +++ .../climateiq_merge_output_cf/main_test.py | 10 +++++ .../requirements.txt | 26 +++++++++++ 5 files changed, 95 insertions(+), 3 deletions(-) rename .github/workflows/{python-app.yml => climateiq_data_export_cf.yml} (83%) create mode 100644 .github/workflows/climateiq_merge_output_cf.yml create mode 100644 cloud_functions/climateiq_merge_output_cf/main.py create mode 100644 cloud_functions/climateiq_merge_output_cf/main_test.py create mode 100644 cloud_functions/climateiq_merge_output_cf/requirements.txt diff --git a/.github/workflows/python-app.yml b/.github/workflows/climateiq_data_export_cf.yml similarity index 83% rename from .github/workflows/python-app.yml rename to .github/workflows/climateiq_data_export_cf.yml index 6a4989f..31d9a81 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/climateiq_data_export_cf.yml @@ -1,13 +1,17 @@ # This workflow will install Python dependencies, run tests and lint with a single version of Python # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python -name: Python application +name: climateiq_data_export_cf on: push: branches: [ "main" ] + paths: + - "cloud_functions/climateiq_data_export_cf/**" pull_request: branches: [ "main" ] + paths: + - "cloud_functions/climateiq_data_export_cf/**" permissions: contents: read @@ -17,9 +21,9 @@ jobs: name: climateiq_data_export_cf CI runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python 3.11 - uses: actions/setup-python@v3 + uses: actions/setup-python@v5 with: python-version: "3.11" - name: Install dependencies diff --git a/.github/workflows/climateiq_merge_output_cf.yml b/.github/workflows/climateiq_merge_output_cf.yml new file mode 100644 index 0000000..eb7ee99 --- /dev/null +++ b/.github/workflows/climateiq_merge_output_cf.yml @@ -0,0 +1,45 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: climateiq_merge_output_cf + +on: + push: + branches: [ "main" ] + paths: + - "cloud_functions/climateiq_merge_output_cf/**" + pull_request: + branches: [ "main" ] + paths: + - "cloud_functions/climateiq_merge_output_cf/**" + +permissions: + contents: read + +jobs: + climateiq_merge_output_cf: + name: climateiq_merge_output_cf CI + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.11 + uses: actions/setup-python@v5 + with: + python-version: "3.11" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + cd cloud_functions/climateiq_merge_output_cf + pip install -r requirements.txt + - name: Lint with flake8 + run: | + flake8 cloud_functions/climateiq_merge_output_cf --show-source --statistics + - name: Ensure black auto-formatter has run + run: | + black cloud_functions/climateiq_merge_output_cf --check + - name: MyPy Type Checking + run: | + mypy cloud_functions/climateiq_merge_output_cf + - name: Test with pytest + run: | + pytest cloud_functions/climateiq_merge_output_cf diff --git a/cloud_functions/climateiq_merge_output_cf/main.py b/cloud_functions/climateiq_merge_output_cf/main.py new file mode 100644 index 0000000..3050eb6 --- /dev/null +++ b/cloud_functions/climateiq_merge_output_cf/main.py @@ -0,0 +1,7 @@ +from cloudevents import http +import functions_framework + + +@functions_framework.cloud_event +def merge_predictions(cloud_event: http.CloudEvent) -> None: + return diff --git a/cloud_functions/climateiq_merge_output_cf/main_test.py b/cloud_functions/climateiq_merge_output_cf/main_test.py new file mode 100644 index 0000000..0667b53 --- /dev/null +++ b/cloud_functions/climateiq_merge_output_cf/main_test.py @@ -0,0 +1,10 @@ +from cloudevents import http + +import main + + +def test_merge_predictions() -> None: + cloud_event = http.CloudEvent( + {"type": "google.cloud.storage.object.v1.finalized", "source": "source"}, {} + ) + assert main.merge_predictions(cloud_event) is None diff --git a/cloud_functions/climateiq_merge_output_cf/requirements.txt b/cloud_functions/climateiq_merge_output_cf/requirements.txt new file mode 100644 index 0000000..7e5ffe9 --- /dev/null +++ b/cloud_functions/climateiq_merge_output_cf/requirements.txt @@ -0,0 +1,26 @@ +black==24.4.2 +blinker==1.8.2 +click==8.1.7 +cloudevents==1.10.1 +deprecation==2.1.0 +flake8==7.0.0 +Flask==3.0.3 +functions-framework==3.7.0 +gunicorn==22.0.0 +iniconfig==2.0.0 +itsdangerous==2.2.0 +Jinja2==3.1.4 +MarkupSafe==2.1.5 +mccabe==0.7.0 +mypy==1.10.0 +mypy-extensions==1.0.0 +packaging==24.1 +pathspec==0.12.1 +platformdirs==4.2.2 +pluggy==1.5.0 +pycodestyle==2.11.1 +pyflakes==3.2.0 +pytest==8.2.2 +typing_extensions==4.12.2 +watchdog==4.0.1 +Werkzeug==3.0.3 From bfb0dbaddad76a52e8b11b6235c15331c0fb23ae Mon Sep 17 00:00:00 2001 From: Sunny Mak Date: Wed, 12 Jun 2024 21:24:52 +0000 Subject: [PATCH 2/3] Update to address comments. --- cloud_functions/climateiq_merge_output_cf/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud_functions/climateiq_merge_output_cf/main.py b/cloud_functions/climateiq_merge_output_cf/main.py index 3050eb6..75170ab 100644 --- a/cloud_functions/climateiq_merge_output_cf/main.py +++ b/cloud_functions/climateiq_merge_output_cf/main.py @@ -3,5 +3,5 @@ @functions_framework.cloud_event -def merge_predictions(cloud_event: http.CloudEvent) -> None: +def merge_scenario_predictions(cloud_event: http.CloudEvent) -> None: return From e4d84ea335016070de67f8738f294ec2b354c985 Mon Sep 17 00:00:00 2001 From: Sunny Mak Date: Wed, 12 Jun 2024 21:28:55 +0000 Subject: [PATCH 3/3] Update to address comments. --- cloud_functions/climateiq_merge_output_cf/main_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cloud_functions/climateiq_merge_output_cf/main_test.py b/cloud_functions/climateiq_merge_output_cf/main_test.py index 0667b53..240a09f 100644 --- a/cloud_functions/climateiq_merge_output_cf/main_test.py +++ b/cloud_functions/climateiq_merge_output_cf/main_test.py @@ -3,8 +3,8 @@ import main -def test_merge_predictions() -> None: +def test_merge_scenario_predictions() -> None: cloud_event = http.CloudEvent( {"type": "google.cloud.storage.object.v1.finalized", "source": "source"}, {} ) - assert main.merge_predictions(cloud_event) is None + assert main.merge_scenario_predictions(cloud_event) is None