Skip to content

Commit 1955881

Browse files
authored
Fix(sqlglotc): pin sqlglot to the exact matching version (#7730)
* Fix(sqlglotc): pin sqlglot to the exact matching version * Make install_requirements more resilient * More feedback from copilot
1 parent df507aa commit 1955881

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

sqlglotc/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "sqlglotc"
3-
dynamic = ["version"]
3+
dynamic = ["version", "dependencies"]
44
description = "mypyc-compiled extensions for sqlglot"
55
authors = [{ name = "Toby Mao", email = "toby.mao@gmail.com" }]
66
license = "MIT"

sqlglotc/setup.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,42 @@ def run(self):
128128
shutil.rmtree(local_sqlglot, ignore_errors=True)
129129

130130

131+
def _sqlglot_requirement():
132+
"""Pin sqlglot to the matching version so resolvers keep the two packages in lockstep."""
133+
try:
134+
pkg_info = os.path.join(os.path.dirname(os.path.abspath(__file__)), "PKG-INFO")
135+
if os.path.isfile(pkg_info):
136+
# Building from an sdist: no git metadata; the released version is frozen in PKG-INFO.
137+
with open(pkg_info, encoding="utf-8") as fd:
138+
version = next(
139+
(line.split(":", 1)[1].strip() for line in fd if line.startswith("Version:")),
140+
"",
141+
)
142+
else:
143+
from setuptools_scm import get_version
144+
145+
version = get_version(
146+
root="..",
147+
relative_to=__file__,
148+
local_scheme="no-local-version",
149+
fallback_version="0.0.0",
150+
)
151+
except Exception as e:
152+
print(f"sqlglotc: failed to determine the sqlglot version to pin: {e}")
153+
version = ""
154+
155+
# Dev and fallback (no git metadata) builds have no matching sqlglot release on PyPI;
156+
# depend on sqlglot unpinned since the extensions can't be imported without it.
157+
if version in ("", "0.0.0") or ".dev" in version:
158+
return ["sqlglot"]
159+
160+
return [f"sqlglot=={version}"]
161+
162+
131163
setup(
132164
name="sqlglotc",
133165
packages=[],
166+
install_requires=_sqlglot_requirement(),
134167
ext_modules=mypycify(
135168
_source_paths(), opt_level=os.environ.get("MYPYC_OPT", "2"), separate=True, verbose=True
136169
),

0 commit comments

Comments
 (0)