@@ -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+
131163setup (
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