Skip to content

Commit f63c40b

Browse files
dnicolodirgommers
authored andcommitted
MAINT: split editable wheel builder from wheel builder
1 parent d8ff480 commit f63c40b

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

mesonpy/__init__.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -397,22 +397,6 @@ def _stable_abi(self) -> Optional[str]:
397397
return 'abi3'
398398
return None
399399

400-
@property
401-
def top_level_modules(self) -> Collection[str]:
402-
modules = set()
403-
for type_ in self._manifest:
404-
for path, _ in self._manifest[type_]:
405-
name, dot, ext = path.parts[0].partition('.')
406-
if dot:
407-
# module
408-
suffix = dot + ext
409-
if suffix in _SUFFIXES:
410-
modules.add(name)
411-
else:
412-
# package
413-
modules.add(name)
414-
return modules
415-
416400
def _install_path(self, wheel_file: mesonpy._wheelfile.WheelFile, origin: Path, destination: pathlib.Path) -> None:
417401
"""Add a file to the wheel."""
418402

@@ -470,8 +454,27 @@ def build(self, directory: Path) -> pathlib.Path:
470454

471455
return wheel_file
472456

473-
def build_editable(self, directory: Path, source_dir: pathlib.Path, build_dir: pathlib.Path,
474-
build_command: List[str], verbose: bool = False) -> pathlib.Path:
457+
458+
class _EditableWheelBuilder(_WheelBuilder):
459+
460+
@property
461+
def _top_level_modules(self) -> Collection[str]:
462+
modules = set()
463+
for type_ in self._manifest:
464+
for path, _ in self._manifest[type_]:
465+
name, dot, ext = path.parts[0].partition('.')
466+
if dot:
467+
# module
468+
suffix = dot + ext
469+
if suffix in _SUFFIXES:
470+
modules.add(name)
471+
else:
472+
# package
473+
modules.add(name)
474+
return modules
475+
476+
def build(self, directory: Path, source_dir: pathlib.Path, build_dir: pathlib.Path, # type: ignore[override]
477+
build_command: List[str], verbose: bool = False) -> pathlib.Path:
475478

476479
wheel_file = pathlib.Path(directory, f'{self.name}.whl')
477480
with mesonpy._wheelfile.WheelFile(wheel_file, 'w') as whl:
@@ -486,7 +489,7 @@ def build_editable(self, directory: Path, source_dir: pathlib.Path, build_dir: p
486489
f'{loader_module_name}.py',
487490
read_binary('mesonpy', '_editable.py') + textwrap.dedent(f'''
488491
install(
489-
{self.top_level_modules!r},
492+
{self._top_level_modules!r},
490493
{os.fspath(build_dir)!r},
491494
{build_command!r},
492495
{verbose!r},
@@ -882,14 +885,14 @@ def sdist(self, directory: Path) -> pathlib.Path:
882885
def wheel(self, directory: Path) -> pathlib.Path:
883886
"""Generates a wheel in the specified directory."""
884887
self.build()
885-
builder = _WheelBuilder(self._metadata, self._manifest, self._is_pure, self._limited_api)
888+
builder = _WheelBuilder(self._metadata, self._manifest, self._limited_api)
886889
return builder.build(directory)
887890

888891
def editable(self, directory: Path) -> pathlib.Path:
889892
"""Generates an editable wheel in the specified directory."""
890893
self.build()
891-
builder = _WheelBuilder(self._metadata, self._manifest, self._is_pure, self._limited_api)
892-
return builder.build_editable(directory, self._source_dir, self._build_dir, self._build_command, self._editable_verbose)
894+
builder = _EditableWheelBuilder(self._metadata, self._manifest, self._limited_api)
895+
return builder.build(directory, self._source_dir, self._build_dir, self._build_command, self._editable_verbose)
893896

894897

895898
@contextlib.contextmanager

tests/test_wheel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ def test_entrypoints(wheel_full_metadata):
232232

233233
def test_top_level_modules(package_module_types):
234234
with mesonpy._project() as project:
235-
builder = mesonpy._WheelBuilder(project._metadata, project._manifest, project._is_pure, project._limited_api)
236-
assert set(builder.top_level_modules) == {
235+
builder = mesonpy._EditableWheelBuilder(project._metadata, project._manifest, project._limited_api)
236+
assert set(builder._top_level_modules) == {
237237
'file',
238238
'package',
239239
'namespace',

0 commit comments

Comments
 (0)