Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Case-insensitive lexicographical sorting #9

Open
kdeldycke opened this issue Apr 16, 2023 · 2 comments
Open

Case-insensitive lexicographical sorting #9

kdeldycke opened this issue Apr 16, 2023 · 2 comments

Comments

@kdeldycke
Copy link

Let's say I have the following __all__ already set:

$ cat ./__init__.py
from click import *
from cloup import *

__all__ = [
    "Argument",
    "argument",
    "BOOL",
    "Choice",
    "clear",
    "ClickException",
    "color_option",
    "ColorOption",
    ...
]

When running asort 0.1.3, I get the following results:

$ poetry run python -m pip install asort
Collecting asort
  Downloading asort-0.1.3-py3-none-any.whl (9.8 kB)
Installing collected packages: asort
Successfully installed asort-0.1.3

$ poetry run asort ./__init__.py

$ cat ./__init__.py
from click import *
from cloup import *

__all__ = [
    "Argument",
    "BOOL",
    "Choice",
    "ClickException",
    "ColorOption",
    "argument",
    "clear",
    "color_option",
    ...
]

You can see above how all title-cased and upper-cased strings bubble up at the top of the list. This is normal as it is the natural order of sorted strings in Python.

What I would like to have is a parameter or a configuration option so I can instead have the elements of the __all__ list sorted regardless of the case. I.e., in the case I presented here, I expect the __all__ to look like this:

__all__ = [
    "Argument",
    "argument",
    "BOOL",
    "Choice",
    "clear",
    "ClickException",
    "color_option",
    "ColorOption",
    ...
]

My main motivation to have this flavour of sorting is so I can visually inspect that for each of my main classe (like Argument), I have a corresponding decorator (the lower-cased argument) publicly available at the root of my library.

@kdeldycke
Copy link
Author

For the context, this example is based on my Click Extra project: https://github.com/kdeldycke/click-extra/blob/v3.10.0/click_extra/__init__.py

@kdeldycke
Copy link
Author

And for reference, here is the code I use in my unittests to check that my __all__ is properly sorted: https://github.com/kdeldycke/click-extra/blob/e83ac9ffe653eaa69bad28d7a08c202b85bb5133/click_extra/tests/test_commands.py#L44-L86

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant