Skip to content

Commit d748e53

Browse files
authored
Chore!: Introduce pyproject.toml and switch to packaging via build (#4865)
* Chore!: Introduce pyproject.toml and switch to packaging via build * Drop python 3.7 from tests * shotgun debugging * Remove python 3.7
1 parent 47959a9 commit d748e53

File tree

7 files changed

+56
-40
lines changed

7 files changed

+56
-40
lines changed

.github/workflows/python-package.yml

+3-6
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ jobs:
1010
runs-on: ubuntu-22.04
1111
strategy:
1212
matrix:
13-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
13+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
1414
steps:
1515
- uses: actions/checkout@v3
1616
- name: Set up Python ${{ matrix.python-version }}
1717
uses: actions/setup-python@v4
1818
with:
1919
python-version: ${{ matrix.python-version }}
20+
cache: pip
2021
- name: Create a virtual environment
2122
run: |
2223
python -m venv .venv
@@ -28,8 +29,4 @@ jobs:
2829
- name: Run checks (linter, code style, tests)
2930
run: |
3031
source ./.venv/bin/activate
31-
if [[ ${{ matrix.python-version }} == "3.7" ]]; then
32-
make test test-rs
33-
else
34-
make check
35-
fi
32+
make check

.github/workflows/python-publish.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ jobs:
5555
- uses: actions/setup-python@v5
5656
if: matrix.os == 'windows'
5757
with:
58-
python-version: '3.7'
58+
python-version: '3.8'
5959
architecture: ${{ matrix.python-architecture || 'x64' }}
6060
- name: Build wheels
6161
uses: PyO3/maturin-action@v1
6262
with:
6363
target: ${{ matrix.target }}
64-
args: --release --out dist --interpreter 3.7 3.8 3.9 3.10 3.11 3.12 3.13
64+
args: --release --out dist --interpreter 3.8 3.9 3.10 3.11 3.12 3.13
6565
sccache: 'true'
6666
manylinux: auto
6767
working-directory: ./sqlglotrs
@@ -122,15 +122,15 @@ jobs:
122122
python -m venv .venv
123123
source ./.venv/bin/activate
124124
python -m pip install --upgrade pip
125-
pip install setuptools wheel twine
125+
pip install build twine
126126
make install-dev
127127
- name: Build and publish
128128
env:
129129
TWINE_USERNAME: __token__
130130
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
131131
run: |
132132
source ./.venv/bin/activate
133-
python setup.py sdist bdist_wheel
133+
python -m build
134134
twine upload dist/*
135135
- name: Update API docs
136136
run: |

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ celerybeat.pid
106106
.venv
107107
env/
108108
venv/
109+
venv*/
109110
ENV/
110111
env.bak/
111112
venv.bak/

pyproject.toml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[project]
2+
name = "sqlglot"
3+
dynamic = ["version", "optional-dependencies"]
4+
description = "An easily customizable SQL parser and transpiler"
5+
readme = "README.md"
6+
authors = [{ name = "Toby Mao", email = "[email protected]" }]
7+
license = { file = "LICENSE" }
8+
requires-python = ">= 3.8"
9+
classifiers=[
10+
"Development Status :: 5 - Production/Stable",
11+
"Intended Audience :: Developers",
12+
"Intended Audience :: Science/Research",
13+
"License :: OSI Approved :: MIT License",
14+
"Operating System :: OS Independent",
15+
"Programming Language :: SQL",
16+
"Programming Language :: Python :: 3 :: Only",
17+
]
18+
19+
[project.urls]
20+
Homepage = "https://sqlglot.com/"
21+
Documentation = "https://sqlglot.com/sqlglot.html"
22+
Repository = "https://github.com/tobymao/sqlglot"
23+
Issues = "https://github.com/tobymao/sqlglot/issues"
24+
25+
[build-system]
26+
requires = ["setuptools >= 61.0", "setuptools_scm"]
27+
build-backend = "setuptools.build_meta"
28+
29+
[tool.setuptools]
30+
include-package-data = false
31+
32+
[tool.setuptools_scm]
33+
version_file = "sqlglot/_version.py"
34+
fallback_version = "0.0.0"
35+
local_scheme = "no-local-version"
36+
37+
[tool.setuptools.packages.find]
38+
include=["sqlglot", "sqlglot.*"]
39+
40+
[tool.setuptools.package-data]
41+
"*" = ["py.typed"]

setup.py

+5-27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from setuptools import find_packages, setup
1+
from setuptools import setup
22

33

44
def sqlglotrs_version():
@@ -9,24 +9,11 @@ def sqlglotrs_version():
99
raise ValueError("Could not find version in Cargo.toml")
1010

1111

12+
# Everything is defined in pyproject.toml except the extras because for the [rs] extra we need to dynamically
13+
# read the sqlglotrs version. [dev] has to be specified here as well because you cant specify some extras groups
14+
# dynamically and others statically, it has to be either all dynamic or all static
15+
# ref: https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#dynamic-metadata
1216
setup(
13-
name="sqlglot",
14-
description="An easily customizable SQL parser and transpiler",
15-
long_description=open("README.md").read(),
16-
long_description_content_type="text/markdown",
17-
url="https://github.com/tobymao/sqlglot",
18-
author="Toby Mao",
19-
author_email="[email protected]",
20-
license="MIT",
21-
packages=find_packages(include=["sqlglot", "sqlglot.*"]),
22-
package_data={"sqlglot": ["py.typed"]},
23-
use_scm_version={
24-
"write_to": "sqlglot/_version.py",
25-
"fallback_version": "0.0.0",
26-
"local_scheme": "no-local-version",
27-
},
28-
setup_requires=["setuptools_scm"],
29-
python_requires=">=3.7",
3017
extras_require={
3118
"dev": [
3219
"duckdb>=0.6",
@@ -45,13 +32,4 @@ def sqlglotrs_version():
4532
],
4633
"rs": [f"sqlglotrs=={sqlglotrs_version()}"],
4734
},
48-
classifiers=[
49-
"Development Status :: 5 - Production/Stable",
50-
"Intended Audience :: Developers",
51-
"Intended Audience :: Science/Research",
52-
"License :: OSI Approved :: MIT License",
53-
"Operating System :: OS Independent",
54-
"Programming Language :: SQL",
55-
"Programming Language :: Python :: 3 :: Only",
56-
],
5735
)

sqlglot/expressions.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,7 @@ def depth(self) -> int:
410410

411411
def iter_expressions(self, reverse: bool = False) -> t.Iterator[Expression]:
412412
"""Yields the key and expression for all arguments, exploding list args."""
413-
# remove tuple when python 3.7 is deprecated
414-
for vs in reversed(tuple(self.args.values())) if reverse else self.args.values(): # type: ignore
413+
for vs in reversed(self.args.values()) if reverse else self.args.values(): # type: ignore
415414
if type(vs) is list:
416415
for v in reversed(vs) if reverse else vs: # type: ignore
417416
if hasattr(v, "parent"):

sqlglotrs/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "maturin"
55
[project]
66
name = "sqlglotrs"
77
description = "An easily customizable SQL parser and transpiler"
8-
requires-python = ">=3.7"
8+
requires-python = ">=3.8"
99
classifiers = [
1010
"Programming Language :: Rust",
1111
"Programming Language :: Python :: Implementation :: CPython",

0 commit comments

Comments
 (0)