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
DOC: Add Cython style guideline for DIPY. #1714
Conversation
A very first draft. Somme comments:
Please have your say about them: either that we should incorporate them to the guideline as they are, or that we want to add them with specific changes. One controversial point may be that of the
since my experience writing/reading Cython code is limited. So suggestions for content are welcome.
|
8eea49e
to
118c286
Compare
Codecov Report
@@ Coverage Diff @@
## master #1714 +/- ##
========================================
Coverage ? 84.3%
========================================
Files ? 115
Lines ? 13790
Branches ? 2186
========================================
Hits ? 11625
Misses ? 1656
Partials ? 509 |
Are you proposing to add the style guidelines you pointed to. They seem reasonable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of small comments.
118c286
to
4c13254
Compare
Thanks for the suggestions @matthew-brett ! |
Anyone having the bandwith to comment on the open questions? Thanks. |
4c13254
to
4f6e11c
Compare
Hi @jhlegarreta, Can you rebase your PR ?
I think you can incorporate what you pointed too.
I will try to create a PR on you repo for this point
I am ok with that point. @arokem, @Garyfallidis, any thought? |
4f6e11c
to
a27b8ac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a27b8ac rebased on master and added a few more sections to the guideline based on the link I found.
Some comments inline.
I may find to modify the examples using DIPY's Cython specific code, but the guidelines are already there.
Suggestions, contributions are welcome.
When declaring an error return value with the `except` keyword, use one space on | ||
both sides of the `except`. If in a function definition, there should be no | ||
spaces between the error return value and the colon `:`. Avoid `except *` | ||
unless it is needed for functions returning `void`:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few places where
Avoid `except *` unless it is needed for functions returning `void`:
sentence is not fulfilled in DIPY, e.g. in featurespeed.pyx:53
:
cdef void c_extract(Feature self, Data2D datum, Data2D out) nogil except *:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to look deeper into this rule...
|
||
# Good | ||
<float> i | ||
<void *> s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be subject to some discussion/is may be a matter of tastes. I guess the line cythonutils.pyx:141
memview._data = <char*> calloc(buffer_size, sizeof(float))
was may be not written following any specific guideline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am ok, with this rule, we can update our code on a new PR. Any other thought?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. I'm OK with it. Yes, we should eventually converge to abide by these rules in our Cython code 📘 .
|
||
# Good | ||
cdef int& i | ||
cdef char * s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As said earlier in the PR, personally, I find clearer
cdef int &i
or
cdef char *s
but I am aware this may be controversial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personnally, I prefer just this:
cdef int& i
cdef char* s
I find it clearer because it avoid to mix different type on the same line. I see often this
cdef char *s, k, *p, t
which is confusing (to see 2 declaration types on the same line)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example you pointed would not be allowed according to the Variable declaration
section rules, since pointer variables should dwell on a line of their own 😅 .
Whether the dereference operator goes beside the type or not, as said, is subject to debate. I'd be OK with whatever is decided, would update the PR with it, and would adapt to it in DIPY.
I find that whatever is decided, the Casting
rule/example should also abide by it: i.e. <void *> s
or <void*> s
.
a27b8ac
to
d19163f
Compare
d19163f uses examples directly taken from the DIPY Cython code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update @jhlegarreta, here some quick comment
|
||
# Good | ||
<float> i | ||
<void *> s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am ok, with this rule, we can update our code on a new PR. Any other thought?
|
||
# Good | ||
cdef int& i | ||
cdef char * s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personnally, I prefer just this:
cdef int& i
cdef char* s
I find it clearer because it avoid to mix different type on the same line. I see often this
cdef char *s, k, *p, t
which is confusing (to see 2 declaration types on the same line)
When declaring an error return value with the `except` keyword, use one space on | ||
both sides of the `except`. If in a function definition, there should be no | ||
spaces between the error return value and the colon `:`. Avoid `except *` | ||
unless it is needed for functions returning `void`:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to look deeper into this rule...
ff65019
to
2166e44
Compare
Add Cython style guideline for DIPY. Fixes dipy#583.
2166e44
to
176a3e7
Compare
Travis CI failures are unrelated:
are failing for different reasons unrelated to this topic. I ignore whether these have already been detected. |
Thanks for the rebase @jhlegarreta. |
This is a good first version so I will go ahead and merge it. I will keep #583 open because this guideline needs a bit more work but it can be done on a new PR. Thank @jhlegarreta for introducing this guideline. |
Add Cython style guideline for DIPY.
Fixes #583.