From 4d8d41f1d4a3de284ef6d817c36df967dfdd1143 Mon Sep 17 00:00:00 2001 From: Paco Valdez Date: Tue, 6 May 2025 10:45:13 -0700 Subject: [PATCH 1/3] Fix for multiple primary keys --- src/cube_dbt/model.py | 10 +- tests/test_model.py | 493 ++++++++++++++++++++---------------------- 2 files changed, 241 insertions(+), 262 deletions(-) diff --git a/src/cube_dbt/model.py b/src/cube_dbt/model.py index 975e870..4e3ff3b 100644 --- a/src/cube_dbt/model.py +++ b/src/cube_dbt/model.py @@ -19,16 +19,10 @@ def _init_columns(self) -> None: self._detect_primary_key() def _detect_primary_key(self) -> None: - candidates = list( + self._primary_key = list( column for column in self._columns if column.primary_key ) - - if len(candidates) > 1: - column_names = list(column.name for column in candidates) - raise RuntimeError(f"More than one primary key column found in {self.name}: {', '.join(column_names)}") - - self._primary_key = candidates[0] if len(candidates) == 1 else None @property def name(self) -> str: @@ -58,7 +52,7 @@ def column(self, name: str) -> Column: return next(column for column in self._columns if column.name == name) @property - def primary_key(self) -> Column or None: + def primary_key(self) -> list[Column]: self._init_columns() return self._primary_key diff --git a/tests/test_model.py b/tests/test_model.py index 58143c5..fe6742e 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -1,288 +1,273 @@ from pytest import raises from cube_dbt import Model + class TestModel: - def test_sql_table_with_relation(self): - """ - If a relation is present, then use it - """ - model_dict = { - 'relation_name': '"db"."schema"."table"', - 'database': 'db_2', - 'schema': 'schema_2', - 'name': 'table_2' - } - model = Model(model_dict) - assert model.sql_table == '"db"."schema"."table"' + def test_sql_table_with_relation(self): + """ + If a relation is present, then use it + """ + model_dict = { + "relation_name": '"db"."schema"."table"', + "database": "db_2", + "schema": "schema_2", + "name": "table_2", + } + model = Model(model_dict) + assert model.sql_table == '"db"."schema"."table"' - def test_sql_table_without_relation(self): - """ - If a relation is not present, then compose it - """ - model_dict = { - 'database': 'db_2', - 'schema': 'schema_2', - 'name': 'table_2' - } - model = Model(model_dict) - assert model.sql_table == '`db_2`.`schema_2`.`table_2`' + def test_sql_table_without_relation(self): + """ + If a relation is not present, then compose it + """ + model_dict = {"database": "db_2", "schema": "schema_2", "name": "table_2"} + model = Model(model_dict) + assert model.sql_table == "`db_2`.`schema_2`.`table_2`" - def test_sql_table_without_relation_with_alias(self): - """ - If a relation is not present and an alias is, - then compose it using that alias - """ - model_dict = { - 'database': 'db_2', - 'schema': 'schema_2', - 'name': 'table_2', - 'alias': 'alias_2' - } - model = Model(model_dict) - assert model.sql_table == '`db_2`.`schema_2`.`alias_2`' + def test_sql_table_without_relation_with_alias(self): + """ + If a relation is not present and an alias is, + then compose it using that alias + """ + model_dict = { + "database": "db_2", + "schema": "schema_2", + "name": "table_2", + "alias": "alias_2", + } + model = Model(model_dict) + assert model.sql_table == "`db_2`.`schema_2`.`alias_2`" - def test_detect_primary_key_no_columns(self): - """ - If a model has no columns with a 'primary key' - tag, then detect no primary keys - """ - model_dict = { - 'name': 'model', - 'columns': { - 'id': { - 'name': 'id', - 'data_type': 'numeric', - 'tags': [] - }, - 'status': { - 'name': 'status', - 'data_type': None, - 'tags': [] + def test_detect_primary_key_no_columns(self): + """ + If a model has no columns with a 'primary key' + tag, then detect no primary keys + """ + model_dict = { + "name": "model", + "columns": { + "id": {"name": "id", "data_type": "numeric", "tags": []}, + "status": {"name": "status", "data_type": None, "tags": []}, + }, } - } - } - model = Model(model_dict) - assert model.primary_key == None + model = Model(model_dict) + assert len(model.primary_key) == 0 - def test_detect_primary_key_one_column(self): - """ - If a model has one and only one column with a 'primary key' - tag, then use it as a primary key - """ - model_dict = { - 'name': 'model', - 'columns': { - 'id': { - 'name': 'id', - 'data_type': 'numeric', - 'tags': [ - 'primary_key' - ] - }, - 'status': { - 'name': 'status', - 'data_type': None, - 'tags': [] + def test_detect_primary_key_one_column(self): + """ + If a model has one and only one column with a 'primary key' + tag, then use it as a primary key + """ + model_dict = { + "name": "model", + "columns": { + "id": {"name": "id", "data_type": "numeric", "tags": ["primary_key"]}, + "status": {"name": "status", "data_type": None, "tags": []}, + }, } - } - } - model = Model(model_dict) - assert model.primary_key != None - assert model.primary_key.name == 'id' + model = Model(model_dict) + assert len(model.primary_key) == 1 + assert model.primary_key[0].name == "id" - def test_detect_primary_key_two_columns(self): - """ - If a model has more than one column with a 'primary_key' - tag, then raise an exception - """ - model_dict = { - 'name': 'model', - 'columns': { - 'id': { - 'name': 'id', - 'data_type': 'numeric', - 'tags': [ - 'primary_key' - ] - }, - 'status': { - 'name': 'status', - 'data_type': None, - 'tags': [ - 'primary_key' - ] + def test_detect_primary_key_two_columns(self): + """ + If a model has more than one column with a 'primary_key' + tag, then raise an exception + """ + model_dict = { + "name": "model", + "columns": { + "id": {"name": "id", "data_type": "numeric", "tags": ["primary_key"]}, + "status": { + "name": "status", + "data_type": "string", + "tags": ["primary_key"], + }, + }, } - } - } - model = Model(model_dict) - with raises(RuntimeError): - model.primary_key + model = Model(model_dict) + assert len(model.primary_key) == 2 + assert model.primary_key[0].name is not None + assert model.primary_key[1].name is not None - def test_as_cube(self): - model_dict = { - 'relation_name': '"db"."schema"."table"', - 'database': 'db_2', - 'schema': 'schema_2', - 'name': 'table_2', - 'description': '' - } - model = Model(model_dict) - assert model._as_cube() == { - 'name': 'table_2', - 'sql_table': '"db"."schema"."table"' - } + def test_as_cube(self): + model_dict = { + "relation_name": '"db"."schema"."table"', + "database": "db_2", + "schema": "schema_2", + "name": "table_2", + "description": "", + } + model = Model(model_dict) + assert model._as_cube() == { + "name": "table_2", + "sql_table": '"db"."schema"."table"', + } - def test_as_cube_render(self): - model_dict = { - 'relation_name': '"db"."schema"."table"', - 'database': 'db_2', - 'schema': 'schema_2', - 'name': 'table_2', - 'description': '' - } - model = Model(model_dict) - assert model.as_cube() == """name: table_2 + def test_as_cube_render(self): + model_dict = { + "relation_name": '"db"."schema"."table"', + "database": "db_2", + "schema": "schema_2", + "name": "table_2", + "description": "", + } + model = Model(model_dict) + assert ( + model.as_cube() + == """name: table_2 sql_table: '"db"."schema"."table"' """ + ) - def test_as_dimensions(self): - model_dict = { - 'name': 'model', - 'columns': { - 'id': { - 'name': 'id', - 'description': '', - 'meta': {}, - 'data_type': 'numeric', - 'tags': [] - }, - 'status': { - 'name': 'status', - 'description': '', - 'meta': {}, - 'data_type': None, - 'tags': [] + def test_as_dimensions(self): + model_dict = { + "name": "model", + "columns": { + "id": { + "name": "id", + "description": "", + "meta": {}, + "data_type": "numeric", + "tags": [], + }, + "status": { + "name": "status", + "description": "", + "meta": {}, + "data_type": None, + "tags": [], + }, + }, } - } - } - model = Model(model_dict) - assert model._as_dimensions() == [ - { - 'name': 'id', - 'sql': 'id', - 'type': 'number' - }, - { - 'name': 'status', - 'sql': 'status', - 'type': 'string' - } - ] + model = Model(model_dict) + assert model._as_dimensions() == [ + {"name": "id", "sql": "id", "type": "number"}, + {"name": "status", "sql": "status", "type": "string"}, + ] - def test_as_dimensions_with_primary_key(self): - model_dict = { - 'name': 'model', - 'columns': { - 'id': { - 'name': 'id', - 'description': '', - 'meta': {}, - 'data_type': 'numeric', - 'tags': [ - 'primary_key' - ] - }, - 'status': { - 'name': 'status', - 'description': '', - 'meta': {}, - 'data_type': None, - 'tags': [] + def test_as_dimensions_with_primary_key(self): + model_dict = { + "name": "model", + "columns": { + "id": { + "name": "id", + "description": "", + "meta": {}, + "data_type": "numeric", + "tags": ["primary_key"], + }, + "status": { + "name": "status", + "description": "", + "meta": {}, + "data_type": None, + "tags": [], + }, + }, } - } - } - model = Model(model_dict) - assert model._as_dimensions() == [ - { - 'name': 'id', - 'sql': 'id', - 'type': 'number', - 'primary_key': True - }, - { - 'name': 'status', - 'sql': 'status', - 'type': 'string' - } - ] + model = Model(model_dict) + assert model._as_dimensions() == [ + {"name": "id", "sql": "id", "type": "number", "primary_key": True}, + {"name": "status", "sql": "status", "type": "string"}, + ] - def test_as_dimensions_with_skipped_columns(self): - model_dict = { - 'name': 'model', - 'columns': { - 'id': { - 'name': 'id', - 'description': '', - 'meta': {}, - 'data_type': 'numeric', - 'tags': [] - }, - 'status': { - 'name': 'status', - 'description': '', - 'meta': {}, - 'data_type': None, - 'tags': [] + def test_as_dimensions_with_skipped_columns(self): + model_dict = { + "name": "model", + "columns": { + "id": { + "name": "id", + "description": "", + "meta": {}, + "data_type": "numeric", + "tags": [], + }, + "status": { + "name": "status", + "description": "", + "meta": {}, + "data_type": None, + "tags": [], + }, + }, } - } - } - model = Model(model_dict) - assert model._as_dimensions(skip=['id']) == [ - { - 'name': 'status', - 'sql': 'status', - 'type': 'string' - } - ] + model = Model(model_dict) + assert model._as_dimensions(skip=["id"]) == [ + {"name": "status", "sql": "status", "type": "string"} + ] + + def test_as_dimensions_render(self): + model_dict = { + "name": "model", + "columns": { + "id": { + "name": "id", + "description": "", + "meta": {}, + "data_type": "numeric", + "tags": ["primary_key"], + }, + "status": { + "name": "status", + "description": "", + "meta": {}, + "data_type": None, + "tags": [], + }, + }, + } + + model = Model(model_dict) + assert ( + model.as_dimensions() + == """- name: id + sql: id + type: number + primary_key: true + - name: status + sql: status + type: string + """ + ) - def test_as_dimensions_render(self): - model_dict = { - 'name': 'model', - 'columns': { - 'id': { - 'name': 'id', - 'description': '', - 'meta': {}, - 'data_type': 'numeric', - 'tags': [ - 'primary_key' - ] - }, - 'status': { - 'name': 'status', - 'description': '', - 'meta': {}, - 'data_type': None, - 'tags': [] + def test_as_dimensions_render_two_primary_keys(self): + model_dict = { + "name": "model", + "columns": { + "id": { + "name": "id", + "description": "", + "meta": {}, + "data_type": "numeric", + "tags": ["primary_key"], + }, + "status": { + "name": "status", + "description": "", + "meta": {}, + "data_type": None, + "tags": ["primary_key"], + }, + }, } - } - } - model = Model(model_dict) - assert model.as_dimensions() == """- name: id + model = Model(model_dict) + assert ( + model.as_dimensions() + == """- name: id sql: id type: number primary_key: true - name: status sql: status type: string + primary_key: true """ + ) - def test_as_dimensions_render_when_empty(self): - model_dict = { - 'name': 'model', - 'columns': {} - } + def test_as_dimensions_render_when_empty(self): + model_dict = {"name": "model", "columns": {}} - model = Model(model_dict) - assert model.as_dimensions() == '' \ No newline at end of file + model = Model(model_dict) + assert model.as_dimensions() == "" From ba8049ebc55c9b65264be2fdd2c23b93cadbda1a Mon Sep 17 00:00:00 2001 From: Paco Valdez Date: Wed, 7 May 2025 07:57:36 -0700 Subject: [PATCH 2/3] remove format edits --- tests/test_model.py | 511 ++++++++++++++++++++++++-------------------- 1 file changed, 280 insertions(+), 231 deletions(-) diff --git a/tests/test_model.py b/tests/test_model.py index fe6742e..60f086a 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -1,227 +1,276 @@ from pytest import raises from cube_dbt import Model - class TestModel: - def test_sql_table_with_relation(self): - """ - If a relation is present, then use it - """ - model_dict = { - "relation_name": '"db"."schema"."table"', - "database": "db_2", - "schema": "schema_2", - "name": "table_2", - } - model = Model(model_dict) - assert model.sql_table == '"db"."schema"."table"' + def test_sql_table_with_relation(self): + """ + If a relation is present, then use it + """ + model_dict = { + 'relation_name': '"db"."schema"."table"', + 'database': 'db_2', + 'schema': 'schema_2', + 'name': 'table_2' + } + model = Model(model_dict) + assert model.sql_table == '"db"."schema"."table"' - def test_sql_table_without_relation(self): - """ - If a relation is not present, then compose it - """ - model_dict = {"database": "db_2", "schema": "schema_2", "name": "table_2"} - model = Model(model_dict) - assert model.sql_table == "`db_2`.`schema_2`.`table_2`" + def test_sql_table_without_relation(self): + """ + If a relation is not present, then compose it + """ + model_dict = { + 'database': 'db_2', + 'schema': 'schema_2', + 'name': 'table_2' + } + model = Model(model_dict) + assert model.sql_table == '`db_2`.`schema_2`.`table_2`' - def test_sql_table_without_relation_with_alias(self): - """ - If a relation is not present and an alias is, - then compose it using that alias - """ - model_dict = { - "database": "db_2", - "schema": "schema_2", - "name": "table_2", - "alias": "alias_2", - } - model = Model(model_dict) - assert model.sql_table == "`db_2`.`schema_2`.`alias_2`" + def test_sql_table_without_relation_with_alias(self): + """ + If a relation is not present and an alias is, + then compose it using that alias + """ + model_dict = { + 'database': 'db_2', + 'schema': 'schema_2', + 'name': 'table_2', + 'alias': 'alias_2' + } + model = Model(model_dict) + assert model.sql_table == '`db_2`.`schema_2`.`alias_2`' - def test_detect_primary_key_no_columns(self): - """ - If a model has no columns with a 'primary key' - tag, then detect no primary keys - """ - model_dict = { - "name": "model", - "columns": { - "id": {"name": "id", "data_type": "numeric", "tags": []}, - "status": {"name": "status", "data_type": None, "tags": []}, - }, + def test_detect_primary_key_no_columns(self): + """ + If a model has no columns with a 'primary key' + tag, then detect no primary keys + """ + model_dict = { + 'name': 'model', + 'columns': { + 'id': { + 'name': 'id', + 'data_type': 'numeric', + 'tags': [] + }, + 'status': { + 'name': 'status', + 'data_type': None, + 'tags': [] } - model = Model(model_dict) - assert len(model.primary_key) == 0 + } + } + model = Model(model_dict) + assert len(model.primary_key) == 0 - def test_detect_primary_key_one_column(self): - """ - If a model has one and only one column with a 'primary key' - tag, then use it as a primary key - """ - model_dict = { - "name": "model", - "columns": { - "id": {"name": "id", "data_type": "numeric", "tags": ["primary_key"]}, - "status": {"name": "status", "data_type": None, "tags": []}, - }, + def test_detect_primary_key_one_column(self): + """ + If a model has one and only one column with a 'primary key' + tag, then use it as a primary key + """ + model_dict = { + 'name': 'model', + 'columns': { + 'id': { + 'name': 'id', + 'data_type': 'numeric', + 'tags': [ + 'primary_key' + ] + }, + 'status': { + 'name': 'status', + 'data_type': None, + 'tags': [] } - model = Model(model_dict) - assert len(model.primary_key) == 1 - assert model.primary_key[0].name == "id" + } + } + model = Model(model_dict) + assert len(model.primary_key) == 1 + assert model.primary_key[0].name == "id" - def test_detect_primary_key_two_columns(self): - """ - If a model has more than one column with a 'primary_key' - tag, then raise an exception - """ - model_dict = { - "name": "model", - "columns": { - "id": {"name": "id", "data_type": "numeric", "tags": ["primary_key"]}, - "status": { - "name": "status", - "data_type": "string", - "tags": ["primary_key"], - }, - }, + def test_detect_primary_key_two_columns(self): + """ + If a model has more than one column with a 'primary_key' + tag, then raise an exception + """ + model_dict = { + 'name': 'model', + 'columns': { + 'id': { + 'name': 'id', + 'data_type': 'numeric', + 'tags': [ + 'primary_key' + ] + }, + 'status': { + 'name': 'status', + 'data_type': None, + 'tags': [ + 'primary_key' + ] } - model = Model(model_dict) - assert len(model.primary_key) == 2 - assert model.primary_key[0].name is not None - assert model.primary_key[1].name is not None + } + } + model = Model(model_dict) + assert len(model.primary_key) == 2 + assert model.primary_key[0].name is not None + assert model.primary_key[1].name is not None - def test_as_cube(self): - model_dict = { - "relation_name": '"db"."schema"."table"', - "database": "db_2", - "schema": "schema_2", - "name": "table_2", - "description": "", - } - model = Model(model_dict) - assert model._as_cube() == { - "name": "table_2", - "sql_table": '"db"."schema"."table"', - } + def test_as_cube(self): + model_dict = { + 'relation_name': '"db"."schema"."table"', + 'database': 'db_2', + 'schema': 'schema_2', + 'name': 'table_2', + 'description': '' + } + model = Model(model_dict) + assert model._as_cube() == { + 'name': 'table_2', + 'sql_table': '"db"."schema"."table"' + } - def test_as_cube_render(self): - model_dict = { - "relation_name": '"db"."schema"."table"', - "database": "db_2", - "schema": "schema_2", - "name": "table_2", - "description": "", - } - model = Model(model_dict) - assert ( - model.as_cube() - == """name: table_2 + def test_as_cube_render(self): + model_dict = { + 'relation_name': '"db"."schema"."table"', + 'database': 'db_2', + 'schema': 'schema_2', + 'name': 'table_2', + 'description': '' + } + model = Model(model_dict) + assert model.as_cube() == """name: table_2 sql_table: '"db"."schema"."table"' """ - ) - def test_as_dimensions(self): - model_dict = { - "name": "model", - "columns": { - "id": { - "name": "id", - "description": "", - "meta": {}, - "data_type": "numeric", - "tags": [], - }, - "status": { - "name": "status", - "description": "", - "meta": {}, - "data_type": None, - "tags": [], - }, - }, + def test_as_dimensions(self): + model_dict = { + 'name': 'model', + 'columns': { + 'id': { + 'name': 'id', + 'description': '', + 'meta': {}, + 'data_type': 'numeric', + 'tags': [] + }, + 'status': { + 'name': 'status', + 'description': '', + 'meta': {}, + 'data_type': None, + 'tags': [] } - model = Model(model_dict) - assert model._as_dimensions() == [ - {"name": "id", "sql": "id", "type": "number"}, - {"name": "status", "sql": "status", "type": "string"}, - ] + } + } + model = Model(model_dict) + assert model._as_dimensions() == [ + { + 'name': 'id', + 'sql': 'id', + 'type': 'number' + }, + { + 'name': 'status', + 'sql': 'status', + 'type': 'string' + } + ] - def test_as_dimensions_with_primary_key(self): - model_dict = { - "name": "model", - "columns": { - "id": { - "name": "id", - "description": "", - "meta": {}, - "data_type": "numeric", - "tags": ["primary_key"], - }, - "status": { - "name": "status", - "description": "", - "meta": {}, - "data_type": None, - "tags": [], - }, - }, + def test_as_dimensions_with_primary_key(self): + model_dict = { + 'name': 'model', + 'columns': { + 'id': { + 'name': 'id', + 'description': '', + 'meta': {}, + 'data_type': 'numeric', + 'tags': [ + 'primary_key' + ] + }, + 'status': { + 'name': 'status', + 'description': '', + 'meta': {}, + 'data_type': None, + 'tags': [] } - model = Model(model_dict) - assert model._as_dimensions() == [ - {"name": "id", "sql": "id", "type": "number", "primary_key": True}, - {"name": "status", "sql": "status", "type": "string"}, - ] + } + } + model = Model(model_dict) + assert model._as_dimensions() == [ + { + 'name': 'id', + 'sql': 'id', + 'type': 'number', + 'primary_key': True + }, + { + 'name': 'status', + 'sql': 'status', + 'type': 'string' + } + ] - def test_as_dimensions_with_skipped_columns(self): - model_dict = { - "name": "model", - "columns": { - "id": { - "name": "id", - "description": "", - "meta": {}, - "data_type": "numeric", - "tags": [], - }, - "status": { - "name": "status", - "description": "", - "meta": {}, - "data_type": None, - "tags": [], - }, - }, + def test_as_dimensions_with_skipped_columns(self): + model_dict = { + 'name': 'model', + 'columns': { + 'id': { + 'name': 'id', + 'description': '', + 'meta': {}, + 'data_type': 'numeric', + 'tags': [] + }, + 'status': { + 'name': 'status', + 'description': '', + 'meta': {}, + 'data_type': None, + 'tags': [] } - model = Model(model_dict) - assert model._as_dimensions(skip=["id"]) == [ - {"name": "status", "sql": "status", "type": "string"} - ] + } + } + model = Model(model_dict) + assert model._as_dimensions(skip=['id']) == [ + { + 'name': 'status', + 'sql': 'status', + 'type': 'string' + } + ] - def test_as_dimensions_render(self): - model_dict = { - "name": "model", - "columns": { - "id": { - "name": "id", - "description": "", - "meta": {}, - "data_type": "numeric", - "tags": ["primary_key"], - }, - "status": { - "name": "status", - "description": "", - "meta": {}, - "data_type": None, - "tags": [], - }, - }, + def test_as_dimensions_render(self): + model_dict = { + 'name': 'model', + 'columns': { + 'id': { + 'name': 'id', + 'description': '', + 'meta': {}, + 'data_type': 'numeric', + 'tags': [ + 'primary_key' + ] + }, + 'status': { + 'name': 'status', + 'description': '', + 'meta': {}, + 'data_type': None, + 'tags': [] } + } + } - model = Model(model_dict) - assert ( - model.as_dimensions() - == """- name: id + model = Model(model_dict) + assert model.as_dimensions() == """- name: id sql: id type: number primary_key: true @@ -229,33 +278,39 @@ def test_as_dimensions_render(self): sql: status type: string """ - ) - def test_as_dimensions_render_two_primary_keys(self): - model_dict = { - "name": "model", - "columns": { - "id": { - "name": "id", - "description": "", - "meta": {}, - "data_type": "numeric", - "tags": ["primary_key"], - }, - "status": { - "name": "status", - "description": "", - "meta": {}, - "data_type": None, - "tags": ["primary_key"], - }, - }, - } + def test_as_dimensions_render_when_empty(self): + model_dict = { + 'name': 'model', + 'columns': {} + } + + model = Model(model_dict) + assert model.as_dimensions() == '' - model = Model(model_dict) - assert ( - model.as_dimensions() - == """- name: id + def test_as_dimensions_render_two_primary_keys(self): + model_dict = { + "name": "model", + "columns": { + "id": { + "name": "id", + "description": "", + "meta": {}, + "data_type": "numeric", + "tags": ["primary_key"], + }, + "status": { + "name": "status", + "description": "", + "meta": {}, + "data_type": None, + "tags": ["primary_key"], + }, + }, + } + model = Model(model_dict) + assert ( + model.as_dimensions() == """- name: id sql: id type: number primary_key: true @@ -264,10 +319,4 @@ def test_as_dimensions_render_two_primary_keys(self): type: string primary_key: true """ - ) - - def test_as_dimensions_render_when_empty(self): - model_dict = {"name": "model", "columns": {}} - - model = Model(model_dict) - assert model.as_dimensions() == "" + ) From c6d7734ce2dde0b00cbe1d993239e6a321086173 Mon Sep 17 00:00:00 2001 From: Paco Valdez Date: Mon, 12 May 2025 10:11:16 -0700 Subject: [PATCH 3/3] Add publish workflow --- .github/workflows/publish.yaml | 30 ++++++++++++++++++++++++++++++ pyproject.toml | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish.yaml diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..169ca8e --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,30 @@ +name: Upload Python Package to PyPI when a Release is Created + +on: + release: + types: [created] + +jobs: + pypi-publish: + name: Publish release to PyPI + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/weiser-ai + permissions: + id-token: write + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.x" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel + - name: Build package + run: | + python setup.py sdist bdist_wheel # Could also be python -m build + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index bc68c77..eb180bc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "cube_dbt" -version = "0.6.1" +version = "0.6.2" description = "dbt integration for Cube" authors = [ {name = "Artyom Keydunov", email = "artyom@cube.dev"},