Skip to content

Commit

Permalink
[2022-11-01 20:48] Fixed package not working (#78)
Browse files Browse the repository at this point in the history
FIXED:
 - The var_map location should now properly be detected.
 - The scripts have been altered to properly work in every execution mode.
 - Some remaining "print()"s have been removed

CHANGES:
 - The version update workflow now starts building images regardless of progress in the package deployment stage.

Closes #77 

Signed-off-by: Raoul Linnenbank <[email protected]>
  • Loading branch information
rflinnenbank authored Nov 1, 2022
1 parent f6f73c3 commit 59ab32f
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/version-update-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
# ---------------------------------------------------------------- #
create-and-upload-image:
name: Create and upload the image
needs: package-creation-and-upload
needs: tests-and-sonarcloud
runs-on: ubuntu-latest
permissions:
id-token: write
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
[tool.poetry]
name = "weather_provider_api"
version = "2.21.08"
version = "2.29.0"
description = "Weather Provider Libraries and API"
authors = ["Verbindingsteam", "Raoul Linnenbank <[email protected]>"]
license = "MPL-2.0"
readme = "README.md"
repository="https://github.com/alliander-opensource/wpla/"
include = [
{path = "var_maps/*.json", format = "wheel"}
]

[tool.poetry.dependencies]
python = ">=3.8,<4.0"
Expand Down
1 change: 0 additions & 1 deletion tests/test_grid_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,5 @@ def test_round_to_grid(
coordinates, grid_resolution_lat_lon, starting_points_lat_lon
)

print(len(results))
for result_coordinate, expected_result_coordinate in zip(results, expected_results):
assert result_coordinate.get_WGS84() == expected_result_coordinate.get_WGS84()
1 change: 0 additions & 1 deletion tests/test_weather_alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class FakeResponse:
requests.Session, "get", mock_request_response
) # Intercepting request response
output = wa.get_alarm()
print(output)

