Skip to content

Commit

Permalink
fix flake8 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
xnuinside committed May 12, 2024
1 parent 37d77e1 commit 960c3ad
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion omymodels/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 2 additions & 3 deletions omymodels/from_ddl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion omymodels/models/gino/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion omymodels/models/sqlalchemy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion omymodels/models/sqlalchemy_core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 10 additions & 6 deletions omymodels/models/sqlmodel/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,28 +130,32 @@ 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
if table.indexes or table.alter or table.checks or not schema_global:
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"
Expand Down
7 changes: 3 additions & 4 deletions one.ddl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
CREATE TABLE qwe (
id integer NOT NULL,
name character varying(255),
);
CREATE TABLE `option` (
FIELD1 VARCHAR(256),
) ;
6 changes: 2 additions & 4 deletions tests/functional/generator/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/generator/test_sqlmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 960c3ad

Please sign in to comment.