Skip to content

Commit 3ac77e9

Browse files
committed
demo_pkg_inline.build: PEP 517, respect the metadata_directory
If the caller provides a metadata_directory, then put the contents into the wheel (instead of the hardcoded metadata in the module). From pyproject-api with modifications: * correct the order of the `build_wheel` arguments according to PEP 517 to work correctly with pyproject_hooks * remove unnecessary `dedent` calls (these are applied during build)
1 parent 23510dc commit 3ac77e9

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

tests/demo_pkg_inline/build.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
record = "{}/RECORD".format(dist_info)
2222
content = {
2323
logic: "def do():\n print('greetings from {}')".format(name),
24-
plugin: dedent(
25-
"""
24+
plugin: """
2625
try:
2726
from tox.plugin import impl
2827
from tox.tox_env.python.virtual_env.runner import VirtualEnvRunner
@@ -37,14 +36,13 @@ def id() -> str:
3736
@impl
3837
def tox_register_tox_env(register: ToxEnvRegister) -> None:
3938
register.add_run_env(ExampleVirtualEnvRunner)
40-
""",
41-
),
42-
entry_points: dedent(
43-
"""
39+
""",
40+
}
41+
metadata_files = {
42+
entry_points: """
4443
[tox]
4544
example = {}.example_plugin""".format(
46-
name,
47-
),
45+
name,
4846
),
4947
metadata: """
5048
Metadata-Version: 2.1
@@ -88,12 +86,22 @@ def tox_register_tox_env(register: ToxEnvRegister) -> None:
8886
}
8987

9088

91-
def build_wheel(wheel_directory, metadata_directory=None, config_settings=None): # noqa: U100
89+
def build_wheel(wheel_directory, config_settings=None, metadata_directory=None): # noqa: U100
9290
base_name = "{}-{}-py{}-none-any.whl".format(name, version, sys.version_info[0])
9391
path = os.path.join(wheel_directory, base_name)
9492
with ZipFile(path, "w") as zip_file_handler:
9593
for arc_name, data in content.items(): # pragma: no branch
9694
zip_file_handler.writestr(arc_name, dedent(data).strip())
95+
if metadata_directory is not None:
96+
for sub_directory, _, filenames in os.walk(metadata_directory):
97+
for filename in filenames:
98+
zip_file_handler.write(
99+
os.path.join(metadata_directory, sub_directory, filename),
100+
os.path.join(sub_directory, filename),
101+
)
102+
else:
103+
for arc_name, data in metadata_files.items(): # pragma: no branch
104+
zip_file_handler.writestr(arc_name, dedent(data).strip())
97105
print("created wheel {}".format(path))
98106
return base_name
99107

0 commit comments

Comments
 (0)