forked from dbt-labs/dbt-redshift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CT-1524 - Add support for python 3.11 (dbt-labs#236)
* added python 3.11 support * added change log for python 3.11 support * added python 3.11 support in docs * updated `setup.py` * replaced regular expressions with direct parsing with `exec()` for version * replaced os.path with pathlib * made `setup.py` functions private * decomposed the dbt-redshift > dbt-core function to make it clear that we're pinning the plugin to dbt-core at the minor * pinned all dependencies to the minor version * added `pip install -e .` to `make dev` so that packages in `setup.py` get picked up as well, namely boto3 * readability updates * added comments for clarity * fixed typos in comments * fixed white space convention * general cleanup * removed file because it did nothing; it contained a test that always passes
- Loading branch information
1 parent
ac04793
commit fb07c02
Showing
14 changed files
with
138 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
kind: Dependencies | ||
body: Add support for python 3.11 | ||
time: 2022-12-09T23:39:05.296196-05:00 | ||
custom: | ||
Author: mikealfare | ||
Issue: "225" | ||
PR: "236" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,89 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
import re | ||
|
||
# require python 3.7 or newer | ||
if sys.version_info < (3, 7): | ||
print("Error: dbt does not support this version of Python.") | ||
print("Please upgrade to Python 3.7 or higher.") | ||
sys.exit(1) | ||
|
||
|
||
# require version of setuptools that supports find_namespace_packages | ||
from setuptools import setup | ||
|
||
try: | ||
from setuptools import find_namespace_packages | ||
except ImportError: | ||
# the user has a downlevel version of setuptools. | ||
print("Error: dbt requires setuptools v40.1.0 or higher.") | ||
print('Please upgrade setuptools with "pip install --upgrade setuptools" ' "and try again") | ||
print('Please upgrade setuptools with "pip install --upgrade setuptools" and try again') | ||
sys.exit(1) | ||
|
||
|
||
# pull long description from README | ||
this_directory = os.path.abspath(os.path.dirname(__file__)) | ||
with open(os.path.join(this_directory, "README.md")) as f: | ||
long_description = f.read() | ||
from pathlib import Path | ||
from setuptools import setup | ||
|
||
|
||
# pull the long description from the README | ||
README = Path(__file__).parent / "README.md" | ||
|
||
|
||
# used for this adapter's version and in determining the compatible dbt-core version | ||
VERSION = Path(__file__).parent / "dbt/adapters/redshift/__version__.py" | ||
|
||
|
||
def _plugin_version() -> str: | ||
""" | ||
Pull the package version from the main package version file | ||
""" | ||
attributes = {} | ||
exec(VERSION.read_text(), attributes) | ||
return attributes["version"] | ||
|
||
|
||
def _core_patch(plugin_patch: str): | ||
""" | ||
Determines the compatible dbt-core patch given this plugin's patch | ||
Args: | ||
plugin_patch: the version patch of this plugin | ||
""" | ||
pre_release_phase = "".join([i for i in plugin_patch if not i.isdigit()]) | ||
if pre_release_phase: | ||
if pre_release_phase not in ["a", "b", "rc"]: | ||
raise ValueError(f"Invalid prerelease patch: {plugin_patch}") | ||
return f"0{pre_release_phase}1" | ||
return "0" | ||
|
||
|
||
# get this package's version from dbt/adapters/<name>/__version__.py | ||
def _get_plugin_version_dict(): | ||
_version_path = os.path.join(this_directory, "dbt", "adapters", "redshift", "__version__.py") | ||
_semver = r"""(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)""" | ||
_pre = r"""((?P<prekind>a|b|rc)(?P<pre>\d+))?""" | ||
_version_pattern = fr"""version\s*=\s*["']{_semver}{_pre}["']""" | ||
with open(_version_path) as f: | ||
match = re.search(_version_pattern, f.read().strip()) | ||
if match is None: | ||
raise ValueError(f"invalid version at {_version_path}") | ||
return match.groupdict() | ||
# require a compatible minor version (~=) and prerelease if this is a prerelease | ||
def _core_version(plugin_version: str = _plugin_version()) -> str: | ||
""" | ||
Determine the compatible dbt-core version give this plugin's version. | ||
We assume that the plugin must agree with `dbt-core` down to the minor version. | ||
# require a compatible minor version (~=), prerelease if this is a prerelease | ||
def _get_dbt_core_version(): | ||
parts = _get_plugin_version_dict() | ||
minor = "{major}.{minor}.0".format(**parts) | ||
pre = parts["prekind"] + "1" if parts["prekind"] else "" | ||
return f"{minor}{pre}" | ||
Args: | ||
plugin_version: the version of this plugin, this is an argument in case we ever want to unit test this | ||
""" | ||
try: | ||
major, minor, plugin_patch = plugin_version.split(".") | ||
except ValueError: | ||
raise ValueError(f"Invalid version: {plugin_version}") | ||
|
||
return f"{major}.{minor}.{_core_patch(plugin_patch)}" | ||
|
||
package_name = "dbt-redshift" | ||
package_version = "1.4.0b1" | ||
dbt_core_version = _get_dbt_core_version() | ||
description = """The Redshift adapter plugin for dbt""" | ||
|
||
setup( | ||
name=package_name, | ||
version=package_version, | ||
description=description, | ||
long_description=long_description, | ||
name="dbt-redshift", | ||
version=_plugin_version(), | ||
description="The Redshift adapter plugin for dbt", | ||
long_description=README.read_text(), | ||
long_description_content_type="text/markdown", | ||
author="dbt Labs", | ||
author_email="[email protected]", | ||
url="https://github.com/dbt-labs/dbt-redshift", | ||
packages=find_namespace_packages(include=["dbt", "dbt.*"]), | ||
include_package_data=True, | ||
install_requires=[ | ||
"dbt-core~={}".format(dbt_core_version), | ||
"dbt-postgres~={}".format(dbt_core_version), | ||
# the following are all to match snowflake-connector-python | ||
"boto3>=1.4.4,<2.0.0", | ||
f"dbt-core~={_core_version()}", | ||
f"dbt-postgres~={_core_version()}", | ||
"boto3~=1.26.26", | ||
], | ||
zip_safe=False, | ||
classifiers=[ | ||
|
@@ -82,6 +96,7 @@ def _get_dbt_core_version(): | |
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
], | ||
python_requires=">=3.7", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ def setUp(self): | |
}, | ||
} | ||
|
||
|
||
PROJECT_DATA = { | ||
'name': 'root', | ||
'version': '0.1', | ||
|
Oops, something went wrong.