Additionally expose multidict as a Cython importable#1178
Additionally expose multidict as a Cython importable#1178Vizonex wants to merge 88 commits intoaio-libs:masterfrom Vizonex:Cython-Compatability
Conversation
|
FYI, we got rid of Cython in #249 |
There was a problem hiding this comment.
This is where you can see a preview of how this change note is rendered: https://multidict--1178.org.readthedocs.build/en/1178/changes/. Alternatively, if you want to build the docs locally, it'll also include draft/unreleased notes.
| """Get multidict headers for compiling multidict with other | ||
| C Extensions or cython code""" |
There was a problem hiding this comment.
This doesn't seem PEP 257-compliant. Could you organize it as a summary line and a separate description?
There was a problem hiding this comment.
Sure let me do so here in a bit I just woke up.
| # NOTE: Import pathlib later so that were not being slow during | ||
| # other use-cases | ||
| import pathlib |
There was a problem hiding this comment.
I'm not sure if this is worth breaking the style for. Most people's apps would be importing pathlib anyway. So in real world, it'll likely be cached by the time multidict is imported.
|
|
||
| upstr = istr | ||
|
|
||
| # Inspired by Numpy |
There was a problem hiding this comment.
Is this a comment for get_include()? Why is it several lines away from it? Code comments should be next to things they reference (ideally on the same line) so they don't drift even further away over time. Additionally, code comments should provide useful context that is otherwise unobvious, using complete sentenced (it is confusing to have 3 arbitrary words on a separate line without any other context that would at least seem related).
If you took this idea from elsewhere, it's of course good to give credit. But please also explain what the idea is in the first place.
| # other use-cases | ||
| import pathlib | ||
|
|
||
| return str(pathlib.Path(__file__).parent) |
There was a problem hiding this comment.
Honestly, I'd avoid string-based path APIs. In Python, it's best to always use pathlib objects up until the point where strings are needed to interface with external systems. I think it's best to just return a pathlib object and let the caller convert it however they prefer. Maybe also .resolve() it before returning for a good measure.
There was a problem hiding this comment.
The function returns a value that should be added to a configuration, e.g. as -I cmdline option.
It's not a path to operate on; it's always processed as a string.
.resolve makes sense, though.
There was a problem hiding this comment.
I think it's not obvious to me (or probably @webknjaz) what the purpose of this function is? Is this some sort of standard interface to something?
It's not called anywhere in this PR and it's being exported as a public function. The docstring says it gets headers, but it appears to just return the path that multidict is installed in. Do people need this function, when they can just do multidict.__path__?
There was a problem hiding this comment.
@Dreamsorcerer good question.
I guess it could be used as Extension argument for third-party C extensions:
setup(...,
extensions=[Extension(..., include_dirs=multidict.get_include())])
The same could be applied to third-party Cython extensions
multidict.__path__ could do the same, probably. I have no strong preference.
There was a problem hiding this comment.
Also, with the headers not being installed, is this unusable right now?
There was a problem hiding this comment.
Also, with the headers not being installed, is this unusable right now?
I think I solved that by editing manifest.in recently.
There was a problem hiding this comment.
That only governs what's included into sdists.
| { | ||
| return PyModuleDef_Init(&multidict_module); | ||
| } | ||
|
|
There was a problem hiding this comment.
accidental trailing line?
| return 0; | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
Looks like other sections follow a single-line separator convention between function definitions, only using double-lines where those sections end.
Regardless, we shouldn't include unrelated formatting because it surfaces arbitrary chunks of code in the PR diff.
FYI, #1123 proposes plugging a code formatter for C. If you'd like to work on it, this would solve the problem of accidentally changing things in PRs. And it'd be useful to all of us in general.
| -r towncrier.txt | ||
| -r doc.txt | ||
| pyperformance==1.11.0 | ||
| cython==3.1.2 |
There was a problem hiding this comment.
Why is this needed? Where is it used?
There was a problem hiding this comment.
@webknjaz A little bit outdated but the plan was to use it for a cython test to ensure that the inner c-api to and from cython works correctly.
There was a problem hiding this comment.
Then put it into ci.txt and add a code comment that it's for capsule testing.
|
I'm stumped on writing the workflow to compiling the _multidict_cython test module that I wrote so I will simply wait for help. |
webknjaz
left a comment
There was a problem hiding this comment.
There's a lot of cleaning to be done before this is mergeable. I marked some places related to what we talked about on matrix.
| graft tests | ||
| global-exclude *.pyc | ||
| include multidict/*.c | ||
| include multidict/_multilib/*.h |
There was a problem hiding this comment.
This adds the file to sdist. You may have to include it into wheels too.
There was a problem hiding this comment.
I will make sure I do so. Thanks for reminding me about wheels. I will get that done after I write some new documentation for using multidict with cython.
| # other use-cases | ||
| import pathlib | ||
|
|
||
| return str(pathlib.Path(__file__).parent) |
There was a problem hiding this comment.
That only governs what's included into sdists.
| -r towncrier.txt | ||
| -r doc.txt | ||
| pyperformance==1.11.0 | ||
| cython==3.1.2 |
There was a problem hiding this comment.
Then put it into ci.txt and add a code comment that it's for capsule testing.
There was a problem hiding this comment.
We should stop putting arbitrary artifacts into the test dir root. Ideally, they should just be generated and put into tmp dir. Or at least into a subdir.
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
for more information, see https://pre-commit.ci
|
Good news is that I did figure out that setuptools has no way to compile something without the setup portion so I came up with a workaround for it, cythonize was also pretty vague about this so that route turned out to just be a dead-end. |
for more information, see https://pre-commit.ci
…tidict into Cython-Compatability
for more information, see https://pre-commit.ci
|
Moved to #1183 I will be using this information I got from this one to help me later. |
What do these changes do?
These changes add a new C-API for Cython support with multidict. This is my second attempt at getting this passed but this time I've added everything in to ensure a smooth pull request.
What I will mainly need help with is figuring out are the following parts
Are there changes in behavior for the user?
Users could now import multidict as a cython library which is something not very commonly seen I also added a get_include function for finding the multidict C Headers, will have to start including them for now on so that users will be able to compile them to cython or other C/C++ Apis.
Related issue number
Checklist