diff --git a/.flake8 b/.flake8 deleted file mode 100644 index b08ffcd53..000000000 --- a/.flake8 +++ /dev/null @@ -1,16 +0,0 @@ -[flake8] -select = - E - W - F -ignore = - # makes Flake8 work like black - W503, - W504, - # makes Flake8 work like black - E203, - E741, - E501, -exclude = test -per-file-ignores = - */__init__.py: F401 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c361cb987..389f55a88 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -58,7 +58,6 @@ jobs: python -m pip install -r dev-requirements.txt python -m pip --version pre-commit --version - mypy --version - name: pre-commit hooks run: pre-commit run --all-files --show-diff-on-failure diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b89d0df27..ae249943d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,67 +1,55 @@ -# For more on configuring pre-commit hooks (see https://pre-commit.com/) - -# Force all unspecified python hooks to run python 3.8 default_language_version: - python: python3 + python: python3 repos: -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 - hooks: - - id: check-yaml - args: [--unsafe] - - id: check-json - - id: end-of-file-fixer - - id: trailing-whitespace - - id: check-case-conflict -- repo: https://github.com/dbt-labs/pre-commit-hooks - rev: v0.1.0a1 - hooks: - - id: dbt-core-in-adapters-check -- repo: https://github.com/psf/black - rev: 23.1.0 - hooks: - - id: black - additional_dependencies: ['click~=8.1'] - args: - - "--line-length=99" - - "--target-version=py38" - - id: black - alias: black-check - stages: [manual] - additional_dependencies: ['click~=8.1'] - args: - - "--line-length=99" - - "--target-version=py38" - - "--check" - - "--diff" -- repo: https://github.com/pycqa/flake8 - rev: 6.0.0 - hooks: - - id: flake8 - - id: flake8 - alias: flake8-check - stages: [manual] -- repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.1.1 - hooks: - - id: mypy - # N.B.: Mypy is... a bit fragile. - # - # By using `language: system` we run this hook in the local - # environment instead of a pre-commit isolated one. This is needed - # to ensure mypy correctly parses the project. +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: check-yaml + args: [--unsafe] + - id: check-json + - id: end-of-file-fixer + - id: trailing-whitespace + - id: check-case-conflict + +- repo: https://github.com/dbt-labs/pre-commit-hooks + rev: v0.1.0a1 + hooks: + - id: dbt-core-in-adapters-check + +- repo: https://github.com/psf/black + rev: 24.4.0 + hooks: + - id: black + args: + - --line-length=99 + - --target-version=py38 + - --target-version=py39 + - --target-version=py310 + - --target-version=py311 + +- repo: https://github.com/pycqa/flake8 + rev: 7.0.0 + hooks: + - id: flake8 + exclude: tests/ + args: + - --max-line-length=99 + - --select=E,F,W + - --ignore=E203,E501,E741,W503,W504 + - --per-file-ignores=*/__init__.py:F401 + additional_dependencies: [flaky] - # It may cause trouble in that it adds environmental variables out - # of our control to the mix. Unfortunately, there's nothing we can - # do about per pre-commit's author. - # See https://github.com/pre-commit/pre-commit/issues/730 for details. - args: [--show-error-codes, --ignore-missing-imports, --explicit-package-bases] - files: ^dbt/adapters/.* - language: system - - id: mypy - alias: mypy-check - stages: [manual] - args: [--show-error-codes, --pretty, --ignore-missing-imports, --explicit-package-bases] - files: ^dbt/adapters - language: system +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.9.0 + hooks: + - id: mypy + args: + - --show-error-codes + - --pretty + - --ignore-missing-imports + - --explicit-package-bases + files: ^dbt/adapters + additional_dependencies: + - types-pytz + - types-requests diff --git a/dbt/adapters/redshift/connections.py b/dbt/adapters/redshift/connections.py index cc58c02a6..b890127c6 100644 --- a/dbt/adapters/redshift/connections.py +++ b/dbt/adapters/redshift/connections.py @@ -50,7 +50,7 @@ class UserSSLMode(StrEnum): @classmethod def default(cls) -> "UserSSLMode": # default for `psycopg2`, which aligns with dbt-redshift 1.4 and provides backwards compatibility - return cls.prefer + return cls("prefer") class RedshiftSSLMode(StrEnum): @@ -60,11 +60,11 @@ class RedshiftSSLMode(StrEnum): SSL_MODE_TRANSLATION = { UserSSLMode.disable: None, - UserSSLMode.allow: RedshiftSSLMode.verify_ca, - UserSSLMode.prefer: RedshiftSSLMode.verify_ca, - UserSSLMode.require: RedshiftSSLMode.verify_ca, - UserSSLMode.verify_ca: RedshiftSSLMode.verify_ca, - UserSSLMode.verify_full: RedshiftSSLMode.verify_full, + UserSSLMode.allow: RedshiftSSLMode("verify-ca"), + UserSSLMode.prefer: RedshiftSSLMode("verify-ca"), + UserSSLMode.require: RedshiftSSLMode("verify-ca"), + UserSSLMode.verify_ca: RedshiftSSLMode("verify-ca"), + UserSSLMode.verify_full: RedshiftSSLMode("verify-full"), } diff --git a/dbt/adapters/redshift/relation_configs/dist.py b/dbt/adapters/redshift/relation_configs/dist.py index c41eda578..0104d8db4 100644 --- a/dbt/adapters/redshift/relation_configs/dist.py +++ b/dbt/adapters/redshift/relation_configs/dist.py @@ -24,7 +24,7 @@ class RedshiftDistStyle(StrEnum): @classmethod def default(cls) -> "RedshiftDistStyle": - return cls.auto + return cls("auto") @dataclass(frozen=True, eq=True, unsafe_hash=True) @@ -103,7 +103,7 @@ def parse_relation_config(cls, relation_config: RelationConfig) -> dict: config = {"diststyle": diststyle} else: - config = {"diststyle": RedshiftDistStyle.key.value, "distkey": dist} + config = {"diststyle": RedshiftDistStyle.key.value, "distkey": dist} # type: ignore return config diff --git a/dbt/adapters/redshift/relation_configs/materialized_view.py b/dbt/adapters/redshift/relation_configs/materialized_view.py index 05f4b170d..f6d93754e 100644 --- a/dbt/adapters/redshift/relation_configs/materialized_view.py +++ b/dbt/adapters/redshift/relation_configs/materialized_view.py @@ -57,7 +57,7 @@ class RedshiftMaterializedViewConfig(RedshiftRelationConfigBase, RelationConfigV database_name: str query: str backup: bool = field(default=True, compare=False, hash=False) - dist: RedshiftDistConfig = RedshiftDistConfig(diststyle=RedshiftDistStyle.even) + dist: RedshiftDistConfig = RedshiftDistConfig(diststyle=RedshiftDistStyle("even")) sort: RedshiftSortConfig = RedshiftSortConfig() autorefresh: bool = False diff --git a/dbt/adapters/redshift/relation_configs/sort.py b/dbt/adapters/redshift/relation_configs/sort.py index e44784c2f..91152615e 100644 --- a/dbt/adapters/redshift/relation_configs/sort.py +++ b/dbt/adapters/redshift/relation_configs/sort.py @@ -23,11 +23,11 @@ class RedshiftSortStyle(StrEnum): @classmethod def default(cls) -> "RedshiftSortStyle": - return cls.auto + return cls("auto") @classmethod def default_with_columns(cls) -> "RedshiftSortStyle": - return cls.compound + return cls("compound") @dataclass(frozen=True, eq=True, unsafe_hash=True) diff --git a/dev-requirements.txt b/dev-requirements.txt index 85edead99..d02863ae0 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -5,28 +5,22 @@ git+https://github.com/dbt-labs/dbt-common.git git+https://github.com/dbt-labs/dbt-core.git#subdirectory=core git+https://github.com/dbt-labs/dbt-postgres.git -# if version 1.x or greater -> pin to major version -# if version 0.x -> pin to minor -black>=24.3 -bumpversion~=0.6.0 -click~=8.1 +# dev +ipdb~=0.13.13 +pre-commit==3.7.0;python_version >="3.9" +pre-commit==3.5.0;python_version <"3.9" + +# test ddtrace==2.3.0 -flake8~=6.1 -flaky~=3.7 freezegun~=1.3 -ipdb~=0.13.13 -mypy==1.7.1 # patch updates have historically introduced breaking changes -pip-tools~=7.3 -pre-commit~=3.5 -pre-commit-hooks~=4.5 pytest~=7.4 pytest-csv~=3.0 pytest-dotenv~=0.5.2 pytest-logbook~=1.2 pytest-xdist~=3.5 -pytz~=2023.3 tox~=4.11 -types-pytz~=2023.3 -types-requests~=2.31 + +# build +bumpversion~=0.6.0 twine~=4.0 wheel~=0.42 diff --git a/mypy.ini b/mypy.ini deleted file mode 100644 index b6e603581..000000000 --- a/mypy.ini +++ /dev/null @@ -1,2 +0,0 @@ -[mypy] -namespace_packages = True diff --git a/tests/unit/relation_configs/test_materialized_view.py b/tests/unit/relation_configs/test_materialized_view.py index 5e454fe5e..8e4f6ca3e 100644 --- a/tests/unit/relation_configs/test_materialized_view.py +++ b/tests/unit/relation_configs/test_materialized_view.py @@ -14,8 +14,8 @@ def test_redshift_materialized_view_config_handles_all_valid_bools(bool_value): query="select * from sometable", ) model_node = Mock() - model_node.config.extra.get = ( - lambda x, y=None: bool_value if x in ["auto_refresh", "backup"] else "someDistValue" + model_node.config.extra.get = lambda x, y=None: ( + bool_value if x in ["auto_refresh", "backup"] else "someDistValue" ) config_dict = config.parse_relation_config(model_node) assert isinstance(config_dict["autorefresh"], bool) @@ -33,8 +33,8 @@ def test_redshift_materialized_view_config_throws_expected_exception_with_invali query="select * from sometable", ) model_node = Mock() - model_node.config.extra.get = ( - lambda x, y=None: bool_value if x in ["auto_refresh", "backup"] else "someDistValue" + model_node.config.extra.get = lambda x, y=None: ( + bool_value if x in ["auto_refresh", "backup"] else "someDistValue" ) with pytest.raises(TypeError): config.parse_relation_config(model_node) @@ -48,8 +48,8 @@ def test_redshift_materialized_view_config_throws_expected_exception_with_invali query="select * from sometable", ) model_node = Mock() - model_node.config.extra.get = ( - lambda x, y=None: "notABool" if x in ["auto_refresh", "backup"] else "someDistValue" + model_node.config.extra.get = lambda x, y=None: ( + "notABool" if x in ["auto_refresh", "backup"] else "someDistValue" ) with pytest.raises(ValueError): config.parse_relation_config(model_node) diff --git a/tests/unit/utils.py b/tests/unit/utils.py index 3fc1d7ec6..4de03ec80 100644 --- a/tests/unit/utils.py +++ b/tests/unit/utils.py @@ -2,6 +2,7 @@ Note that all imports should be inside the functions to avoid import/mocking issues. """ + import string import os from unittest import mock