-
-
Notifications
You must be signed in to change notification settings - Fork 45
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 sort option to automodsumm #182
Conversation
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.
Good idea! Some comments inline.
sphinx_automodapi/automodapi.py
Outdated
@@ -67,6 +67,11 @@ | |||
Propagates the ``noindex`` flag to autodoc. Use it to avoid duplicate | |||
objects warnings. | |||
|
|||
* ``:sort:`` | |||
Sort the objects in the module alphabetically. The default is to | |||
sort by the order they appear in the module (as specified by `__all__` |
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.
Looking at the actual code below, I see that without __all__
, our use of dir(module)
automatically sorts things. So, maybe rewrite as
Sort the objects in the module alphabetically also if they are
explicitly given in ``__all__`` (if ``__all__`` is not present, the
objects are found using `dir`, which always gives a sorted list).
Actually, writing this suggests that perhaps the default should be to sort also with __all__
and have a nosort
option. In that case,
Do not sort the objects alphabetically, but use the order given by ``__all__``.
This option has no effect if a module does not have ``__all__``.
But probably what you have makes a bit more sense.
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.
✅
sphinx_automodapi/utils.py
Outdated
@@ -81,6 +81,9 @@ def find_mod_objs(modname, onlylocals=False): | |||
else: | |||
pkgitems = [(k, getattr(mod, k)) for k in dir(mod) if k[0] != '_'] | |||
|
|||
if sort: |
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.
Given that dir
is guaranteed to sort, this could be moved inside the if
statement. (This is true even if __dir__
is defined and returns something unsorted.)
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.
✅
Maybe we should change the option from |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #182 +/- ##
==========================================
+ Coverage 90.24% 90.28% +0.03%
==========================================
Files 28 28
Lines 1179 1204 +25
==========================================
+ Hits 1064 1087 +23
- Misses 115 117 +2 ☔ View full report in Codecov by Sentry. |
We do need to add a test... |
@nstarman , are you still interested in pursuing this? |
Yes. Thanks for putting it back on my radar. |
d259d02
to
e02d4ee
Compare
Hm. Not sure why the test is failing so early. I copied it from a test above! |
I cannot tell why it is failing from the log. You might need to run this test locally and debug. |
I would welcome help on the test suite for this PR. The PR works when tested on Astropy, I just can't wrangle this library's test suite. |
@nstarman - I think I found the problem: you missed how |
Thanks @mhvk! I just cherry-picked your commit from your branch https://github.com/mhvk/sphinx-automodapi/tree/sort-option |
Signed-off-by: nstarman <[email protected]>
Signed-off-by: nstarman <[email protected]>
Signed-off-by: nstarman <[email protected]>
Signed-off-by: nstarman <[email protected]>
Rebased to fix conflict. |
Ping @eteq, I think this is now ready for review! |
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 think this looks all good, but then I looked at it already. The one unfortunate thing about the last commit (mine...) is that it does a lot of unrelated blackening as well - this makes it much harder to review. Could you try adding that commit again without that happening? (I checked, my original commit did not do this). I will make review much easier for @eteq.
Signed-off-by: nstarman <[email protected]> # Conflicts: # sphinx_automodapi/automodsumm.py
Done! Had to google how VSCode can do saving w/out formatting (I have mine set up to run code quality tools on save). |
""" | ||
|
||
|
||
def test_sort(tmpdir): |
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.
Since this is new test, no reason to use legacy tmpdir
? Can you please switch to tmp_path
? Thanks!
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.
Unfortunately this will require a larger refactor, because run_sphinx_in_tmpdir
requires a tmpdir object! (the .strpath)
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.
Ah ok, I opened #188 . Thanks for the clarification!
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.
Given this is opt-in, let's merge. Thanks!
Do you need an immediate release?
I wonder whether we could clean out 1 or 2 more of the remaining PRs, so we don't end up with single PR releases :) |
Ping @mhvk