Skip to content

Commit

Permalink
Handle wheel.bdist_wheel deprecation warning (#463)
Browse files Browse the repository at this point in the history
* Handle wheel.bdist_wheel deprecation warning

* Add relevant type ignore annotations

* Remove unused type: ignore annotations

* Remove wheel dependency and rely on setuptools providing bdist_wheel

* Add temporary workaround for issue 117 of cffi

* Further changes to avoid CI errors with CFFI

* Ensure recent setuptools is installed to avoid CI error

* Fallback to importing bdist_wheel from wheel for type-checking

* remove pin

* remove pins

* CHANGELOG entry

---------

Co-authored-by: David Hewitt <[email protected]>
  • Loading branch information
abravalheri and davidhewitt authored Oct 2, 2024
1 parent 4e5f25f commit 37dd294
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 35 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
rustup target add aarch64-apple-darwin
rustup target add x86_64-apple-darwin
cd examples/namespace_package
pip install build wheel
pip install build 'setuptools>=70.1'
python -m build --no-isolation
ls -l dist/
pip install --force-reinstall dist/namespace_package*_universal2.whl
Expand Down Expand Up @@ -163,7 +163,7 @@ jobs:
set -e
cd examples/rust_with_cffi/
python --version
pip install -U build cffi wheel
pip install -U build cffi 'setuptools>=70.1'
echo -e "[bdist_wheel]\npy_limited_api=cp39" > $DIST_EXTRA_CONFIG
python -m build --no-isolation
ls -la dist/
Expand All @@ -180,7 +180,6 @@ jobs:
run: |
set -e
cd examples/
pip install -U wheel
python --version
pip install rust_with_cffi/dist/rust_with_cffi*.whl
python -c "from rust_with_cffi import rust; assert rust.rust_func() == 14"
Expand Down Expand Up @@ -235,7 +234,7 @@ jobs:
run: |
cd examples/namespace_package
docker build -t cross-pyo3:aarch64-unknown-linux-gnu .
python -m pip install build wheel
python -m pip install build
echo -e "[bdist_wheel]\nplat_name=manylinux2014_aarch64" > $DIST_EXTRA_CONFIG
python -m build --no-isolation
ls -la dist/
Expand Down Expand Up @@ -283,7 +282,7 @@ jobs:
mkdir -p $PYO3_CROSS_LIB_DIR
docker cp -L $(docker create --rm quay.io/pypa/manylinux2014_aarch64:latest):/opt/python/cp38-cp38 /opt/python
cd examples/namespace_package
python -m pip install build wheel
python -m pip install build
echo -e "[bdist_wheel]\nplat_name=manylinux2014_aarch64" > $DIST_EXTRA_CONFIG
python -m build --no-isolation
ls -la dist/
Expand Down Expand Up @@ -315,7 +314,7 @@ jobs:
env:
CIBW_BUILD: cp39-*
CIBW_BEFORE_BUILD: >
pip install -U 'pip>=23.2.1' 'setuptools>=68.0.0' 'wheel>=0.41.2' 'auditwheel>=5.4.0'
pip install -U 'pip>=23.2.1' 'setuptools>=70.1.0' 'auditwheel>=5.4.0'
&& pip install -e .
&& pip list
CIBW_ARCHS_MACOS: "x86_64 universal2 arm64"
Expand Down Expand Up @@ -354,7 +353,7 @@ jobs:

- name: Install test dependencies
shell: msys2 {0}
run: python -m pip install --upgrade nox pip wheel
run: python -m pip install --upgrade nox pip

- name: Create libpython symlink
shell: msys2 {0}
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.10.2 (2024-10-01)
### Fixed
- Fix deprecation warning from use of `wheel.bdist_wheel`.

## 1.10.1 (2024-08-04)
### Fixed
- Fix regression in 1.10.0 where editable builds would be built in release mode
Expand Down
2 changes: 1 addition & 1 deletion examples/hello-world-script/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@nox.session()
def test(session: nox.Session):
session.install(SETUPTOOLS_RUST, "wheel")
session.install(SETUPTOOLS_RUST)
# Ensure build uses version of setuptools-rust under development
session.install("--no-build-isolation", ".")
# Test Rust binary
Expand Down
2 changes: 1 addition & 1 deletion examples/hello-world-script/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools", "wheel", "setuptools-rust"]
requires = ["setuptools", "setuptools-rust"]
build-backend = "setuptools.build_meta"

[project]
Expand Down
2 changes: 1 addition & 1 deletion examples/hello-world-setuppy/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@nox.session()
def test(session: nox.Session):
session.install(SETUPTOOLS_RUST, "wheel")
session.install(SETUPTOOLS_RUST)
# Ensure build uses version of setuptools-rust under development
session.install("--no-build-isolation", ".")
# Test Rust binary
Expand Down
2 changes: 1 addition & 1 deletion examples/hello-world-setuppy/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build-system]
requires = ["setuptools", "wheel", "setuptools-rust"]
requires = ["setuptools", "setuptools-rust"]
build-backend = "setuptools.build_meta"
2 changes: 1 addition & 1 deletion examples/hello-world/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@nox.session()
def test(session: nox.Session):
session.install(SETUPTOOLS_RUST, "wheel", "build", "pytest")
session.install(SETUPTOOLS_RUST, "build", "pytest")
# Ensure build works as intended
session.install("--no-build-isolation", ".")
# Test Rust binary
Expand Down
2 changes: 1 addition & 1 deletion examples/html-py-ever/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ test_bench_selector_python[/home/david/dev/setuptools-rust/examples/html-py-ever

**building and installing**
```
pip install setuptools-rust setuptools wheel
pip install setuptools-rust setuptools
python3 setup.py install --user
```

Expand Down
2 changes: 1 addition & 1 deletion examples/html-py-ever/build-wheels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export PATH="$HOME/.cargo/bin:$PATH"
# Compile wheels
for PYBIN in /opt/python/cp{37,38,39,310}*/bin; do
rm -rf /io/build/
"${PYBIN}/pip" install -U setuptools setuptools-rust wheel
"${PYBIN}/pip" install -U setuptools setuptools-rust
"${PYBIN}/pip" wheel /io/ -w /io/dist/ --no-deps
done

Expand Down
4 changes: 1 addition & 3 deletions examples/html-py-ever/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

@nox.session()
def test(session: nox.Session):
session.install(
SETUPTOOLS_RUST, "wheel", "pytest", "pytest-benchmark", "beautifulsoup4"
)
session.install(SETUPTOOLS_RUST, "pytest", "pytest-benchmark", "beautifulsoup4")
# Ensure build uses version of setuptools-rust under development
session.install("--no-build-isolation", ".")
# Test Python package
Expand Down
2 changes: 1 addition & 1 deletion examples/html-py-ever/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools", "wheel", "setuptools-rust"]
requires = ["setuptools", "setuptools-rust"]
build-backend = "setuptools.build_meta"

[project]
Expand Down
3 changes: 1 addition & 2 deletions examples/html-py-ever/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
setuptools-rust
setuptools
wheel
setuptools>=70.1.0
2 changes: 1 addition & 1 deletion examples/namespace_package/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@nox.session()
def test(session: nox.Session):
session.install(SETUPTOOLS_RUST, "wheel")
session.install(SETUPTOOLS_RUST)
# Ensure build uses version of setuptools-rust under development
session.install("--no-build-isolation", ".[dev]")
# Test Python package
Expand Down
2 changes: 1 addition & 1 deletion examples/namespace_package/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools", "wheel", "setuptools-rust"]
requires = ["setuptools", "setuptools-rust"]
build-backend = "setuptools.build_meta"

[project]
Expand Down
2 changes: 1 addition & 1 deletion examples/rust_with_cffi/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@nox.session()
def test(session: nox.Session):
session.install(SETUPTOOLS_RUST, "wheel", "pytest")
session.install(SETUPTOOLS_RUST, "pytest")

try:
session.install("cffi", "--only-binary=cffi")
Expand Down
8 changes: 4 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_examples(session: nox.Session):

@nox.session(name="test-sdist-vendor")
def test_sdist_vendor(session: nox.Session):
session.install(".", "build", "wheel")
session.install(".", "build")
namespace_package = Path(__file__).parent / "examples" / "namespace_package"
os.chdir(namespace_package)
tmp = Path(session.create_tmp())
Expand Down Expand Up @@ -79,8 +79,8 @@ def test_crossenv(session: nox.Session):
python3.11 -m crossenv "/opt/python/cp311-cp311/bin/python3" --cc $TARGET_CC --cxx $TARGET_CXX --sysroot $TARGET_SYSROOT --env LIBRARY_PATH= --manylinux manylinux1 /venv
. /venv/bin/activate
build-pip install -U 'pip>=23.2.1' 'setuptools>=68.0.0' 'wheel>=0.41.1' 'build>=1'
cross-pip install -U 'pip>=23.2.1' 'setuptools>=68.0.0' 'wheel>=0.41.1' 'build>=1'
build-pip install -U 'pip>=23.2.1' 'setuptools>=70.1' 'build>=1'
cross-pip install -U 'pip>=23.2.1' 'setuptools>=70.1' 'build>=1'
build-pip install cffi
cross-expose cffi
cross-pip install -e ../../
Expand Down Expand Up @@ -171,7 +171,7 @@ def newrun(*args, **kwargs):
examples = Path(os.path.dirname(__file__)).absolute() / "examples"

with patch.object(nox.command, "run", newrun):
session.install(".", "wheel")
session.install(".")

session.install("--no-build-isolation", str(examples / "hello-world"))
session.run("print-hello")
Expand Down
13 changes: 8 additions & 5 deletions setuptools_rust/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@


try:
from wheel.bdist_wheel import bdist_wheel as CommandBdistWheel
except ImportError: # wheel installation might be deferred in PEP 517
from setuptools import Command as CommandBdistWheel
from setuptools.command.bdist_wheel import bdist_wheel as CommandBdistWheel
except ImportError: # old version of setuptools
try:
from wheel.bdist_wheel import bdist_wheel as CommandBdistWheel # type: ignore[no-redef]
except ImportError:
from setuptools import Command as CommandBdistWheel # type: ignore[assignment]


def _check_cargo_supports_crate_type_option() -> bool:
Expand Down Expand Up @@ -789,12 +792,12 @@ def _replace_cross_target_dir(path: str, ext: RustExtension, *, quiet: bool) ->
return path.replace(cross_target_dir, local_target_dir)


def _get_bdist_wheel_cmd( # type: ignore[no-any-unimported]
def _get_bdist_wheel_cmd(
dist: Distribution, create: Literal[True, False] = True
) -> Optional[CommandBdistWheel]:
try:
cmd_obj = dist.get_command_obj("bdist_wheel", create=create)
cmd_obj.ensure_finalized() # type: ignore[union-attr]
return cast(CommandBdistWheel, cmd_obj) # type: ignore[no-any-unimported]
return cast(CommandBdistWheel, cmd_obj)
except Exception:
return None
9 changes: 6 additions & 3 deletions setuptools_rust/setuptools_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
from .extension import Binding, RustBin, RustExtension, Strip

try:
from wheel.bdist_wheel import bdist_wheel
from setuptools.command.bdist_wheel import bdist_wheel
except ImportError:
bdist_wheel = None
try: # old version of setuptools
from wheel.bdist_wheel import bdist_wheel # type: ignore[no-redef]
except ImportError:
bdist_wheel = None # type: ignore[assignment,misc]

if sys.version_info[:2] >= (3, 11):
from tomllib import load as toml_load
Expand Down Expand Up @@ -251,7 +254,7 @@ def run(self) -> None:
dist.cmdclass["install_scripts"] = install_scripts_rust_extension

if bdist_wheel is not None:
bdist_wheel_base_class = cast( # type: ignore[no-any-unimported]
bdist_wheel_base_class = cast(
Type[bdist_wheel], dist.cmdclass.get("bdist_wheel", bdist_wheel)
)
bdist_wheel_options = bdist_wheel_base_class.user_options.copy()
Expand Down

0 comments on commit 37dd294

Please sign in to comment.