assert (
len(output) == 12
Expand Down
49 changes: 30 additions & 19 deletions weather_provider_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Its '__main__' if-clause handles running it directly from a directory or IDE setting.
"""
from datetime import datetime

import structlog
import uvicorn
Expand All @@ -30,29 +31,39 @@
from weather_provider_api.versions.v1 import app as v1
from weather_provider_api.versions.v2 import app as v2

# Enable logging
initialize_logging()
logger = structlog.get_logger(__name__)

# Create and configure new application instance
app = FastAPI(version=get_setting("APP_VERSION"), title=get_setting("APP_NAME"))
initialize_error_handling(app)
initialize_metadata_header_middleware(app)
initialize_validation_middleware(app)
initialize_prometheus_middleware(app)
def main():
# Enable logging
initialize_logging()
logger = structlog.get_logger(__name__)
logger.info(f'--------------------------------------', datetime=datetime.utcnow())
logger.info(f'Booting Weather Provider API Systems..', datetime=datetime.utcnow())
logger.info(f'--------------------------------------', datetime=datetime.utcnow())

# Activate enabled API versions
mount_api_version(app, v1)
mount_api_version(app, v2)
# Create and configure new application instance
app = FastAPI(version=get_setting("APP_VERSION"), title=get_setting("APP_NAME"))
initialize_error_handling(app)
initialize_metadata_header_middleware(app)
initialize_validation_middleware(app)
initialize_prometheus_middleware(app)

# Activate enabled API versions
mount_api_version(app, v1)
mount_api_version(app, v2)

# Redirect users to the docs
@app.get("/")
def redirect_to_docs():
redirect_url = "/api/v2/docs" # replace with docs URL or use weather_provider_api.url_path_for()
return RedirectResponse(url=redirect_url)
# Redirect users to the docs
@app.get("/")
def redirect_to_docs():
redirect_url = "/api/v2/docs" # replace with docs URL or use weather_provider_api.url_path_for()
return RedirectResponse(url=redirect_url)

logger.info(f'--------------------------------------', datetime=datetime.utcnow())
logger.info(f'Finished booting; starting uvicorn...', datetime=datetime.utcnow())
logger.info(f'--------------------------------------', datetime=datetime.utcnow())

if __name__ == "__main__":
# Run the application locally
uvicorn.run(app, host="127.0.0.1", port=8080)


if __name__ == "__main__":
main()

Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def get_alarm(self):
A function that retrieves the current weather alarm stage for each of the Dutch provinces and puts those
together into a formatted list of results (string-based).
Returns:
A list of strings holding all of the provinces and their retrieved current alarm stages according to KNMI
A list of strings holding all the provinces and their retrieved current alarm stages according to KNMI
"""
alarm_list = []
for province in self.provinces:
Expand Down Expand Up @@ -93,7 +93,6 @@ def process_page(page_text: str, status_code, province):
if status_code == 200 and page_text is not None:
# A page was found and loaded
soup = BeautifulSoup(page_text, features="lxml")
print(soup.find("div"))

classes_first_warning_block = soup.find(
"div", {"class": "warning-overview"}
Expand Down
18 changes: 11 additions & 7 deletions weather_provider_api/routers/weather/utils/file_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
# SPDX-License-Identifier: MPL-2.0

import os
import sys
import site
from pathlib import Path

import structlog


async def remove_file(
file_path, logger=structlog.get_logger(__name__)
file_path, logger=structlog.get_logger(__name__)
): # pragma: no cover
if file_path is not None:
try:
Expand All @@ -27,16 +27,20 @@ async def remove_file(


def get_var_map_file_location(filename: str) -> Path:
logger = structlog.get_logger(__name__)
var_map_folder = 'var_maps'

possible_main_folders = [
Path(os.getcwd()),
Path(os.getcwd()).parent,
Path(sys.prefix)
Path(os.getcwd()), # Running from main folder
Path(os.getcwd()).parent, # Running from weather_provider_api folder or scripts
Path(site.getsitepackages()[-1]), # Running as package
]

for folder in possible_main_folders:
if folder.joinpath(var_map_folder).exists():
return folder.joinpath(var_map_folder).joinpath(filename)
possible_var_map_folder = folder.joinpath(var_map_folder)
if possible_var_map_folder.exists():
logger.info(f'"var_maps" folder was found at: {possible_var_map_folder}')
return possible_var_map_folder.joinpath(filename)


raise FileNotFoundError
2 changes: 0 additions & 2 deletions weather_provider_api/routers/weather/utils/grid_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ def round_coordinates_to_wgs84_grid(
for coordinate in wgs84_coordinate_list
]

print(rounded_wgs84_coordinate_list)

return [
GeoPosition(coordinate[0], coordinate[1])
for coordinate in rounded_wgs84_coordinate_list
Expand Down
7 changes: 6 additions & 1 deletion weather_provider_api/scripts/erase_arome_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

from weather_provider_api.routers.weather.sources.knmi.client.arome_repository import AromeRepository

if __name__ == "__main__":

def main():
arome_repo = AromeRepository()
arome_repo.purge_repository()


if __name__ == "__main__":
main()
11 changes: 7 additions & 4 deletions weather_provider_api/scripts/erase_era5land_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
# SPDX-License-Identifier: MPL-2.0


from weather_provider_api.routers.weather.sources.cds.client.era5land_repository import (
ERA5LandRepository,
)
from weather_provider_api.routers.weather.sources.cds.client.era5land_repository import ERA5LandRepository

if __name__ == "__main__": # pragma: no cover

def main():
era5land_repo = ERA5LandRepository()
era5land_repo.purge_repository()


if __name__ == "__main__": # pragma: no cover
main()
7 changes: 6 additions & 1 deletion weather_provider_api/scripts/erase_era5sl_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

from weather_provider_api.routers.weather.sources.cds.client.era5sl_repository import ERA5SLRepository

if __name__ == "__main__":

def main():
era5sl_repo = ERA5SLRepository()
era5sl_repo.purge_repository()


if __name__ == "__main__":
main()
7 changes: 6 additions & 1 deletion weather_provider_api/scripts/update_arome_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

from weather_provider_api.routers.weather.sources.knmi.client.arome_repository import AromeRepository

if __name__ == "__main__":

def main():
arome_repo = AromeRepository()
arome_repo.update()


if __name__ == "__main__":
main()
7 changes: 6 additions & 1 deletion weather_provider_api/scripts/update_era5land_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
# -*- coding: utf-8 -*-
from weather_provider_api.routers.weather.sources.cds.client.era5land_repository import ERA5LandRepository

if __name__ == "__main__": # pragma: no cover

def main():
era5land_repo = ERA5LandRepository()
era5land_repo.update()


if __name__ == "__main__": # pragma: no cover
main()
7 changes: 6 additions & 1 deletion weather_provider_api/scripts/update_era5sl_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

from weather_provider_api.routers.weather.sources.cds.client.era5sl_repository import ERA5SLRepository

if __name__ == "__main__":

def main():
era5sl_repo = ERA5SLRepository()
era5sl_repo.update()


if __name__ == "__main__":
main()

0 comments on commit 59ab32f

Please sign in to comment.