diff --git a/pyproject.toml b/pyproject.toml index 06d30b4..ecb5180 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] requires = [ - "setuptools>=30.3.0", + "setuptools>=64", ] [tool.ruff.per-file-ignores] diff --git a/setup.py b/setup.py index 7120747..4663f6d 100755 --- a/setup.py +++ b/setup.py @@ -5,10 +5,12 @@ from os import fspath from pathlib import Path +from setuptools import Command from setuptools import find_packages from setuptools import setup from setuptools.command.develop import develop from setuptools.command.easy_install import easy_install +from setuptools.command.editable_wheel import editable_wheel from setuptools.command.install_lib import install_lib pth_file = Path(__file__).parent.joinpath('src', 'manhole.pth') @@ -20,6 +22,26 @@ def run(self): self.copy_file(fspath(pth_file), fspath(Path(self.build_lib, pth_file.name))) +class PTHWheelPiggyback: + def __init__(self, strategy): + self.strategy = strategy + + def __enter__(self): + self.strategy.__enter__() + + def __exit__(self, exc_type, exc_val, exc_tb): + self.strategy.__exit__(exc_type, exc_val, exc_tb) + + def __call__(self, wheel, files, mapping): + self.strategy(wheel, files, mapping) + wheel.writestr(fspath(pth_file.name), pth_file.read_bytes()) + + +class EditableWheelWithPTH(editable_wheel): + def _select_strategy(self, dist_name, tag, lib): + return PTHWheelPiggyback(super()._select_strategy(dist_name, tag, lib)) + + class EasyInstallWithPTH(easy_install): def run(self, *args, **kwargs): super().run(*args, **kwargs) @@ -43,6 +65,21 @@ def run(self): self.copy_file(fspath(pth_file), str(Path(self.install_dir, pth_file.name))) +class GeneratePTH(Command): + user_options = [] # noqa: RUF012 + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self): + with pth_file.open('w') as fh: + with pth_file.with_suffix('.embed').open() as sh: + fh.write(f"import os, sys;exec({sh.read().replace(' ', ' ')!r})") + + def read(*names, **kwargs): with Path(__file__).parent.joinpath(*names).open(encoding=kwargs.get('encoding', 'utf8')) as fh: return fh.read() @@ -118,5 +155,7 @@ def read(*names, **kwargs): 'easy_install': EasyInstallWithPTH, 'install_lib': InstallLibWithPTH, 'develop': DevelopWithPTH, + 'editable_wheel': EditableWheelWithPTH, + 'genpth': GeneratePTH, }, )