Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add a PlatformModule type #1461

Merged
merged 3 commits into from Apr 14, 2023
Merged

Conversation

hoodmane
Copy link
Contributor

@hoodmane hoodmane commented Apr 7, 2023

This avoids the repetition of the platform checks in main.py by defining a dataclass with get_python_configurations and build.

@hoodmane
Copy link
Contributor Author

Could someone merge this?

This avoids the repetition of the platform checks in __main__.py
by defining a dataclass with `get_python_configurations` and `build`.
@joerick
Copy link
Contributor

joerick commented Apr 10, 2023

I've just been playing with this and I think it would be simpler to use the module itself as the 'interface' object. We can type it with a Protocol I believe, like so

class PlatformModule(typing.Protocol):
    # note that as per PEP544, the self argument is ignored when the protocol
    # is applied to a module
    def get_python_configurations(self, build_selector: BuildSelector, architectures: Set[Architecture]) -> typing.Sequence[GenericPythonConfiguration]:
        ...
    def build(self, options: Options, tmp_path: Path) -> None:
        ...

cibuildwheel/__main__.py Outdated Show resolved Hide resolved
@joerick
Copy link
Contributor

joerick commented Apr 10, 2023

I have a version that looks to be working locally, I can push here if you like?

@joerick
Copy link
Contributor

joerick commented Apr 10, 2023

I'm off to bed so I've pushed that, hope that's okay. I think it's a bit simpler without the extra object.


def get_platform_module(platform: PlatformName) -> PlatformModule:
if platform == "linux":
return cibuildwheel.linux
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I did not realize you could do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I tried, I left out the self parameter and got complaints.

@joerick joerick changed the title chore: Add a platform_interface type to export from each platform chore: Add a PlatformModule type to export from each platform Apr 14, 2023
@joerick joerick changed the title chore: Add a PlatformModule type to export from each platform chore: Add a PlatformModule type Apr 14, 2023
@joerick joerick merged commit 7c9b837 into pypa:main Apr 14, 2023
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants