File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -188,7 +188,21 @@ def get_version(version: str) -> Version:
188188 from packaging .version import Version
189189
190190 except ImportError : # pragma: no cover
191+ # Trigger the sys.path change mentioned below, but discard this.
191192 from setuptools ._vendor .packaging .version import Version
193+
194+ try :
195+ # See https://pydanticlogfire.slack.com/archives/C06EDRBSAH3/p1722017944332959
196+ # Importing setuptools modifies sys.path so that `packaging.version` points to the vendored module.
197+ # This means that two calls to this function could return instances of
198+ # `setuptools._vendor.packaging.version.Version` and `packaging.version.Version`
199+ # (the same file but in different module objects) which cannot be compared.
200+ # So first try `packaging.version` again.
201+ from packaging .version import Version
202+
203+ except ImportError :
204+ # sys.path is only changed in newer versions, so fallback to just importing the vendored Version directly.
205+ from setuptools ._vendor .packaging .version import Version
192206 return Version (version ) # type: ignore
193207
194208
You can’t perform that action at this time.
0 commit comments