seequent / properties

An organizational aid and wrapper for validation and tab completion of class properties/traits.
http://propertiespy.rtfd.org
MIT License
18 stars 9 forks source link

Allow custom module name for a properties.Instance #291

Open jcapriot opened 4 years ago

jcapriot commented 4 years ago

I would like to be able to specify the module name of a properties.Instance property. Sometimes these class reside in a module that does not specifically have documentation of it. This can happen fairly often in a code. For example, see the discretize documentation for the discretize.base.BaseMesh (http://discretize.simpeg.xyz/en/master/api/generated/discretize.base.BaseMesh.html) where the actual module where it is defined is in the discretize.base.base_mesh.BaseMesh (https://github.com/simpeg/discretize/blob/e353fb53ec254aa2a18733679da3fddae71ddbb7/discretize/base/base_mesh.py#L14) However we don't necessarily want that module exposed to the documentation, but would still like to generate automatic links to it from other packages.

The current Instance class will generate a documentation target for the property using instance_class.__module__. https://github.com/seequent/properties/blob/85dccbbd5455e4a34a255f18fbf1db6f71311868/properties/base/instance.py#L183 Which would then fail to find the accurate reference in the documentation.

As far as I know there would be no way to programmatically get where the item was imported through, so I propose adding an optional argument to the properties.Instance class that would hold this module_name.

jcapriot commented 4 years ago

I realize this was late last night, so hopefully I can expand this a little more clearly...

let's say we construct a properties.Instance from a properties.HasProperties class.

prop = properties.Instance('This property has properties', properties.HasProperties) prop.sphinx_class() will evaluate to properties.base.base.HasProperties.

What I would like is for something like: prop = properties.Instance('This property has properties', properties.HasProperties, module_name='properties') in which case prop.sphinx_class() will evaluate to properties.HasProperties.