diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e598ed17..c677d227 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/poetry.lock b/poetry.lock index 598112b6..8c74110f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -307,6 +307,20 @@ typing-extensions = ">=4.2.0" dotenv = ["python-dotenv (>=0.10.4)"] email = ["email-validator (>=1.0.3)"] +[[package]] +name = "pydocstyle" +version = "6.3.0" +description = "Python docstring style checker" +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +snowballstemmer = ">=2.2.0" + +[package.extras] +toml = ["tomli (>=1.2.3)"] + [[package]] name = "pygments" version = "2.14.0" @@ -664,7 +678,7 @@ test = ["black (>=22.3.0,<23.0.0)", "coverage (>=6.2,<7.0)", "isort (>=5.0.6,<6. [[package]] name = "types-pyyaml" -version = "6.0.12.6" +version = "6.0.12.7" description = "Typing stubs for PyYAML" category = "dev" optional = false @@ -701,7 +715,7 @@ python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" [[package]] name = "zipp" -version = "3.13.0" +version = "3.14.0" description = "Backport of pathlib-compatible object wrapper for zip files" category = "main" optional = false @@ -714,7 +728,7 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools" [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "e0347b018c8e0b45300639561036acde94c3e1056ca0f60bd653dbc3f215291f" +content-hash = "13652c77ff027bf3e82b5914e24a4657795416c769cd6fe04616d66dad947676" [metadata.files] alabaster = [ @@ -1196,6 +1210,10 @@ pydantic = [ {file = "pydantic-1.10.5-py3-none-any.whl", hash = "sha256:7c5b94d598c90f2f46b3a983ffb46ab806a67099d118ae0da7ef21a2a4033b28"}, {file = "pydantic-1.10.5.tar.gz", hash = "sha256:9e337ac83686645a46db0e825acceea8e02fca4062483f40e9ae178e8bd1103a"}, ] +pydocstyle = [ + {file = "pydocstyle-6.3.0-py3-none-any.whl", hash = "sha256:118762d452a49d6b05e194ef344a55822987a462831ade91ec5c06fd2169d019"}, + {file = "pydocstyle-6.3.0.tar.gz", hash = "sha256:7ce43f0c0ac87b07494eb9c0b462c0b73e6ff276807f204d6b53edc72b7e44e1"}, +] pygments = [ {file = "Pygments-2.14.0-py3-none-any.whl", hash = "sha256:fa7bd7bd2771287c0de303af8bfdfc731f51bd2c6a47ab69d117138893b82717"}, {file = "Pygments-2.14.0.tar.gz", hash = "sha256:b3ed06a9e8ac9a9aae5a6f5dbe78a8a58655d17b43b93c078f094ddc476ae297"}, @@ -1367,8 +1385,8 @@ typer = [ {file = "typer-0.7.0.tar.gz", hash = "sha256:ff797846578a9f2a201b53442aedeb543319466870fbe1c701eab66dd7681165"}, ] types-pyyaml = [ - {file = "types-PyYAML-6.0.12.6.tar.gz", hash = "sha256:24e76b938d58e68645271eeb149af6022d1da99788e481f959bd284b164f39a1"}, - {file = "types_PyYAML-6.0.12.6-py3-none-any.whl", hash = "sha256:77b74d0874482f2b42dd566b7277b0a220068595e0fb42689d0c0560f3d1ae9e"}, + {file = "types-PyYAML-6.0.12.7.tar.gz", hash = "sha256:ad40c99142b1812615bac08d5e240d35107a27ec285af501682c685957692f95"}, + {file = "types_PyYAML-6.0.12.7-py3-none-any.whl", hash = "sha256:91c64379a9ae88471a473d1ce0abf6a09c285700a297621b2177163d506584b8"}, ] typing-extensions = [ {file = "typing_extensions-4.5.0-py3-none-any.whl", hash = "sha256:fb33085c39dd998ac16d1431ebc293a8b3eedd00fd4a32de0ff79002c19511b4"}, @@ -1445,6 +1463,6 @@ wrapt = [ {file = "wrapt-1.14.1.tar.gz", hash = "sha256:380a85cf89e0e69b7cfbe2ea9f765f004ff419f34194018a6827ac0e3edfed4d"}, ] zipp = [ - {file = "zipp-3.13.0-py3-none-any.whl", hash = "sha256:e8b2a36ea17df80ffe9e2c4fda3f693c3dad6df1697d3cd3af232db680950b0b"}, - {file = "zipp-3.13.0.tar.gz", hash = "sha256:23f70e964bc11a34cef175bc90ba2914e1e4545ea1e3e2f67c079671883f9cb6"}, + {file = "zipp-3.14.0-py3-none-any.whl", hash = "sha256:188834565033387710d046e3fe96acfc9b5e86cbca7f39ff69cf21a4128198b7"}, + {file = "zipp-3.14.0.tar.gz", hash = "sha256:9e5421e176ef5ab4c0ad896624e87a7b2f07aca746c9b2aa305952800cb8eecb"}, ] diff --git a/pyproject.toml b/pyproject.toml index 3886a533..ff2bd0fb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"] diff --git a/sqlsynthgen/main.py b/sqlsynthgen/main.py index 803d4fbf..aadd2bbd 100644 --- a/sqlsynthgen/main.py +++ b/sqlsynthgen/main.py @@ -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 @@ -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) @@ -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. @@ -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.) diff --git a/sqlsynthgen/make.py b/sqlsynthgen/make.py index 941cbf84..580ec018 100644 --- a/sqlsynthgen/make.py +++ b/sqlsynthgen/make.py @@ -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: @@ -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. @@ -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)) @@ -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. diff --git a/sqlsynthgen/settings.py b/sqlsynthgen/settings.py index 8e8918d3..56e7cc26 100644 --- a/sqlsynthgen/settings.py +++ b/sqlsynthgen/settings.py @@ -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")