Skip to content

Commit 54e8750

Browse files
committed
Add some missing setuptools command (incl pth file setup for editable wheels aka pep660).
1 parent a73fb89 commit 54e8750

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build-system]
22
requires = [
3-
"setuptools>=30.3.0",
3+
"setuptools>=64",
44
]
55

66
[tool.ruff.per-file-ignores]

setup.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
from os import fspath
66
from pathlib import Path
77

8+
from setuptools import Command
89
from setuptools import find_packages
910
from setuptools import setup
1011
from setuptools.command.develop import develop
1112
from setuptools.command.easy_install import easy_install
13+
from setuptools.command.editable_wheel import editable_wheel
1214
from setuptools.command.install_lib import install_lib
1315

1416
pth_file = Path(__file__).parent.joinpath('src', 'manhole.pth')
@@ -20,6 +22,26 @@ def run(self):
2022
self.copy_file(fspath(pth_file), fspath(Path(self.build_lib, pth_file.name)))
2123

2224

25+
class PTHWheelPiggyback:
26+
def __init__(self, strategy):
27+
self.strategy = strategy
28+
29+
def __enter__(self):
30+
self.strategy.__enter__()
31+
32+
def __exit__(self, exc_type, exc_val, exc_tb):
33+
self.strategy.__exit__(exc_type, exc_val, exc_tb)
34+
35+
def __call__(self, wheel, files, mapping):
36+
self.strategy(wheel, files, mapping)
37+
wheel.writestr(fspath(pth_file.name), pth_file.read_bytes())
38+
39+
40+
class EditableWheelWithPTH(editable_wheel):
41+
def _select_strategy(self, dist_name, tag, lib):
42+
return PTHWheelPiggyback(super()._select_strategy(dist_name, tag, lib))
43+
44+
2345
class EasyInstallWithPTH(easy_install):
2446
def run(self, *args, **kwargs):
2547
super().run(*args, **kwargs)
@@ -43,6 +65,21 @@ def run(self):
4365
self.copy_file(fspath(pth_file), str(Path(self.install_dir, pth_file.name)))
4466

4567

68+
class GeneratePTH(Command):
69+
user_options = [] # noqa: RUF012
70+
71+
def initialize_options(self):
72+
pass
73+
74+
def finalize_options(self):
75+
pass
76+
77+
def run(self):
78+
with pth_file.open('w') as fh:
79+
with pth_file.with_suffix('.embed').open() as sh:
80+
fh.write(f"import os, sys;exec({sh.read().replace(' ', ' ')!r})")
81+
82+
4683
def read(*names, **kwargs):
4784
with Path(__file__).parent.joinpath(*names).open(encoding=kwargs.get('encoding', 'utf8')) as fh:
4885
return fh.read()
@@ -118,5 +155,7 @@ def read(*names, **kwargs):
118155
'easy_install': EasyInstallWithPTH,
119156
'install_lib': InstallLibWithPTH,
120157
'develop': DevelopWithPTH,
158+
'editable_wheel': EditableWheelWithPTH,
159+
'genpth': GeneratePTH,
121160
},
122161
)

0 commit comments

Comments
 (0)