Skip to content

Commit 2e689e0

Browse files
yuki-inahoclaude
andcommitted
Drop pkg_resources from setup.py; retire setuptools<81 build pin
Replace the pkg_resources import (removed in setuptools>=81) with importlib.metadata + packaging.version (open-mmlab#3326/open-mmlab#3328). The wheel build no longer needs the setuptools<81 workaround, so the GitHub Action and justfile build-wheel now install plain setuptools (+ packaging). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 7b6f80b commit 2e689e0

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

.github/workflows/build-cu121-wheels.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ jobs:
6464
- name: Install torch (cu121) + build deps
6565
run: |
6666
set -eux
67-
# setuptools<81 still ships pkg_resources, which mmcv's setup.py imports.
68-
python${PYTHON_VERSION} -m pip install "setuptools<81" wheel ninja "numpy<2"
67+
# setup.py no longer needs pkg_resources, so any setuptools works.
68+
python${PYTHON_VERSION} -m pip install setuptools wheel ninja packaging "numpy<2"
6969
python${PYTHON_VERSION} -m pip install "torch==${TORCH_VERSION}" \
7070
--index-url "${CU_INDEX}"
7171

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ build-wheel CC="8.6":
5656
if [ -f pyproject.toml ]; then mv pyproject.toml .pyproject.devenv.bak; fi
5757
uv run --no-project --python 3.10 \
5858
--with "torch=={{ TORCH_VERSION }}" --with "numpy<2" \
59-
--with pip --with "setuptools<81" --with wheel --with ninja \
59+
--with pip --with setuptools --with wheel --with ninja --with packaging \
6060
--index-strategy unsafe-best-match --extra-index-url "{{ CU_INDEX }}" \
6161
env MMCV_WITH_OPS=1 FORCE_CUDA=1 TORCH_CUDA_ARCH_LIST="{{ CC }}" \
6262
python -m pip wheel --no-build-isolation --no-deps -w "dist/cc_{{ CC }}" . -v ; \

setup.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,26 @@
22
import os
33
import platform
44
import re
5-
from pkg_resources import DistributionNotFound, get_distribution, parse_version
65
from setuptools import find_packages, setup
76

7+
# Avoid the deprecated pkg_resources (removed in setuptools>=81). Use
8+
# importlib.metadata + packaging.version instead.
9+
from importlib.metadata import PackageNotFoundError
10+
from importlib.metadata import version as _pkg_version
11+
from packaging.version import parse as parse_version
12+
13+
14+
class DistributionNotFound(Exception):
15+
"""Raised by get_distribution() when a package is not installed."""
16+
17+
18+
def get_distribution(name):
19+
"""Probe whether ``name`` is installed; raise DistributionNotFound if not."""
20+
try:
21+
_pkg_version(name)
22+
except PackageNotFoundError as exc:
23+
raise DistributionNotFound(name) from exc
24+
825
EXT_TYPE = ''
926
try:
1027
import torch

0 commit comments

Comments
 (0)