Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ repos:
entry: poetry run pylint
language: system
types: ['python']
- id: pydocstyle
name: pydocstyle
entry: poetry run pydocstyle
language: system
types: ['python']
exclude: (?x)(
tests/|
docs/
)
- id: mypy
name: mypy
entry: poetry run mypy --follow-imports=silent
Expand Down
32 changes: 25 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mypy = "^0.991"
types-pyyaml = "^6.0.12.4"
python-docs-theme = "^2022.1"
sphinx-rtd-theme = "^1.1.1"
pydocstyle = "^6.3.0"

[build-system]
requires = ["poetry-core"]
Expand Down
8 changes: 4 additions & 4 deletions sqlsynthgen/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


def import_file(file_path: str) -> ModuleType:
"""Import a file
"""Import a file.

This utility function returns
the file at file_path as a module
Expand All @@ -29,7 +29,6 @@ def import_file(file_path: str) -> ModuleType:
Returns:
ModuleType
"""

file_path_path = Path(file_path)
module_path = ".".join(file_path_path.parts[:-1] + (file_path_path.stem,))
return import_module(module_path)
Expand All @@ -48,7 +47,8 @@ def create_data(
ssg_file: str = typer.Argument(...),
num_rows: int = typer.Argument(...),
) -> None:
"""Populate schema with synthetic data
"""Populate schema with synthetic data.

This CLI command generates synthetic data for
Python table structures, and inserts these rows
into a destination schema.
Expand Down Expand Up @@ -89,7 +89,7 @@ def create_vocab(ssg_file: str = typer.Argument(...)) -> None:

@app.command()
def create_tables(orm_file: str = typer.Argument(...)) -> None:
"""Create schema from Python classes
"""Create schema from Python classes.

This CLI command creates Postgresql schema using object relational model
declared as Python tables. (eg.)
Expand Down
12 changes: 4 additions & 8 deletions sqlsynthgen/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ def _orm_class_from_table_name(tables_module: Any, full_name: str) -> Optional[A


def _add_custom_generators(content: str, table_config: dict) -> tuple[str, list[str]]:
"""Add to the generators file, written in the string `content`, the custom
generators for the given table.
"""
"""Append the custom generators to content, for the given table."""
generators_config = table_config.get("custom_generators", {})
columns_covered = []
for gen_conf in generators_config:
Expand All @@ -82,9 +80,7 @@ def _add_custom_generators(content: str, table_config: dict) -> tuple[str, list[


def _add_default_generator(content: str, tables_module: ModuleType, column: Any) -> str:
"""Add to the generator file `content` a default generator for the given column,
determined by the column's type.
"""
"""Append a default generator to content, for the given column."""
content += INDENTATION * 2
# If it's a primary key column, we presume that primary keys are populated
# automatically.
Expand Down Expand Up @@ -142,7 +138,7 @@ def _add_generator_for_table(


def _download_table(table: Any, engine: Any) -> None:
"""Download a table and store it as a .csv file"""
"""Download a table and store it as a .csv file."""
stmt = select([table])
with engine.connect() as conn:
result = list(conn.execute(stmt))
Expand All @@ -158,7 +154,7 @@ def _download_table(table: Any, engine: Any) -> None:
def make_generators_from_tables(
tables_module: ModuleType, generator_config: dict
) -> str:
"""Creates sqlsynthgen generator classes from a sqlacodegen-generated file.
"""Create sqlsynthgen generator classes from a sqlacodegen-generated file.

Args:
tables_module: A sqlacodegen-generated module.
Expand Down
1 change: 0 additions & 1 deletion sqlsynthgen/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def validate_dst_postgres_dsn(cls, _: Optional[PostgresDsn], values: Any) -> str
@staticmethod
def check_postgres_dsn(_: Optional[PostgresDsn], values: Any, prefix: str) -> str:
"""Build a DSN string from the host, db name, port, username and password."""

# We want to build the Data Source Name ourselves so none should be provided
if _:
raise ValueError("postgres_dsn should not be provided")
Expand Down