Skip to content

feat: Add a rendering option to change the sorting of members - #274

Merged
pawamoy merged 13 commits into
mkdocstrings:masterfrom
joerick:sort_members
Aug 20, 2021
Merged

pawamoy merged 13 commits into
mkdocstrings:masterfrom
joerick:sort_members

Conversation

@joerick

@joerick joerick commented May 1, 2021

Copy link
Copy Markdown
Contributor

Hey! I developed this feature for my own use but figured it could be useful for others too. I wanted to make the members of a class appear as they do in the source file, instead of sorting them alphabetically. So I added this option. It works like:

::: mkdocs_autorefs.plugin
    rendering:
      sort_members: source

'lexical' is the default, 'source' sets the order to that in the source file. It works by pulling the sort behaviour out of the template, and into the PythonRenderer.

This might be related to #102? Or maybe not.

@oprypin oprypin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution! It makes sense and I don't see a problem with this.

I will let @pawamoy lead the review, though.

I am just leaving some comments on the details, but no need to act on them immediately.

Comment thread src/mkdocstrings/handlers/python.py Resolved
Comment thread src/mkdocstrings/handlers/python.py Resolved
Comment thread src/mkdocstrings/handlers/python.py Resolved
Comment thread src/mkdocstrings/handlers/python.py Resolved

@pawamoy pawamoy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @joerick, thank you for this PR 🙂
I think a lot of people will love that feature!

Just added a few comments. I'll try to be more thorough later.

Comment thread src/mkdocstrings/handlers/python.py Resolved
@joerick

joerick commented May 6, 2021

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews! I've made a few edits based on your feedback.

Comment thread docs/reference/autorefs/plugin.md Resolved
Comment thread src/mkdocstrings/handlers/python.py Resolved
Comment thread src/mkdocstrings/handlers/python.py Resolved

@pawamoy pawamoy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the update! A few suggestions 🙂
Please add a test for each sorting function as well, and we should be good to go!
Let me know if you need any advice about writing the tests.

Comment thread src/mkdocstrings/handlers/python.py Resolved
Comment thread src/mkdocstrings/handlers/python.py Resolved
Comment thread src/mkdocstrings/handlers/python.py Resolved
@pawamoy
pawamoy merged commit b1fff8b into mkdocstrings:master Aug 20, 2021
@camold

camold commented Aug 25, 2021

Copy link
Copy Markdown

When will this appear in a public version on pypi? The last version (0.15) dates from February, unfortunately.

@pawamoy

pawamoy commented Aug 25, 2021

Copy link
Copy Markdown
Member

We should be able to release 0.16 soon. Just polishing docs and we're good to go.

@Gaoyongxian666

Copy link
Copy Markdown

image

I can't achieve this ,why?

@ofek

ofek commented Nov 24, 2021

Copy link
Copy Markdown
Contributor

@joerick Trying this now, just to confirm: was your intention to order by appearance rather than line number of definition?

@joerick

joerick commented Nov 24, 2021

Copy link
Copy Markdown
Contributor Author

hey @ofek! The intention was to render docs in the order that the classes/methods appear in the .py file

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.

6 participants