-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Add option to document properties using autoproperty instead of autoattribute #197
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6077184
Modify to allow for autoproperty
WilliamJamieson 53499bb
Add property-attribute tests to current test case
WilliamJamieson 80641ef
Add test case that mixes attributes with properties
WilliamJamieson 84ee7c1
Update documentation with new option
WilliamJamieson 09aeffb
Add changelog entry
WilliamJamieson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,11 @@ class members that are inherited from a base class. This value can be | |
methods like ``__getitem__`` and ``__setitem__``. Defaults to | ||
``['__init__', '__call__']``. | ||
|
||
* ``automodsumm_properties_are_attributes`` | ||
Should be a bool and if ``True`` properties are treated as attributes in the | ||
documentation meaning that no property specific documentation is generated. | ||
Defaults to ``True``. | ||
|
||
.. _sphinx.ext.autosummary: http://sphinx-doc.org/latest/ext/autosummary.html | ||
.. _autosummary: http://sphinx-doc.org/latest/ext/autosummary.html#directive-autosummary | ||
|
||
|
@@ -321,7 +326,8 @@ def process_automodsumm_generation(app): | |
lines, sfn, app=app, builder=app.builder, | ||
base_path=app.srcdir, | ||
inherited_members=app.config.automodsumm_inherited_members, | ||
included_members=app.config.automodsumm_included_members) | ||
included_members=app.config.automodsumm_included_members, | ||
properties_are_attributes=app.config.automodsumm_properties_are_attributes) | ||
|
||
|
||
# _automodsummrex = re.compile(r'^(\s*)\.\. automodsumm::\s*([A-Za-z0-9_.]+)\s*' | ||
|
@@ -462,7 +468,8 @@ def generate_automodsumm_docs(lines, srcfn, app=None, suffix='.rst', | |
base_path=None, builder=None, | ||
template_dir=None, | ||
inherited_members=False, | ||
included_members=('__init__', '__call__')): | ||
included_members=('__init__', '__call__'), | ||
*, properties_are_attributes=True): | ||
""" | ||
This function is adapted from | ||
`sphinx.ext.autosummary.generate.generate_autosummmary_docs` to | ||
|
@@ -595,10 +602,10 @@ def get_members_class(obj, typ, include_public=[], | |
continue | ||
if typ is None or documenter.objtype == typ: | ||
items.append(name) | ||
elif typ == 'attribute' and documenter.objtype == 'property': | ||
# In Sphinx 2.0 and above, properties have a separate | ||
# objtype, but we treat them the same here. | ||
items.append(name) | ||
# elif typ == 'attribute' and documenter.objtype == 'property': | ||
# # In Sphinx 2.0 and above, properties have a separate | ||
# # objtype, but we treat them the same here. | ||
# items.append(name) | ||
public = [x for x in items | ||
if x in include_public or not x.startswith('_')] | ||
return public, items | ||
|
@@ -629,6 +636,15 @@ def get_members_class(obj, typ, include_public=[], | |
ns['attributes'], ns['all_attributes'] = \ | ||
get_members_class(obj, 'attribute', | ||
include_base=include_base) | ||
public_properties, all_properties = \ | ||
get_members_class(obj, 'property', | ||
include_base=include_base) | ||
if properties_are_attributes: | ||
ns['attributes'].extend(public_properties) | ||
ns['all_attributes'].extend(all_properties) | ||
else: | ||
ns['properties'] = public_properties | ||
ns['all_properties'] = all_properties | ||
Comment on lines
+639
to
+647
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the real change. |
||
ns['methods'].sort() | ||
ns['attributes'].sort() | ||
|
||
|
@@ -703,6 +719,7 @@ def setup(app): | |
app.add_config_value('automodsumm_inherited_members', False, 'env') | ||
app.add_config_value( | ||
'automodsumm_included_members', ['__init__', '__call__'], 'env') | ||
app.add_config_value('automodsumm_properties_are_attributes', True, 'env') | ||
|
||
return {'parallel_read_safe': True, | ||
'parallel_write_safe': True} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions
27
...pi/sphinx_automodapi.tests.example_module.abstract_classes.SequenceSubclass.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
SequenceSubclass | ||
================ | ||
|
||
.. currentmodule:: sphinx_automodapi.tests.example_module.abstract_classes | ||
|
||
.. autoclass:: SequenceSubclass | ||
:show-inheritance: | ||
|
||
.. rubric:: Attributes Summary | ||
|
||
.. autosummary:: | ||
|
||
~SequenceSubclass.my_property | ||
|
||
.. rubric:: Methods Summary | ||
|
||
.. autosummary:: | ||
|
||
~SequenceSubclass.my_method | ||
|
||
.. rubric:: Attributes Documentation | ||
|
||
.. autoproperty:: my_property | ||
|
||
.. rubric:: Methods Documentation | ||
|
||
.. automethod:: my_method |
19 changes: 19 additions & 0 deletions
19
sphinx_automodapi/tests/cases/abstract_classes/output_prop_is_not_attr/index.rst.automodapi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
sphinx_automodapi.tests.example_module.abstract_classes Module | ||
-------------------------------------------------------------- | ||
|
||
.. automodule:: sphinx_automodapi.tests.example_module.abstract_classes | ||
|
||
Classes | ||
^^^^^^^ | ||
|
||
.. automodsumm:: sphinx_automodapi.tests.example_module.abstract_classes | ||
:classes-only: | ||
:toctree: api | ||
|
||
Class Inheritance Diagram | ||
^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. automod-diagram:: sphinx_automodapi.tests.example_module.abstract_classes | ||
:private-bases: | ||
:parts: 1 |
6 changes: 6 additions & 0 deletions
6
sphinx_automodapi/tests/cases/abstract_classes/output_prop_is_not_attr/index.rst.automodsumm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.. currentmodule:: sphinx_automodapi.tests.example_module.abstract_classes | ||
|
||
.. autosummary:: | ||
:toctree: api | ||
|
||
SequenceSubclass |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions
29
...ames/output_prop_is_not_attr/api/sphinx_automodapi.tests.example_module.Egg.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Egg | ||
=== | ||
|
||
.. currentmodule:: sphinx_automodapi.tests.example_module | ||
|
||
.. autoclass:: Egg | ||
:show-inheritance: | ||
|
||
.. rubric:: Attributes Summary | ||
|
||
.. autosummary:: | ||
|
||
~Egg.weight | ||
|
||
.. rubric:: Methods Summary | ||
|
||
.. autosummary:: | ||
|
||
~Egg.buy | ||
~Egg.eat | ||
|
||
.. rubric:: Attributes Documentation | ||
|
||
.. autoproperty:: weight | ||
|
||
.. rubric:: Methods Documentation | ||
|
||
.. automethod:: buy | ||
.. automethod:: eat |
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
sphinx_automodapi/tests/cases/allowed_names/output_prop_is_not_attr/index.rst.automodapi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
sphinx_automodapi.tests.example_module Package | ||
---------------------------------------------- | ||
|
||
.. automodule:: sphinx_automodapi.tests.example_module | ||
|
||
Classes | ||
^^^^^^^ | ||
|
||
.. automodsumm:: sphinx_automodapi.tests.example_module | ||
:classes-only: | ||
:toctree: api | ||
:allowed-package-names: sphinx_automodapi.tests.example_module.classes | ||
|
||
Class Inheritance Diagram | ||
^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. automod-diagram:: sphinx_automodapi.tests.example_module | ||
:private-bases: | ||
:parts: 1 | ||
:allowed-package-names: sphinx_automodapi.tests.example_module.classes |
7 changes: 7 additions & 0 deletions
7
sphinx_automodapi/tests/cases/allowed_names/output_prop_is_not_attr/index.rst.automodsumm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.. currentmodule:: sphinx_automodapi.tests.example_module | ||
|
||
.. autosummary:: | ||
:toctree: api | ||
|
||
Egg | ||
Spam |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This example is to make sure that classes can have attributes and properties | ||
and they can be distiguished if ``automodsumm_properties_are_attributes = False`` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.. automodapi:: sphinx_automodapi.tests.example_module.attribute_class |
29 changes: 29 additions & 0 deletions
29
...i/sphinx_automodapi.tests.example_module.attribute_class.ClassWithAttribute.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
ClassWithAttribute | ||
================== | ||
|
||
.. currentmodule:: sphinx_automodapi.tests.example_module.attribute_class | ||
|
||
.. autoclass:: ClassWithAttribute | ||
:show-inheritance: | ||
|
||
.. rubric:: Attributes Summary | ||
|
||
.. autosummary:: | ||
|
||
~ClassWithAttribute.my_attribute | ||
~ClassWithAttribute.my_property | ||
|
||
.. rubric:: Methods Summary | ||
|
||
.. autosummary:: | ||
|
||
~ClassWithAttribute.my_method | ||
|
||
.. rubric:: Attributes Documentation | ||
|
||
.. autoattribute:: my_attribute | ||
.. autoattribute:: my_property | ||
|
||
.. rubric:: Methods Documentation | ||
|
||
.. automethod:: my_method |
19 changes: 19 additions & 0 deletions
19
sphinx_automodapi/tests/cases/attribute_class/output_prop_is_attr/index.rst.automodapi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
sphinx_automodapi.tests.example_module.attribute_class Module | ||
------------------------------------------------------------- | ||
|
||
.. automodule:: sphinx_automodapi.tests.example_module.attribute_class | ||
|
||
Classes | ||
^^^^^^^ | ||
|
||
.. automodsumm:: sphinx_automodapi.tests.example_module.attribute_class | ||
:classes-only: | ||
:toctree: api | ||
|
||
Class Inheritance Diagram | ||
^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. automod-diagram:: sphinx_automodapi.tests.example_module.attribute_class | ||
:private-bases: | ||
:parts: 1 |
6 changes: 6 additions & 0 deletions
6
sphinx_automodapi/tests/cases/attribute_class/output_prop_is_attr/index.rst.automodsumm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.. currentmodule:: sphinx_automodapi.tests.example_module.attribute_class | ||
|
||
.. autosummary:: | ||
:toctree: api | ||
|
||
ClassWithAttribute |
31 changes: 31 additions & 0 deletions
31
...i/sphinx_automodapi.tests.example_module.attribute_class.ClassWithAttribute.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
ClassWithAttribute | ||
================== | ||
|
||
.. currentmodule:: sphinx_automodapi.tests.example_module.attribute_class | ||
|
||
.. autoclass:: ClassWithAttribute | ||
:show-inheritance: | ||
|
||
.. rubric:: Attributes Summary | ||
|
||
.. autosummary:: | ||
|
||
~ClassWithAttribute.my_attribute | ||
|
||
~ClassWithAttribute.my_property | ||
|
||
.. rubric:: Methods Summary | ||
|
||
.. autosummary:: | ||
|
||
~ClassWithAttribute.my_method | ||
|
||
.. rubric:: Attributes Documentation | ||
|
||
.. autoattribute:: my_attribute | ||
|
||
.. autoproperty:: my_property | ||
|
||
.. rubric:: Methods Documentation | ||
|
||
.. automethod:: my_method |
19 changes: 19 additions & 0 deletions
19
sphinx_automodapi/tests/cases/attribute_class/output_prop_is_not_attr/index.rst.automodapi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
sphinx_automodapi.tests.example_module.attribute_class Module | ||
------------------------------------------------------------- | ||
|
||
.. automodule:: sphinx_automodapi.tests.example_module.attribute_class | ||
|
||
Classes | ||
^^^^^^^ | ||
|
||
.. automodsumm:: sphinx_automodapi.tests.example_module.attribute_class | ||
:classes-only: | ||
:toctree: api | ||
|
||
Class Inheritance Diagram | ||
^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. automod-diagram:: sphinx_automodapi.tests.example_module.attribute_class | ||
:private-bases: | ||
:parts: 1 |
6 changes: 6 additions & 0 deletions
6
sphinx_automodapi/tests/cases/attribute_class/output_prop_is_not_attr/index.rst.automodsumm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.. currentmodule:: sphinx_automodapi.tests.example_module.attribute_class | ||
|
||
.. autosummary:: | ||
:toctree: api | ||
|
||
ClassWithAttribute |
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions
29
...put_prop_is_not_attr/api/sphinx_automodapi.tests.example_module.classes.Egg.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Egg | ||
=== | ||
|
||
.. currentmodule:: sphinx_automodapi.tests.example_module.classes | ||
|
||
.. autoclass:: Egg | ||
:show-inheritance: | ||
|
||
.. rubric:: Attributes Summary | ||
|
||
.. autosummary:: | ||
|
||
~Egg.weight | ||
|
||
.. rubric:: Methods Summary | ||
|
||
.. autosummary:: | ||
|
||
~Egg.buy | ||
~Egg.eat | ||
|
||
.. rubric:: Attributes Documentation | ||
|
||
.. autoproperty:: weight | ||
|
||
.. rubric:: Methods Documentation | ||
|
||
.. automethod:: buy | ||
.. automethod:: eat |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should this be removed?