From 960c3adc2b5913b208601cad38bb5adb0ff7523e Mon Sep 17 00:00:00 2001 From: Iuliia Volkova Date: Sun, 12 May 2024 15:07:45 +0300 Subject: [PATCH] fix flake8 issues --- omymodels/cli.py | 2 +- omymodels/from_ddl.py | 5 ++--- omymodels/models/gino/core.py | 4 +++- omymodels/models/sqlalchemy/core.py | 4 +++- omymodels/models/sqlalchemy_core/core.py | 4 +++- omymodels/models/sqlmodel/core.py | 16 ++++++++++------ one.ddl | 7 +++---- tests/functional/generator/_models.py | 6 ++---- tests/functional/generator/test_sqlmodel.py | 2 +- 9 files changed, 28 insertions(+), 22 deletions(-) diff --git a/omymodels/cli.py b/omymodels/cli.py index 611369a..82fbcdd 100644 --- a/omymodels/cli.py +++ b/omymodels/cli.py @@ -14,7 +14,7 @@ def version(**kwargs): def cli(): omm_cli = argparse.ArgumentParser( description="O! My Models. " - "Create SQLModels, SQLAlchemy, GinoORM and other models from SQL DDL or another models" + "Create SQLModels, SQLAlchemy, GinoORM and other models from SQL DDL or another models" ) omm_cli.add_argument( diff --git a/omymodels/from_ddl.py b/omymodels/from_ddl.py index a5285a8..8db44a5 100644 --- a/omymodels/from_ddl.py +++ b/omymodels/from_ddl.py @@ -154,9 +154,8 @@ def generate_models_file( defaults_off=defaults_off, ) header += generator.create_header( - data["tables"], - schema=schema_global, - models_str=models_str) + data["tables"], schema=schema_global, models_str=models_str + ) else: models_type = "enum" output = render_jinja2_template(models_type, models_str, header) diff --git a/omymodels/models/gino/core.py b/omymodels/models/gino/core.py index b47e779..281c873 100644 --- a/omymodels/models/gino/core.py +++ b/omymodels/models/gino/core.py @@ -59,7 +59,9 @@ def generate_model( # create sequence return model - def create_header(self, tables: List[Dict], schema: bool = False, *args, **kwargs) -> str: + def create_header( + self, tables: List[Dict], schema: bool = False, *args, **kwargs + ) -> str: """header of the file - imports & gino init""" header = "" if "func" in self.state: diff --git a/omymodels/models/sqlalchemy/core.py b/omymodels/models/sqlalchemy/core.py index 891299c..1c01f15 100644 --- a/omymodels/models/sqlalchemy/core.py +++ b/omymodels/models/sqlalchemy/core.py @@ -64,7 +64,9 @@ def generate_model( model = logic.add_table_args(self, model, table, schema_global) return model - def create_header(self, tables: List[Dict], schema: bool = False, *args, **kwargs ) -> str: + def create_header( + self, tables: List[Dict], schema: bool = False, *args, **kwargs + ) -> str: """header of the file - imports & sqlalchemy init""" header = "" if "func" in self.state: diff --git a/omymodels/models/sqlalchemy_core/core.py b/omymodels/models/sqlalchemy_core/core.py index a13e32c..3f2c365 100644 --- a/omymodels/models/sqlalchemy_core/core.py +++ b/omymodels/models/sqlalchemy_core/core.py @@ -234,7 +234,9 @@ def generate_model(self, data: Dict, *args, **kwargs) -> str: model += index return model - def create_header(self, tables: List[Dict], schema: bool = False, *args, **kwargs ) -> str: + def create_header( + self, tables: List[Dict], schema: bool = False, *args, **kwargs + ) -> str: """header of the file - imports & sqlalchemy init""" header = "" if "func" in self.state: diff --git a/omymodels/models/sqlmodel/core.py b/omymodels/models/sqlmodel/core.py index c0bb7b1..f4710f7 100644 --- a/omymodels/models/sqlmodel/core.py +++ b/omymodels/models/sqlmodel/core.py @@ -130,17 +130,16 @@ def generate_model( if column.nullable or column.name in table.primary_key: pydantic_type_str = f"Optional[{pydantic_type_str}]" col_str = st.column_template.format( - column_name=column.name.replace(" ", "_"), - column_type=pydantic_type_str + column_name=column.name.replace(" ", "_"), column_type=pydantic_type_str ) attrs_col_str = logic.setup_column_attributes( - column, table.primary_key, '', table, schema_global, st, self + column, table.primary_key, "", table, schema_global, st, self ) if column_type["sa"]: sa_type = types.add_size_to_orm_column(column_type["sa"], column) attrs_col_str += st.sa_type.format(satype=sa_type) if attrs_col_str: - attrs_col_str = attrs_col_str.replace(',', '', 1).strip() + attrs_col_str = attrs_col_str.replace(",", "", 1).strip() col_str += st.field_template.format(attr_data=attrs_col_str) col_str += "\n" model += col_str @@ -148,10 +147,15 @@ def generate_model( model = self.add_table_args(model, table, schema_global) return model - def create_header(self, tables: List[Dict], models_str: str, schema: bool = False, ) -> str: + def create_header( + self, + tables: List[Dict], + models_str: str, + schema: bool = False, + ) -> str: """header of the file - imports & sqlalchemy init""" header = "" - if 'sa.' in models_str: + if "sa." in models_str: header += st.sqlalchemy_import # Do we always need this import? if "func" in self.state: header += st.sql_alchemy_func_import + "\n" diff --git a/one.ddl b/one.ddl index 7e17c71..ded5bca 100644 --- a/one.ddl +++ b/one.ddl @@ -1,4 +1,3 @@ -CREATE TABLE qwe ( - id integer NOT NULL, - name character varying(255), -); +CREATE TABLE `option` ( + FIELD1 VARCHAR(256), +) ; \ No newline at end of file diff --git a/tests/functional/generator/_models.py b/tests/functional/generator/_models.py index 2279dc4..42bac40 100644 --- a/tests/functional/generator/_models.py +++ b/tests/functional/generator/_models.py @@ -4,8 +4,7 @@ class Users(db.Model): - - __tablename__ = 'users' + __tablename__ = "users" id = db.Column(db.Integer(), autoincrement=True, primary_key=True) name = db.Column(db.String()) @@ -16,8 +15,7 @@ class Users(db.Model): class Languages(db.Model): - - __tablename__ = 'languages' + __tablename__ = "languages" id = db.Column(db.Integer(), primary_key=True) code = db.Column(db.String(2), nullable=False) diff --git a/tests/functional/generator/test_sqlmodel.py b/tests/functional/generator/test_sqlmodel.py index 65d0441..32b0e48 100644 --- a/tests/functional/generator/test_sqlmodel.py +++ b/tests/functional/generator/test_sqlmodel.py @@ -364,7 +364,7 @@ def test_sqlmodel_varying(): name character varying(255), ); """ - result = create_models(ddl, models_type='sqlmodel')['code'] + result = create_models(ddl, models_type="sqlmodel")["code"] expected = """import datetime import decimal from typing import Optional