Move from setup.py to pyproject.toml (#12129)

* convert setup.py to pyproject.toml

* move dev requirements into pyproject.toml

* with setup.py gone we can install from root

* lint

cleanrly state intention to remove

* convert precommit to use dev deps

* consolidate version to pyproject.toml

* editable req

get rid of editable-req

* docs updates

* tweak configs for builds

* fix script

* changelog

* fixes to build

* revert unnecesary changes

more simplification

revert linting

more simplification

fix

don’t need it
This commit is contained in:
Emily Rockman
2025-11-06 14:08:00 +00:00
committed by GitHub
parent c170211ce3
commit 7e10fc72d5
9 changed files with 181 additions and 108 deletions

View File

@@ -32,6 +32,6 @@ first_value = 1
[bumpversion:part:nightly] [bumpversion:part:nightly]
[bumpversion:file:core/setup.py] [bumpversion:file:core/pyproject.toml]
search = version = "{current_version}"
[bumpversion:file:core/dbt/version.py] replace = version = "{new_version}"

View File

@@ -0,0 +1,6 @@
kind: Under the Hood
body: Move from setup.py to pyproject.toml
time: 2025-10-29T13:34:50.106244-04:00
custom:
Author: emmyoop
Issue: "5696"

View File

@@ -39,7 +39,7 @@ Each adapter plugin is a standalone python package that includes:
- `dbt/include/[name]`: A "sub-global" dbt project, of YAML and SQL files, that reimplements Jinja macros to use the adapter's supported SQL syntax - `dbt/include/[name]`: A "sub-global" dbt project, of YAML and SQL files, that reimplements Jinja macros to use the adapter's supported SQL syntax
- `dbt/adapters/[name]`: Python modules that inherit, and optionally reimplement, the base adapter classes defined in dbt-core - `dbt/adapters/[name]`: Python modules that inherit, and optionally reimplement, the base adapter classes defined in dbt-core
- `setup.py` - `pyproject.toml`
The Postgres adapter code is the most central, and many of its implementations are used as the default defined in the dbt-core global project. The greater the distance of a data technology from Postgres, the more its adapter plugin may need to reimplement. The Postgres adapter code is the most central, and many of its implementations are used as the default defined in the dbt-core global project. The greater the distance of a data technology from Postgres, the more its adapter plugin may need to reimplement.

View File

@@ -3,6 +3,9 @@ import importlib
import importlib.util import importlib.util
import json import json
import os import os
import re
from importlib import metadata as importlib_metadata
from pathlib import Path
from typing import Iterator, List, Optional, Tuple from typing import Iterator, List, Optional, Tuple
import requests import requests
@@ -226,5 +229,21 @@ def _get_adapter_plugin_names() -> Iterator[str]:
yield plugin_name yield plugin_name
__version__ = "1.11.0b4" def _resolve_version() -> str:
try:
return importlib_metadata.version("dbt-core")
except importlib_metadata.PackageNotFoundError:
pyproject_path = Path(__file__).resolve().parents[1] / "pyproject.toml"
if not pyproject_path.exists():
raise RuntimeError("Unable to locate pyproject.toml to determine dbt-core version")
text = pyproject_path.read_text(encoding="utf-8")
match = re.search(r'^version\s*=\s*"(?P<version>[^"]+)"', text, re.MULTILINE)
if match:
return match.group("version")
raise RuntimeError("Unable to determine dbt-core version from pyproject.toml")
__version__ = _resolve_version()
installed = get_installed_version() installed = get_installed_version()

110
core/pyproject.toml Normal file
View File

@@ -0,0 +1,110 @@
[tool.setuptools]
package-dir = {"" = "."}
include-package-data = true
zip-safe = false
[tool.setuptools.packages.find]
where = ["."]
include = [
"dbt",
"dbt.*",
]
# this needs to match MANIFEST.in for the wheels
[tool.setuptools.package-data]
"dbt" = [
"include/**/*.py",
"include/**/*.sql",
"include/**/*.yml",
"include/**/*.html",
"include/**/*.md",
"include/**/.gitkeep",
"include/**/.gitignore",
"task/docs/**/*.html",
"jsonschemas/**/*.json",
"py.typed",
]
[project]
name = "dbt-core"
version = "1.11.0b4"
description = "With dbt, data analysts and engineers can build analytics the way engineers build applications."
readme = "README.md"
requires-python = ">=3.10"
license = "Apache-2.0"
license-files = ["License.md"] # License.md copied to core/ by build script even though it lives at the root by convention
keywords = []
authors = [
{ name = "dbt Labs", email = "info@dbtlabs.com" },
]
maintainers = [
{ name = "dbt Labs", email = "info@dbtlabs.com" },
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Operating System :: Microsoft :: Windows",
"Operating System :: MacOS :: MacOS X",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
# ----
# dbt-core uses these packages deeply, throughout the codebase, and there have been breaking changes in past patch releases (even though these are major-version-one).
# Pin to the patch or minor version, and bump in each new minor version of dbt-core.
"agate>=1.7.0,<1.10",
"Jinja2>=3.1.3,<4",
"mashumaro[msgpack]>=3.9,<3.15",
# ----
# dbt-core uses these packages in standard ways. Pin to the major version, and check compatibility
# with major versions in each new minor version of dbt-core.
"click>=8.0.2,<9.0",
"jsonschema>=4.19.1,<5.0",
"networkx>=2.3,<4.0",
"protobuf>=6.0,<7.0",
"requests<3.0.0", # should match dbt-common
"snowplow-tracker>=1.0.2,<2.0",
# ----
# These packages are major-version-0. Keep upper bounds on upcoming minor versions (which could have breaking changes)
# and check compatibility / bump in each new minor version of dbt-core.
"pathspec>=0.9,<0.13",
"sqlparse>=0.5.0,<0.6.0",
# ----
# These are major-version-0 packages also maintained by dbt-labs.
# Accept patches but avoid automatically updating past a set minor version range.
"dbt-extractor>=0.5.0,<=0.6",
"dbt-semantic-interfaces>=0.9.0,<0.10",
# Minor versions for these are expected to be backwards-compatible
"dbt-common>=1.27.0,<2.0",
"dbt-adapters>=1.15.5,<2.0",
"dbt-protos>=1.0.375,<2.0",
"pydantic<3",
# ----
# Expect compatibility with all new versions of these packages, so lower bounds only.
"packaging>20.9",
"pytz>=2015.7",
"pyyaml>=6.0",
"daff>=1.3.46",
"typing-extensions>=4.4",
]
[project.urls]
Homepage = "https://github.com/dbt-labs/dbt-core"
Repository = "https://github.com/dbt-labs/dbt-core.git"
Issues = "https://github.com/dbt-labs/dbt-core/issues"
Changelog = "https://github.com/dbt-labs/dbt-core/blob/main/CHANGELOG.md"
[project.scripts]
dbt = "dbt.cli.main:cli"
[build-system]
requires = [
"setuptools>=61",
"wheel",
]
build-backend = "setuptools.build_meta"

View File

@@ -1,101 +1,26 @@
#!/usr/bin/env python #!/usr/bin/env python
import os
import sys
if sys.version_info < (3, 10):
print("Error: dbt does not support this version of Python.")
print("Please upgrade to Python 3.10 or higher.")
sys.exit(1)
"""Legacy setuptools shim retained for compatibility with existing workflows. Will be removed in a future version."""
from setuptools import setup from setuptools import setup
try: # the user has a downlevel version of setuptools.
from setuptools import find_namespace_packages # ----
except ImportError: # dbt-core uses these packages deeply, throughout the codebase, and there have been breaking changes in past patch releases (even though these are major-version-one).
# the user has a downlevel version of setuptools. # Pin to the patch or minor version, and bump in each new minor version of dbt-core.
print("Error: dbt requires setuptools v40.1.0 or higher.") # ----
print('Please upgrade setuptools with "pip install --upgrade setuptools" ' "and try again") # dbt-core uses these packages in standard ways. Pin to the major version, and check compatibility
sys.exit(1) # with major versions in each new minor version of dbt-core.
# ----
# These packages are major-version-0. Keep upper bounds on upcoming minor versions (which could have breaking changes)
# and check compatibility / bump in each new minor version of dbt-core.
# ----
# These are major-version-0 packages also maintained by dbt-labs.
# Accept patches but avoid automatically updating past a set minor version range.
# Minor versions for these are expected to be backwards-compatible
# ----
# Expect compatibility with all new versions of these packages, so lower bounds only.
# ----
if __name__ == "__main__":
this_directory = os.path.abspath(os.path.dirname(__file__)) setup()
with open(os.path.join(this_directory, "README.md")) as f:
long_description = f.read()
package_name = "dbt-core"
package_version = "1.11.0b4"
description = """With dbt, data analysts and engineers can build analytics \
the way engineers build applications."""
setup(
name=package_name,
version=package_version,
description=description,
long_description=long_description,
long_description_content_type="text/markdown",
author="dbt Labs",
author_email="info@dbtlabs.com",
url="https://github.com/dbt-labs/dbt-core",
packages=find_namespace_packages(include=["dbt", "dbt.*"]),
include_package_data=True,
test_suite="test",
entry_points={
"console_scripts": ["dbt = dbt.cli.main:cli"],
},
install_requires=[
# ----
# dbt-core uses these packages deeply, throughout the codebase, and there have been breaking changes in past patch releases (even though these are major-version-one).
# Pin to the patch or minor version, and bump in each new minor version of dbt-core.
"agate>=1.7.0,<1.10",
"Jinja2>=3.1.3,<4",
"mashumaro[msgpack]>=3.9,<3.15",
# ----
# dbt-core uses these packages in standard ways. Pin to the major version, and check compatibility
# with major versions in each new minor version of dbt-core.
"click>=8.0.2,<9.0",
"jsonschema>=4.19.1,<5.0",
"networkx>=2.3,<4.0",
"protobuf>=6.0,<7.0",
"requests<3.0.0", # should match dbt-common
"snowplow-tracker>=1.0.2,<2.0",
# ----
# These packages are major-version-0. Keep upper bounds on upcoming minor versions (which could have breaking changes)
# and check compatibility / bump in each new minor version of dbt-core.
"pathspec>=0.9,<0.13",
"sqlparse>=0.5.0,<0.6.0",
# ----
# These are major-version-0 packages also maintained by dbt-labs.
# Accept patches but avoid automatically updating past a set minor version range.
"dbt-extractor>=0.5.0,<=0.6",
"dbt-semantic-interfaces>=0.9.0,<0.10",
# Minor versions for these are expected to be backwards-compatible
"dbt-common>=1.27.0,<2.0",
"dbt-adapters>=1.15.5,<2.0",
"dbt-protos>=1.0.375,<2.0",
"pydantic<3",
# ----
# Expect compatibility with all new versions of these packages, so lower bounds only.
"packaging>20.9",
"pytz>=2015.7",
"pyyaml>=6.0",
"daff>=1.3.46",
"typing-extensions>=4.4",
# ----
],
zip_safe=False,
classifiers=[
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: Apache Software License",
"Operating System :: Microsoft :: Windows",
"Operating System :: MacOS :: MacOS X",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
],
python_requires=">=3.10",
)

View File

@@ -1,3 +1,7 @@
# Root-level pyproject.toml for tool configurations
# Packaging configuration is in core/pyproject.toml
# This file exists so tools like mypy and black can find their config when run from root
[tool.mypy] [tool.mypy]
# TODO: widen range of files as we fix issues # TODO: widen range of files as we fix issues
files = 'core/dbt' files = 'core/dbt'

View File

@@ -12,13 +12,20 @@ set -x
rm -rf "$DBT_PATH"/dist rm -rf "$DBT_PATH"/dist
rm -rf "$DBT_PATH"/build rm -rf "$DBT_PATH"/build
rm -rf "$DBT_PATH"/core/dist
rm -rf "$DBT_PATH"/core/build
mkdir -p "$DBT_PATH"/dist mkdir -p "$DBT_PATH"/dist
rm -rf "$DBT_PATH"/core/dist # Copy License.md to core/ for inclusion in distribution (required by Apache 2.0)
rm -rf "$DBT_PATH"core/build # The license-files in pyproject.toml references it relative to core/
cd "$DBT_PATH"/core cp "$DBT_PATH"/License.md "$DBT_PATH"/core/License.md
$PYTHON_BIN setup.py sdist bdist_wheel
cp -r "$DBT_PATH"/"core"/dist/* "$DBT_PATH"/dist/
cd "$DBT_PATH"/core
$PYTHON_BIN -m pip install --upgrade build
$PYTHON_BIN -m build --outdir "$DBT_PATH/dist"
# Clean up License.md that was copied to core/ for build
rm -f "$DBT_PATH/core/License.md"
set +x set +x

View File

@@ -1,14 +1,16 @@
#!/bin/bash -e #!/bin/bash -e
set -e set -e
# this is used in dbt-common for CI
repo=$1 repo=$1
ref=$2 ref=$2
target_req_file="dev-requirements.txt" target_req_file="dev-requirements.txt"
req_sed_pattern="s|${repo}.git@main|${repo}.git@${ref}|g" req_sed_pattern="s|${repo}.git@main|${repo}.git@${ref}|g"
if [[ "$OSTYPE" == darwin* ]]; then if [[ "$OSTYPE" == darwin* ]]; then
# mac ships with a different version of sed that requires a delimiter arg # mac ships with a different version of sed that requires a delimiter arg
sed -i "" "$req_sed_pattern" $target_req_file sed -i "" "$req_sed_pattern" "$target_req_file"
else else
sed -i "$req_sed_pattern" $target_req_file sed -i "$req_sed_pattern" "$target_req_file"
fi fi