-
Notifications
You must be signed in to change notification settings - Fork 86
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
Refactor get_builder_dt legacy to be explicit #288
Conversation
Hello @nicain! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on December 04, 2017 at 20:08 Hours UTC |
@nicain you could also run When addressed, please consider squashing all the commits together. |
@jcfr I think I have finally figured out how to do that :) Ill add you as a reviewer too. |
@jcfr OK, flake is complaining about "./src/pynwb/legacy/map.py:26:5: C901 'TypeMapLegacy.get_builder_dt' is too complex (23)" BTW running flake8 on my dev machine gives > 6000 problems. Is there any way to only run it on the diff? |
If the complexity is legitimate, you can add a comment like this one:
This is strange. Could you confirm you do something like this:
Could you also check you have the latest version of flake8 ? |
src/pynwb/legacy/map.py
Outdated
@@ -25,54 +25,93 @@ class TypeMapLegacy(TypeMap): | |||
|
|||
def get_builder_dt(self, builder): |
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.
Add a docstring explaining what the function do. One sentence is good enough
attrs = builder.attributes | ||
ndt = attrs.get('neurodata_type') | ||
|
||
if ndt == 'Module': |
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.
To reduce the complexity, consider adding a function named _get_builder_dt_from_neurodata_type(neurodata_type, attrs) ?
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 want to keep the functionality as parallel to src/form/build/map.py::get_builder_dt, so I would prefer to use noqa: C901 unless you really think it is unreable w/o a refactor.
return 'ImageSeries' | ||
else: | ||
return ancestry | ||
elif ndt == 'Custom': |
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.
And may be a function named def get_builder_type_from_custom_neurodata_type
or similar name.
That said, it is also nice to have all type handling in one function, and add the noqa
exception can be legitimate.
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.
same as above
src/pynwb/legacy/map.py
Outdated
return None | ||
else: | ||
return 'PlaneSegmentation' | ||
|
||
raise Exception |
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.
Avoid generic Exception. Choose from an existing specialized exception RuntimeError
or similar . Make also sure to associate a descriptive message
Addressing @jcfr:
|
For a given builder, return the neurodata_type. In this legacy | ||
TypeMap, the builder may have out-of-spec neurodata_type; this | ||
function coerces this to a 2.0 compatible version. | ||
''' |
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.
One last nitpick: Prefer """
instead of '''
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.
Or for consistency, we can update all docstring in a later commit
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.
Assuming CI returns green, LGTM
@dorukozturk @jcfr Need a little help here. Travis is complaining about:
, and appveyor hasen't even started after 16 hours. Is there something I did, or a misconfiguration somewhere? |
@nicain I can take a look at travis. I don't know about appveyor though. It looks like lot of things got queued. I canceled some of them, I hope that helps. BTW definitely not something you did. :) |
Probably related to https://blog.travis-ci.com/2017-11-21-xcode8-3-default-image-announce I submitted a PR on a different project to try something. Let's monitor how it goes. See scikit-build/scikit-ci-addons@ee5143d |
Codecov Report
@@ Coverage Diff @@
## dev #288 +/- ##
=========================================
- Coverage 42.84% 42.6% -0.25%
=========================================
Files 35 35
Lines 3622 3638 +16
Branches 719 727 +8
=========================================
- Hits 1552 1550 -2
- Misses 1931 1948 +17
- Partials 139 140 +1
Continue to review full report at Codecov.
|
PEP8 compliance PEP8 compliance Add docstring. flake8 complexity skip. meaningful RuntimeError
@dorukozturk I clicked in on the appveyor check, and it reports jobs that have been queued for 5 days and targeting commit f960403, not bf386b3 (the current head to be merged in). I wonder if that frozen state that appveyor helped you fix last week is somehow not getting applied to this PR. Either way, it looks like this check needs to be restarted. Can you take a look? |
Motivation
Resolves #258
Debugging and developing legacy files (for example #275) is difficult because the code paths that legacy/map.py::get_builder_dt.py can take are very complicated. This commit refactors this function, to make its behavior explicit and (relatively) easy.
How to test the behavior?
Checklist
flake8
from the source directory.#XXX
notation whereXXX
is the issue number ?