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

Refactor get_builder_dt legacy to be explicit #288

Merged
merged 1 commit into from
Dec 4, 2017

Conversation

nicain
Copy link
Contributor

@nicain nicain commented Nov 30, 2017

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?

make test

Checklist

  • Have you checked our Contributing document?
  • Have you ensured the PR description clearly describes problem and the solution?
  • Is your contribution compliant with our coding style ? This can be checked running flake8 from the source directory.
  • Have you checked to ensure that there aren't other open Pull Requests for the same change?
  • Have you included the relevant issue number using #XXX notation where XXX is the issue number ?

@nicain nicain requested a review from neuromusic November 30, 2017 02:04
@pep8speaks
Copy link

pep8speaks commented Nov 30, 2017

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 nicain removed the request for review from neuromusic November 30, 2017 02:16
@jcfr
Copy link
Collaborator

jcfr commented Nov 30, 2017

@nicain you could also run flake8 locally to find out about the error.

When addressed, please consider squashing all the commits together.

@nicain
Copy link
Contributor Author

nicain commented Nov 30, 2017

@jcfr I think I have finally figured out how to do that :) Ill add you as a reviewer too.

@nicain nicain requested review from neuromusic and jcfr November 30, 2017 02:21
@nicain
Copy link
Contributor Author

nicain commented Nov 30, 2017

@jcfr OK, flake is complaining about "./src/pynwb/legacy/map.py:26:5: C901 'TypeMapLegacy.get_builder_dt' is too complex (23)"
I want to tell it, well, you should have seen it before! Any thoughts on the refactor? at least its PEP8 compliant...

BTW running flake8 on my dev machine gives > 6000 problems. Is there any way to only run it on the diff?

@jcfr
Copy link
Collaborator

jcfr commented Nov 30, 2017

@jcfr OK, flake is complaining about "./src/pynwb/legacy/map.py:26:5: C901 'TypeMapLegacy.get_builder_dt' is too complex (23)"

If the complexity is legitimate, you can add a comment like this one:

def get_builder_dt(self, builder):  # noqa: C901

running flake8 on my dev machine gives > 6000 problems

This is strange.

Could you confirm you do something like this:

cd /home/jcfr/Projects/pynwb
workon pyenv-py35
flake8
# => No error report

Could you also check you have the latest version of flake8 ?

@@ -25,54 +25,93 @@ class TypeMapLegacy(TypeMap):

def get_builder_dt(self, builder):
Copy link
Collaborator

@jcfr jcfr Nov 30, 2017

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':
Copy link
Collaborator

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) ?

Copy link
Contributor Author

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':
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above

return None
else:
return 'PlaneSegmentation'

raise Exception
Copy link
Collaborator

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

@nicain
Copy link
Contributor Author

nicain commented Nov 30, 2017

Addressing @jcfr:

  • [x]: Using flake8 locally before push (failure in my dev env due to my .history dir not being --excluded)
  • [x]: Using # noqa: C901 to skip complexity check (complexity is legitimate)
  • [x]: Added docstring
  • [x]: Exception --> RuntimeError
  • [x]: Squashed commit history

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.
'''
Copy link
Collaborator

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 '''

Copy link
Collaborator

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

jcfr
jcfr previously approved these changes Nov 30, 2017
Copy link
Collaborator

@jcfr jcfr left a 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

@nicain
Copy link
Contributor Author

nicain commented Nov 30, 2017

@dorukozturk @jcfr Need a little help here. Travis is complaining about:

The command "pip install -U scikit-ci-addons" failed and exited with 127 during .

, and appveyor hasen't even started after 16 hours. Is there something I did, or a misconfiguration somewhere?

@dorukozturk
Copy link
Contributor

@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. :)

@jcfr
Copy link
Collaborator

jcfr commented Nov 30, 2017

travis

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-io
Copy link

codecov-io commented Dec 1, 2017

Codecov Report

Merging #288 into dev will decrease coverage by 0.24%.
The diff coverage is 2.12%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#form 42.6% <2.12%> (-0.25%) ⬇️
#integration 42.6% <2.12%> (-0.25%) ⬇️
#pynwb 42.6% <2.12%> (-0.25%) ⬇️
Impacted Files Coverage Δ
src/pynwb/legacy/map.py 12.12% <2.12%> (-3.88%) ⬇️
src/pynwb/form/utils.py 72.91% <0%> (-0.7%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 216cbb3...bf386b3. Read the comment docs.

@dorukozturk
Copy link
Contributor

@nicain Let's merge this. There is a major issue with pyenv on travis right now (see this). I will be watching the travis issue and fix it later.

PEP8 compliance

PEP8 compliance

Add docstring. flake8 complexity skip. meaningful RuntimeError
@nicain
Copy link
Contributor Author

nicain commented Dec 4, 2017

@jcfr Great. I just rebased, incorporating #292. Assuming all but travis passes, please merge.

@nicain
Copy link
Contributor Author

nicain commented Dec 4, 2017

@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?

@dorukozturk
Copy link
Contributor

@nicain Appveyor let us do 1 build at a time. Since I merged another branch, it was running the master first. Your PR is currently running see this.

@dorukozturk dorukozturk merged commit 6437c10 into NeurodataWithoutBorders:dev Dec 4, 2017
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.

5 participants