Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Python 3.10 to test matrix #177

Merged
merged 7 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion .github/scripts/integration-test-matrix.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = ({ context }) => {
const defaultPythonVersion = "3.8";
const supportedPythonVersions = ["3.7", "3.8", "3.9"];
const supportedPythonVersions = ["3.7", "3.8", "3.9", "3.10"];
const supportedAdapters = ["bigquery"];

// if PR, generate matrix based on files changed and PR labels
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.7, 3.8] # TODO: support unit testing for python 3.9 (https://github.com/dbt-labs/dbt/issues/3689)
python-version: ['3.7', '3.8', '3.9', '3.10']

env:
TOXENV: "unit"
Expand Down Expand Up @@ -173,7 +173,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.7, 3.8, 3.9]
python-version: ['3.7', '3.8', '3.9', '3.10']

steps:
- name: Set up Python ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ repos:
alias: flake8-check
stages: [manual]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.782
rev: v0.942
hooks:
- id: mypy
args: [--show-error-codes, --ignore-missing-imports]
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## dbt-bigquery 1.1.0 (Release TBD)
## dbt-bigquery 1.2.0 (Release TBD)
- Adding Python 3.10 testing and enabling mypy ([#177](https://github.com/dbt-labs/dbt-bigquery/pull/177))

## dbt-bigquery 1.1.0 (April 28, 2022)

## dbt-bigquery 1.1.0rc2 (April 20, 2022)

### Fixes
- Restore default behavior for query timeout. Set default `job_execution_timeout` to `None` by default. Keep 300 seconds as query timeout where previously used.
Expand Down
3 changes: 3 additions & 0 deletions dbt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)
Copy link
Contributor

@VersusFacit VersusFacit May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I've read changing path this way is uncommon. What's the reason here? Super curious about the use case. edit: Does it have to do with Gerda's comment by chance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had a convo in Slack here about it but the TLDR is that we reuse dbt namespace twice which confuses mypy. This helps just combine them for mypy to reference. In the long run, we should refactor the codebase to not have this issue

2 changes: 1 addition & 1 deletion dbt/adapters/bigquery/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def convert_text_type(cls, agate_table: agate.Table, col_idx: int) -> str:

@classmethod
def convert_number_type(cls, agate_table: agate.Table, col_idx: int) -> str:
decimals = agate_table.aggregate(agate.MaxPrecision(col_idx))
decimals = agate_table.aggregate(agate.MaxPrecision(col_idx)) # type: ignore[attr-defined]
return "float64" if decimals else "int64"

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ flake8
flaky
freezegun==1.1.0
ipdb
mypy==0.782
mypy==0.942
pip-tools
pre-commit
pytest
Expand Down
3 changes: 2 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[mypy]
mypy_path = ./third-party-stubs
mypy_path = third-party-stubs/
namespace_packages = True
exclude = third-party-stubs/*
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def _get_dbt_core_version():
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
],
python_requires=">=3.7",
)
8 changes: 8 additions & 0 deletions tests/integration/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import tempfile
import traceback
import unittest
import warnings
from contextlib import contextmanager
from datetime import datetime
from functools import wraps
Expand Down Expand Up @@ -230,6 +231,13 @@ def _generate_test_root_dir(self):
return normalize(tempfile.mkdtemp(prefix='dbt-int-test-'))

def setUp(self):
# Logbook warnings are ignored so we don't have to fork logbook to support python 3.10.
# This _only_ works for tests in `test/integration`.
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
module="logbook"
)
self.dbt_core_install_root = os.path.dirname(dbt.__file__)
log_manager.reset_handlers()
self.initial_dir = INITIAL_ROOT
Expand Down
89 changes: 89 additions & 0 deletions third-party-stubs/agate/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from collections.abc import Sequence

from typing import Any, Optional, Callable, Iterable, Dict, Union

from . import data_types as data_types
from .data_types import (
Text as Text,
Number as Number,
Boolean as Boolean,
DateTime as DateTime,
Date as Date,
TimeDelta as TimeDelta,
)

class MappedSequence(Sequence):
def __init__(self, values: Any, keys: Optional[Any] = ...) -> None: ...
def __unicode__(self): ...
def __getitem__(self, key: Any): ...
def __setitem__(self, key: Any, value: Any) -> None: ...
def __iter__(self): ...
def __len__(self): ...
def __eq__(self, other: Any): ...
def __ne__(self, other: Any): ...
def __contains__(self, value: Any): ...
def keys(self): ...
def values(self): ...
def items(self): ...
def get(self, key: Any, default: Optional[Any] = ...): ...
def dict(self): ...

class Row(MappedSequence): ...

class Table:
def __init__(
self,
rows: Any,
column_names: Optional[Any] = ...,
column_types: Optional[Any] = ...,
row_names: Optional[Any] = ...,
_is_fork: bool = ...,
) -> None: ...
def __len__(self): ...
def __iter__(self): ...
def __getitem__(self, key: Any): ...
@property
def column_types(self): ...
@property
def column_names(self): ...
@property
def row_names(self): ...
@property
def columns(self): ...
@property
def rows(self): ...
def print_csv(self, **kwargs: Any) -> None: ...
def print_json(self, **kwargs: Any) -> None: ...
def where(self, test: Callable[[Row], bool]) -> "Table": ...
def select(self, key: Union[Iterable[str], str]) -> "Table": ...
# these definitions are much narrower than what's actually accepted
@classmethod
def from_object(
cls, obj: Iterable[Dict[str, Any]], *, column_types: Optional["TypeTester"] = None
) -> "Table": ...
@classmethod
def from_csv(
cls, path: Iterable[str], *, column_types: Optional["TypeTester"] = None
) -> "Table": ...
@classmethod
def merge(cls, tables: Iterable["Table"]) -> "Table": ...
def rename(
self,
column_names: Optional[Iterable[str]] = None,
row_names: Optional[Any] = None,
slug_columns: bool = False,
slug_rows: bool = False,
**kwargs: Any,
) -> "Table": ...

class TypeTester:
def __init__(
self, force: Any = ..., limit: Optional[Any] = ..., types: Optional[Any] = ...
) -> None: ...
def run(self, rows: Any, column_names: Any): ...

class MaxPrecision:
def __init__(self, column_name: Any) -> None: ...

# this is not strictly true, but it's all we care about.
def aggregate(self, aggregations: MaxPrecision) -> int: ...
71 changes: 71 additions & 0 deletions third-party-stubs/agate/data_types.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from typing import Any, Optional

DEFAULT_NULL_VALUES: Any

class DataType:
null_values: Any = ...
def __init__(self, null_values: Any = ...) -> None: ...
def test(self, d: Any): ...
def cast(self, d: Any) -> None: ...
def csvify(self, d: Any): ...
def jsonify(self, d: Any): ...

DEFAULT_TRUE_VALUES: Any
DEFAULT_FALSE_VALUES: Any

class Boolean(DataType):
true_values: Any = ...
false_values: Any = ...
def __init__(
self, true_values: Any = ..., false_values: Any = ..., null_values: Any = ...
) -> None: ...
def cast(self, d: Any): ...
def jsonify(self, d: Any): ...

ZERO_DT: Any

class Date(DataType):
date_format: Any = ...
parser: Any = ...
def __init__(self, date_format: Optional[Any] = ..., **kwargs: Any) -> None: ...
def cast(self, d: Any): ...
def csvify(self, d: Any): ...
def jsonify(self, d: Any): ...

class DateTime(DataType):
datetime_format: Any = ...
timezone: Any = ...
def __init__(
self, datetime_format: Optional[Any] = ..., timezone: Optional[Any] = ..., **kwargs: Any
) -> None: ...
def cast(self, d: Any): ...
def csvify(self, d: Any): ...
def jsonify(self, d: Any): ...

DEFAULT_CURRENCY_SYMBOLS: Any
POSITIVE: Any
NEGATIVE: Any

class Number(DataType):
locale: Any = ...
currency_symbols: Any = ...
group_symbol: Any = ...
decimal_symbol: Any = ...
def __init__(
self,
locale: str = ...,
group_symbol: Optional[Any] = ...,
decimal_symbol: Optional[Any] = ...,
currency_symbols: Any = ...,
**kwargs: Any,
) -> None: ...
def cast(self, d: Any): ...
def jsonify(self, d: Any): ...

class TimeDelta(DataType):
def cast(self, d: Any): ...

class Text(DataType):
cast_nulls: Any = ...
def __init__(self, cast_nulls: bool = ..., **kwargs: Any) -> None: ...
def cast(self, d: Any): ...
1 change: 1 addition & 0 deletions third-party-stubs/requests/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from requests.exceptions import ConnectionError as ConnectionError
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[tox]
skipsdist = True
envlist = py37,py38,py39
envlist = py37,py38,py39,py310

[testenv:{unit,py37,py38,py39,py}]
[testenv:{unit,py37,py38,py39,py310,py}]
description = unit testing
skip_install = true
passenv = DBT_* PYTEST_ADDOPTS
Expand All @@ -11,7 +11,7 @@ deps =
-rdev-requirements.txt
-e.

[testenv:{integration,py37,py38,py39,py}-{bigquery}]
[testenv:{integration,py37,py38,py39,py310,py}-{bigquery}]
description = adapter plugin integration testing
skip_install = true
passenv = DBT_* BIGQUERY_TEST_* PYTEST_ADDOPTS
Expand Down