Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Convert ft2font extension to pybind11#28785

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ianthomas23 merged 5 commits intomatplotlib:mainfromQuLogic:ft2font-pybind11
Sep 18, 2024

Conversation

QuLogic
Copy link
Member

PR summary

Unlike#9763, this is not a full rewrite, but more of a refactor. There may be further cleanup possible in the future, but this is somewhat large enough already.

PR checklist

@QuLogicQuLogic mentioned this pull requestSep 6, 2024
13 tasks
@tacaswelltacaswell added the CI: Run cibuildwheelRun wheel building tests on a PR labelSep 6, 2024
@tacaswelltacaswell added this to thev3.10.0 milestoneSep 6, 2024
@github-actionsgithub-actionsbot removed the CI: Run cibuildwheelRun wheel building tests on a PR labelSep 7, 2024
@QuLogic
Copy link
MemberAuthor

I do not understand the remaining stubtest failures;_tri is similar and doesn't complain about metaclasses (is it because it's private?).

I'm also not sure what to do aboutGlyph; we formerly did not define a constructor so that it couldn't be created from Python and so does this PR, but stubtest seems to be indicating that pybind11 created one anyway?

@ksunden
Copy link
Member

Okay, so on current main,Glyph is not accessible as a class at all in python (i.e. itAttributeErrors if you try)

The methods which return a Glyph do work, and return something that the repr says it should be atmatplotlib.ft2font.Glyph, but no such class actually exists in python-land.

This PR changes that such that the Python classdoes exist.

As for the metaclass, my guess is that that is effectively the same problem.

My leaning would be go ahead and add a constructor, it doesn't hurt anything and may solve these issues. That or see if you can omit Glyph from the PYMODULE and it just works.

I'm not sure why stubtest was not erroring about the class not existing at runtime previously, but it wasn't.

The type hints see no__init__ as inheritingobject's init. Not sure what pybind is doing, but it does seem like there is a default*args, **kwargs added.

@github-actionsgithub-actionsbot added the Documentation: buildbuilding the docs labelSep 10, 2024
@QuLogicQuLogicforce-pushed theft2font-pybind11 branch 2 times, most recently from408b128 to2079fc8CompareSeptember 10, 2024 08:22
@QuLogic
Copy link
MemberAuthor

ForGlyph, I set the module tonullptr and unexpectedly that worked, and didn't seem to break anything.

For the metaclass, I addedBuffer and that seems to have fixed it locally. But it seems__buffer__ is only part of 3.12+ with pybind11, so that fails instead.

@QuLogicQuLogic added the CI: Run cibuildwheelRun wheel building tests on a PR labelSep 10, 2024
@github-actionsgithub-actionsbot removed the CI: Run cibuildwheelRun wheel building tests on a PR labelSep 10, 2024
@QuLogicQuLogic added the CI: Run cibuildwheelRun wheel building tests on a PR labelSep 10, 2024
Inline `convert_xys_to_array` and modify the arguments to take a C++container, so we don't need a less-safe pointer, and we don't need tocopy another time over.
This allows pybind11 to generate the type hints for us, and it alsotakes care of checking the list and its contents are the right type.
The former is not available on the macOS deployment target we use forwheels. We could revert back to `PyOS_snprintf`, but C++11 contains`snprintf`, and it seems to guarantee the same things.
And also ignore the `numpy.float64` reference. The latter seems to bebroken since Sphinx tries to auto-link type hints as `py:class`, butit's an alias in NumPy making it a `py:attr` in their inventory.
@github-actionsgithub-actionsbot removed the CI: Run cibuildwheelRun wheel building tests on a PR labelSep 12, 2024
@QuLogicQuLogic added the CI: Run cibuildwheelRun wheel building tests on a PR labelSep 12, 2024
@QuLogic
Copy link
MemberAuthor

ForGlyph, I set the module tonullptr and unexpectedly that worked, and didn't seem to break anything.

Reverted that, since it causes weird results in the docs. NowGlyph has an__init__, but it raises immediately.

@@ -232,23 +215,73 @@ class FT2Font:
def set_text(
self, string: str, angle: float = ..., flags: int = ...
) -> NDArray[np.float64]: ...
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering ifnp.double is the correct return type?

https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.double

From reading the documentation it seems like float64 is an alias for double onsome (probably most though) platforms.

(Not added in the PR, but the missing reference is...)

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Good thought, but unfortunately it doesn't fix the missing reference. It appears that Sphinx doesn't read any.pyi files (which is why most other pages don't have type hint issues), but in this case is seeing something thatpybind11 is generating in the runtime itself.

@ianthomas23
Copy link
Member

I was going to say that we shouldn't need
https://github.com/QuLogic/matplotlib/blob/a0649e792797e16e5c2d84e267c9a848b9905272/src/ft2font_wrapper.cpp#L7
or
https://github.com/QuLogic/matplotlib/blob/a0649e792797e16e5c2d84e267c9a848b9905272/src/ft2font_wrapper.cpp#L958-L964
asft2font_wrapper.cpp doesn't accessnumpy directly but does so viapybind11. Trying this out locally everything builds and runs OK. Then I realised that we could correspondingly remove 'numpy_dep' from
https://github.com/QuLogic/matplotlib/blob/a0649e792797e16e5c2d84e267c9a848b9905272/src/meson.build#L97
but that leads to trouble due to the eventual import ofmplutils.h which does some low-level stuff even though I think we only actually need thekind codes. So I am backing out of all of this in the interests of getting this merged now and dealing with the "everything is now pybind11" cleanup that@QuLogic has mentioned elsewhere.

}

PyFT2Font *self = new PyFT2Font();
self->x = NULL;
Copy link
Member

Choose a reason for hiding this comment

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

Ideally we'd use the C++nullptr instead ofNULL, but as there are a number ofNULLs already in this file let's leave it consistent with that.

@ianthomas23
Copy link
Member

Merging as there are 2 approvals.

I intend to make time to review#27011 sometime in the next week.

@ianthomas23ianthomas23 merged commit9674b53 intomatplotlib:mainSep 18, 2024
56 checks passed
@tacaswell
Copy link
Member

My understanding is that@QuLogic has some follow on work to finish removing our build-time numpy dependency all together.

ianthomas23 reacted with thumbs up emoji

@QuLogicQuLogic deleted the ft2font-pybind11 branchSeptember 18, 2024 19:11
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@oscargusoscargusoscargus left review comments

@tacaswelltacaswelltacaswell approved these changes

@ianthomas23ianthomas23ianthomas23 approved these changes

Assignees
No one assigned
Labels
CI: Run cibuildwheelRun wheel building tests on a PRDocumentation: buildbuilding the docsMaintenancetopic: text/fonts
Projects
None yet
Milestone
v3.10.0
Development

Successfully merging this pull request may close these issues.

5 participants
@QuLogic@ksunden@ianthomas23@tacaswell@oscargus

[8]ページ先頭

©2009-2025 Movatter.jp