Skip to content

Commit

Permalink
Build wheel from from dynamically created package via custom build.py (
Browse files Browse the repository at this point in the history
…#629)

Co-authored-by: Agundez, Rodrigo <rodrigo.agundez@dyson.com>
  • Loading branch information
rragundez and Agundez, Rodrigo authored Sep 11, 2023
1 parent 8db9d2f commit 8859499
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/poetry/core/masonry/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import warnings

from collections import defaultdict
from functools import cached_property
from pathlib import Path
from typing import TYPE_CHECKING


if TYPE_CHECKING:
from poetry.core.masonry.utils.module import Module
from poetry.core.poetry import Poetry


Expand Down Expand Up @@ -38,13 +40,18 @@ def __init__(
executable: Path | None = None,
) -> None:
from poetry.core.masonry.metadata import Metadata
from poetry.core.masonry.utils.module import Module

self._poetry = poetry
self._package = poetry.package
self._path: Path = poetry.pyproject_path.parent
self._ignore_packages_formats = ignore_packages_formats
self._excluded_files: set[str] | None = None
self._executable = Path(executable or sys.executable)
self._meta = Metadata.from_package(self._package)

@cached_property
def _module(self) -> Module:
from poetry.core.masonry.utils.module import Module

packages = []
for p in self._package.packages:
Expand All @@ -62,7 +69,7 @@ def __init__(
formats
and self.format
and self.format not in formats
and not ignore_packages_formats
and not self._ignore_packages_formats
):
continue

Expand All @@ -76,21 +83,19 @@ def __init__(
formats
and self.format
and self.format not in formats
and not ignore_packages_formats
and not self._ignore_packages_formats
):
continue

includes.append(include)

self._module = Module(
return Module(
self._package.name,
self._path.as_posix(),
packages=packages,
includes=includes,
)

self._meta = Metadata.from_package(self._package)

@property
def executable(self) -> Path:
return self._executable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os
import shutil


package = "my_package"
source = "src_my_package"


def build() -> None:
if os.path.isdir(package):
shutil.rmtree(package)
shutil.copytree("src_my_package", package)


if __name__ == "__main__":
build()
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[tool.poetry]
name = "my_package"
version = "0.1"
description = "Some description."
authors = [
"Rodrigo Agundez <rragundez@gmail.com>"
]
license = "MIT"
homepage = "https://python-poetry.org/"
packages = [
{ include = "my_package" },
]

build = "build.py"
Empty file.
Empty file.
17 changes: 17 additions & 0 deletions tests/masonry/builders/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,23 @@ def test_wheel_module_src() -> None:
assert "module_src.py" in z.namelist()


def test_wheel_build_script_creates_package() -> None:
module_path = fixtures_dir / "build_script_creates_package"
WheelBuilder.make(Factory().create_poetry(module_path))

# Currently, if a build.py script is used,
# poetry just assumes the most specific tags
whl = next((module_path / "dist").glob("my_package-0.1-*.whl"))

assert whl.exists()

with zipfile.ZipFile(str(whl)) as z:
assert "my_package/__init__.py" in z.namelist()
assert "my_package/foo.py" in z.namelist()

shutil.rmtree(module_path / "my_package")


def test_dist_info_file_permissions() -> None:
module_path = fixtures_dir / "complete"
WheelBuilder.make(Factory().create_poetry(module_path))
Expand Down

0 comments on commit 8859499

Please sign in to comment.