Skip to content

Commit

Permalink
[Backport 1.7.latest] Make dbt-core compatible with Python 3.12 (#9673)
Browse files Browse the repository at this point in the history
  • Loading branch information
aranke authored Feb 26, 2024
1 parent 0a6d0c1 commit ffcd9e7
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20240221-145058.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Make dbt-core compatible with Python 3.12
time: 2024-02-21T14:50:58.983559Z
custom:
Author: l1xnan aranke
Issue: "9007"
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]

env:
TOXENV: "unit"
Expand Down Expand Up @@ -157,7 +157,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
os: [ubuntu-20.04]
split-group: ${{ fromJson(needs.integration-metadata.outputs.split-groups) }}
include: ${{ fromJson(needs.integration-metadata.outputs.include) }}
Expand Down
4 changes: 1 addition & 3 deletions core/dbt/task/test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from distutils.util import strtobool

from dataclasses import dataclass
from dbt.utils import _coerce_decimal
from dbt.utils import _coerce_decimal, strtobool
from dbt.events.format import pluralize
from dbt.dataclass_schema import dbtClassMixin
import threading
Expand Down
18 changes: 18 additions & 0 deletions core/dbt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,3 +692,21 @@ def cast_dict_to_dict_of_strings(dct):
for k, v in dct.items():
new_dct[str(k)] = str(v)
return new_dct


# Taken from https://github.com/python/cpython/blob/3.11/Lib/distutils/util.py
# This is a copy of the function from distutils.util, which was removed in Python 3.12.
def strtobool(val: str) -> bool:
"""Convert a string representation of truth to True or False.
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
'val' is anything else.
"""
val = val.lower()
if val in ("y", "yes", "t", "true", "on", "1"):
return True
elif val in ("n", "no", "f", "false", "off", "0"):
return False
else:
raise ValueError("invalid truth value %r" % (val,))
1 change: 1 addition & 0 deletions core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
python_requires=">=3.8",
)
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ env_files =
testpaths =
tests/functional
tests/unit
pythonpath = core plugins/postgres
26 changes: 19 additions & 7 deletions tests/unit/test_plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,25 @@ def test_get_nodes(self, tracking, get_nodes_plugins):
nodes = pm.get_nodes()

assert len(nodes.models) == 2
assert tracking.track_plugin_get_nodes.called_once_with(
{
"plugin_name": get_nodes_plugins[0].name,
"num_model_nodes": 2,
"num_model_packages": 1,
}
)

expected_calls = [
mock.call(
{
"plugin_name": get_nodes_plugins[0].name,
"num_model_nodes": 1,
"num_model_packages": 1,
}
),
mock.call(
{
"plugin_name": get_nodes_plugins[1].name,
"num_model_nodes": 1,
"num_model_packages": 1,
}
),
]

tracking.track_plugin_get_nodes.assert_has_calls(expected_calls)

def test_get_manifest_artifact(self, get_artifacts_plugins):
pm = PluginManager(plugins=get_artifacts_plugins)
Expand Down

0 comments on commit ffcd9e7

Please sign in to comment.