Skip to content

Commit

Permalink
tests: fix under pyproject-hooks 1.2
Browse files Browse the repository at this point in the history
By replacing setuptools with a bare-bones wheel builder.
  • Loading branch information
layday committed Oct 6, 2024
1 parent a73ecbd commit e0e911c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
25 changes: 23 additions & 2 deletions tests/packages/test-no-prepare/backend_no_prepare.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
# SPDX-License-Identifier: MIT

from setuptools.build_meta import build_sdist as build_sdist
from setuptools.build_meta import build_wheel as build_wheel

def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
import os.path
import zipfile

from build._compat import tomllib

with open('pyproject.toml', 'rb') as f:
metadata = tomllib.load(f)

wheel_basename = f"{metadata['project']['name'].replace('-', '_')}-{metadata['project']['version']}"
with zipfile.ZipFile(os.path.join(wheel_directory, f'{wheel_basename}-py3-none-any.whl'), 'w') as wheel:
wheel.writestr(
f'{wheel_basename}.dist-info/METADATA',
f"""\
Metadata-Version: 2.2
Name: {metadata['project']['name']}
Version: {metadata['project']['version']}
Summary: {metadata['project']['description']}
""",
)

return wheel.filename
7 changes: 6 additions & 1 deletion tests/packages/test-no-prepare/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
[build-system]
build-backend = 'backend_no_prepare'
backend-path = ['.']
requires = ['setuptools >= 42.0.0']
requires = []

[project]
name = "test-no-prepare"
version = "1.0.0"
description = "Test extracting metadata from a backend w/out `prepare_metadata_for_build_wheel` hook"
3 changes: 0 additions & 3 deletions tests/packages/test-no-prepare/setup.cfg

This file was deleted.

3 changes: 1 addition & 2 deletions tests/test_projectbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,7 @@ def test_metadata_path_no_prepare(tmp_dir, package_test_no_prepare):
pathlib.Path(builder.metadata_path(tmp_dir)),
).metadata

# Setuptools < v69.0.3 (https://github.com/pypa/setuptools/pull/4159) normalized this to dashes
assert metadata['name'].replace('-', '_') == 'test_no_prepare'
assert metadata['name'] == 'test-no-prepare'
assert metadata['Version'] == '1.0.0'


Expand Down

0 comments on commit e0e911c

Please sign in to comment.