-
Notifications
You must be signed in to change notification settings - Fork 118
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
Reworked the neuron.hclass3
module
#1096
Reworked the neuron.hclass3
module
#1096
Conversation
hclass3
moduleneuron.hclass3
module
Codecov Report
@@ Coverage Diff @@
## master #1096 +/- ##
==========================================
+ Coverage 31.42% 31.47% +0.04%
==========================================
Files 571 572 +1
Lines 108767 108863 +96
==========================================
+ Hits 34182 34261 +79
- Misses 74585 74602 +17
Continue to review full report at Codecov.
|
Regular tests go in |
f8b5966
to
23e3064
Compare
fab6723
to
20a6e95
Compare
thanks @Helveg! 👌 (this is in draft. once ready for review, tag Michael and Robert for the review) |
share/lib/python/neuron/hclass3.py
Outdated
if len(hoc_bases) > 1: | ||
bases = ", ".join(b.__name__) | ||
cname = cls.__name__ | ||
raise TypeError(f"Composition of {bases} HocObjects not allowed in {cname}") |
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.
Note: f-strings require Python 3.6+
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 see... Python 3.5 goes through a different file.
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.
Yea, Python 3.5 or earlier just keeps using the old hclass3.py
file since the required improvements to metaclasses were simply not available in earlier versions, so I kept things the same there.
In order for |
I added tests and make some minor changes such as allowing composition if the HOC type is the same and requiring |
Is this becoming ready? In that case, we can |
It's ready, there's one open action point by @ramcdougal to integrate the benefits of |
There are some CI failures but Github has changed some default CI images yesterday/today. And that's why we have been seeing some random failures. Hopefully this will be fixed in coming days. @ramcdougal : this PR looks good for you as well? |
share/lib/python/Makefile.am
Outdated
@@ -85,4 +86,3 @@ EXTRA_DIST = $(nobase_neuronhomepython_DATA) | |||
# if test $(NRNPYTHON_PYMAJOR) -gt 2 ; then \ | |||
# $(PY2TO3) -w $(DESTDIR)$(neuronhomepythondir) ; \ | |||
# fi | |||
|
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.
nitpick: avoid trivial changes
share/lib/python/neuron/Makefile.am
Outdated
@@ -1,5 +1,3 @@ | |||
## Files which get installed in $(prefix)/share: | |||
|
|||
SUBDIRS = rxd crxd | |||
|
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.
nitpick: avoid trivial changes... in this file especially, there's no need to change this file at all
@Helveg : would love to get this PR ready with 8.0 release. @ramcdougal added comments but I see that those are now marked as resolved as well. Anything else is pending here? 🚀 |
There's still some things to be done, I'll get to that right away! |
🎉 thank you @Helveg ! @alexsavulescu : please cherry-pick this for 8.0! |
* added pyenv's .python-version to gitignore * prevent import py2/3 module in py3/2. removed `exec` wrapper from hclass * Changed comment and removed non-existing `nonlocal_hclass` import * Removed traling whitespaces and double newline at eof * Removed the MetaHocObject metaclass and added `nonlocal_hclass` factory * New `HocBaseObject`; (nonlocal_)hclass uses this new base. * Added dev note to demystify quintessential link between HOC & Python * moved __all__ to PEP8 location * Fixed error with grandchildren of `HocBaseObject` * Apply changes only to Python 3.6+ where metaclass alternative is availbl * fixed import typo * hclass of hoc_type should precede use of hoc.HocObject API's * Fixed usage of module_name * added hclass35.py to Makefile, excessive trailing newlines. * `module` does not exist, see details on mixed approaches in PR#1096 * black formatting & updated hclass2 derived docstrings * Store dummy modules on `neuron` module to better emulate submodules * Add a TypeError if init but not new has been given (see #1129) * Added _pyobj_enabled flag to check whether Python object interface is up * Explicitly defined __new__ for 3.6+ pyobj compatibility * Class composition is allowed if HOC types are the same * added tests for HOC type Python classes, test only in Python 3.6+ * Removed 'super()' call for Python 2 * Revert "added hclass35.py to Makefile, excessive trailing newlines." This reverts commit 080f14a. * Added hclass35 to Makefile * Revert "Removed traling whitespaces and double newline at eof" This reverts commit 046fab4. * Reinstated deprecation messages * Merged hclass and nonlocal_hclass
* added pyenv's .python-version to gitignore * prevent import py2/3 module in py3/2. removed `exec` wrapper from hclass * Changed comment and removed non-existing `nonlocal_hclass` import * Removed traling whitespaces and double newline at eof * Removed the MetaHocObject metaclass and added `nonlocal_hclass` factory * New `HocBaseObject`; (nonlocal_)hclass uses this new base. * Added dev note to demystify quintessential link between HOC & Python * moved __all__ to PEP8 location * Fixed error with grandchildren of `HocBaseObject` * Apply changes only to Python 3.6+ where metaclass alternative is availbl * fixed import typo * hclass of hoc_type should precede use of hoc.HocObject API's * Fixed usage of module_name * added hclass35.py to Makefile, excessive trailing newlines. * `module` does not exist, see details on mixed approaches in PR#1096 * black formatting & updated hclass2 derived docstrings * Store dummy modules on `neuron` module to better emulate submodules * Add a TypeError if init but not new has been given (see #1129) * Added _pyobj_enabled flag to check whether Python object interface is up * Explicitly defined __new__ for 3.6+ pyobj compatibility * Class composition is allowed if HOC types are the same * added tests for HOC type Python classes, test only in Python 3.6+ * Removed 'super()' call for Python 2 * Revert "added hclass35.py to Makefile, excessive trailing newlines." This reverts commit 080f14a. * Added hclass35 to Makefile * Revert "Removed traling whitespaces and double newline at eof" This reverts commit 046fab4. * Reinstated deprecation messages * Merged hclass and nonlocal_hclass
I rewrote the
hclass3
module as it is the most important link and entry-point into thehoc
module for object oriented Python developers that want to understand where their HOC objects are coming from. In its original form this was quite hard to figure out and it was using some outdated/problematic idioms (see #1092, #1094, #1093) mostly only of importance once people start actually creating and inspecting subclasses of the Python interface objects.I unpacked the strings in
hclass2
andhclass3
(closes #1092). I added a factory class that fills in the required class module attributes for inspection (closes #1094). I switched out the localhc
class for a better nonlocalHocBaseObject
that does not require a metaclass (closes #1093) and added a PEP8 compliant__all__
attribute. I also think,hclass3.py
should be renamed to_hclass3.py
as it is an internal interface, but that will be part of another, larger move toward a PEP compliantneuron
package in general ;).(For clarity and PEP compliance I did rename the
.htype
attribute to._hoc_type
, but I think it's only used to pass along the hoc type to the__new__
function anyway)I added RST docstrings to all the function and added a dev comment for anyone that would like to know how their HOC object types are generated. I also made sure that all invalid use of the functions resulted in clear exceptions raised where they occurred.