Skip to content

Commit 08f22bd

Browse files
RonnyPfannschmidtCursor AIWagiklinKasa
committed
fix: lazy-import bdist_wheel and simplify unlink
Avoid ImportError when wheel is not installed during sdist-only builds, and use Path.unlink(missing_ok=True) for SCM metadata cleanup. Co-authored-by: Cursor AI <ai@cursor.sh> Co-authored-by: Cursor Grok 4.5 <grok@x.ai>
1 parent 82768f0 commit 08f22bd

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

‎setuptools-scm/src/setuptools_scm/_integration/bdist_wheel.py‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,9 @@
1818

1919

2020
def _unlink_scm_metadata(distinfo_path: Path) -> None:
21-
"""Remove SCM metadata files from a ``.dist-info`` directory if present.
22-
23-
Mirrors setuptools ``egg2dist``'s ``adios`` for plain files: ``unlink``
24-
when the path exists (including symlinks), never ``rmtree``.
25-
"""
21+
"""Remove SCM metadata files from a ``.dist-info`` directory if present."""
2622
for name in _SCM_DIST_INFO_FILES:
27-
path = distinfo_path / name
28-
if path.exists() or path.is_symlink():
29-
path.unlink()
23+
(distinfo_path / name).unlink(missing_ok=True)
3024

3125

3226
class ScmBdistWheelMixin(_bdist_wheel):

‎setuptools-scm/src/setuptools_scm/_integration/setuptools.py‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
from vcs_versioning.overrides import GlobalOverrides
1414
from vcs_versioning.overrides import ensure_context
1515

16-
from .bdist_wheel import ScmBdistWheelMixin
17-
from .bdist_wheel import bdist_wheel as scm_bdist_wheel
1816
from .build_py import ScmVersionFileMixin
1917
from .build_py import build_py as scm_build_py
2018
from .egg_info import ScmEggInfoMixin
@@ -101,7 +99,20 @@ def _register_bdist_wheel_command(dist: setuptools.Distribution) -> None:
10199
102100
Sdists keep ``scm_version.json`` / ``scm_file_list.json`` for fallback
103101
discovery; wheels already have ``METADATA`` and ``RECORD``.
102+
103+
Import is lazy so sdist-only environments without the ``wheel`` package
104+
still load ``infer_version`` / ``version_keyword``.
104105
"""
106+
try:
107+
from .bdist_wheel import ScmBdistWheelMixin
108+
from .bdist_wheel import bdist_wheel as scm_bdist_wheel
109+
except ImportError:
110+
log.debug(
111+
"bdist_wheel unavailable; skipping SCM wheel metadata strip",
112+
exc_info=True,
113+
)
114+
return
115+
105116
if not dist.cmdclass:
106117
dist.cmdclass = {}
107118

0 commit comments

Comments
 (0)