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

Add sort option to automodsumm #182

Merged
merged 5 commits into from
Apr 22, 2024
Merged

Add sort option to automodsumm #182

merged 5 commits into from
Apr 22, 2024

Conversation

nstarman
Copy link
Member

@nstarman nstarman commented Jan 16, 2024

Ping @mhvk

Copy link
Contributor

@mhvk mhvk left a 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.

@@ -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__`
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -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:
Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

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

@nstarman
Copy link
Member Author

nstarman commented Jan 16, 2024

Maybe we should change the option from sort to alphabetize?
OTOH. @mhvk had an idea about grouping imports my module or some other logical grouping. Should sort not be a boolean flag, but an enumeration? Or would that be a new flag, groupby? E.g. then :groupby: + :sort: would group the objects and sort within each group.

Copy link

codecov bot commented Jan 16, 2024

Codecov Report

Attention: Patch coverage is 93.75000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 90.28%. Comparing base (5ab68d0) to head (2b01690).
Report is 4 commits behind head on main.

Files Patch % Lines
sphinx_automodapi/automodapi.py 60.00% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@mhvk
Copy link
Contributor

mhvk commented Jan 16, 2024

sort in python is pretty unambiguous, so I would just stick with it.

We do need to add a test...

@pllim pllim requested a review from eteq January 16, 2024 21:26
@pllim
Copy link
Member

pllim commented Feb 20, 2024

@nstarman , are you still interested in pursuing this?

@nstarman
Copy link
Member Author

Yes. Thanks for putting it back on my radar.

@nstarman
Copy link
Member Author

Hm. Not sure why the test is failing so early. I copied it from a test above!

@pllim
Copy link
Member

pllim commented Feb 22, 2024

I cannot tell why it is failing from the log. You might need to run this test locally and debug.

@pllim pllim added this to the 0.18.0 milestone Feb 22, 2024
@nstarman
Copy link
Member Author

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.

@mhvk
Copy link
Contributor

mhvk commented Apr 18, 2024

@nstarman - I think I found the problem: you missed how :sort: is also dealt with in writing summary lines. And that showed a problem with the test too... See nstarman#1 (as I'm not a maintainer, I cannot push to your repository...)

@nstarman
Copy link
Member Author

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]>
@nstarman
Copy link
Member Author

Rebased to fix conflict.

@nstarman nstarman marked this pull request as ready for review April 19, 2024 19:33
@nstarman nstarman changed the title WIP: Add sort option to automodsumm Add sort option to automodsumm Apr 19, 2024
@nstarman nstarman requested a review from mhvk April 19, 2024 19:35
@nstarman
Copy link
Member Author

Ping @eteq, I think this is now ready for review!

Copy link
Contributor

@mhvk mhvk left a 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
@nstarman
Copy link
Member Author

nstarman commented Apr 20, 2024

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):
Copy link
Member

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!

Copy link
Member Author

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)

Copy link
Member

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!

Copy link
Member

@pllim pllim left a 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?

@pllim pllim merged commit e7c3b5c into astropy:main Apr 22, 2024
18 checks passed
@bsipocz
Copy link
Member

bsipocz commented Apr 22, 2024

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 :)
Most are adding functionality but don't include tests, so while it's a bit of work to wrap them up I don't expect it to be too complicated.

@nstarman nstarman deleted the sort-option branch April 22, 2024 20:08
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.

4 participants