From b823474acc52d3acca723140f3c58d360bbcc4b7 Mon Sep 17 00:00:00 2001 From: Peter Dudfield <34686298+peterdudfield@users.noreply.github.com> Date: Fri, 27 Jan 2023 09:11:47 +0000 Subject: [PATCH] Fix to use with pv site production (#32) * Make the sqlalchemy dependency more flexible * Expose types * add site relationship on GenerationSQL Co-authored-by: Simon Lemieux <1105380+simlmx@users.noreply.github.com> --- sdk/python/pvsite_datamodel/py.typed | 0 sdk/python/pvsite_datamodel/sqlmodels.py | 2 ++ sdk/python/requirements.txt | 2 +- sdk/python/setup.py | 1 + sdk/python/tests/test_read.py | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 sdk/python/pvsite_datamodel/py.typed diff --git a/sdk/python/pvsite_datamodel/py.typed b/sdk/python/pvsite_datamodel/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/sdk/python/pvsite_datamodel/sqlmodels.py b/sdk/python/pvsite_datamodel/sqlmodels.py index 0f0ba21..148b698 100644 --- a/sdk/python/pvsite_datamodel/sqlmodels.py +++ b/sdk/python/pvsite_datamodel/sqlmodels.py @@ -2,6 +2,7 @@ SQLAlchemy definition of the pvsite database schema """ from __future__ import annotations + # This means we can use Typing of objects that have jet to be defined import uuid @@ -89,6 +90,7 @@ class GenerationSQL(Base, CreatedMixin): datetime_interval: DatetimeIntervalSQL = relationship( "DatetimeIntervalSQL", back_populates="generation" ) + site: SiteSQL = relationship("SiteSQL", back_populates="generation") class ForecastSQL(Base, CreatedMixin): diff --git a/sdk/python/requirements.txt b/sdk/python/requirements.txt index 63693e4..907e0c5 100644 --- a/sdk/python/requirements.txt +++ b/sdk/python/requirements.txt @@ -5,5 +5,5 @@ psycopg2-binary==2.9.5 pytest==7.2.1 python-dateutil==2.8.2 setuptools==65.6.3 -SQLAlchemy==1.4.44 +SQLAlchemy >= 1.4.44, == 1.4.* testcontainers==3.7.1 diff --git a/sdk/python/setup.py b/sdk/python/setup.py index 6f5a88c..d1efe26 100644 --- a/sdk/python/setup.py +++ b/sdk/python/setup.py @@ -7,4 +7,5 @@ setup( long_description=long_description, long_description_content_type="text/markdown", + package_data={"pvsite_datamodel": ["pvsite-datamodel/py.typed"]}, ) diff --git a/sdk/python/tests/test_read.py b/sdk/python/tests/test_read.py index 7487086..54a4660 100644 --- a/sdk/python/tests/test_read.py +++ b/sdk/python/tests/test_read.py @@ -112,6 +112,7 @@ def test_gets_generation_for_single_input_site(self, generations, db_session): assert len(generations) == 10 assert generations[0].datetime_interval is not None + assert generations[0].site is not None def test_gets_generation_for_multiple_input_sites(self, generations, db_session): query: Query = db_session.query(SiteSQL)