You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
needimport: Sort the imported needs using natural sort order #82
I would like to propose an improvement for the "needsimport" directive, so that the imported needs are naturally sorted.
Based on the current sphinxcontrib-needs version (0.3.10), needs having the ids= NEED_1, NEED_2, ... NEED_11, NEED_12 will be imported as follows:
NEED_1, NEED_11, NEED_12, NEED_2
though they are stored in the right order in the json file.
Thanks for reporting this great idea.
But honestly I have no clue how a naturally sorting can be implemented, as the need-id can be everything. I think the way a sorting algorithm should work depends deeply on the project itself.
E.g. in one of our projects we have REQ_A_1.2, SPEC_A_1.2.1, SPEC_A_1.2.2.
Maybe we could allow the registration of a self-written function, so that an author could implement every possible sorting. But I'm not sure if this use case is really common.
I suggest a workaround here: Use needs-id-regex to force the authors to use numbers with 3 digits.
So NEED_1 must be written as NEED_001. The already implemented sorting should work as needed now.
My use case is to automatically import the requirements from a database to sphinx, using the directive needimport. This works very well. I really like the sphinx-needs.
Furthermore I already sorted the json file so that, the needs are naturally sorted in the file. The problem is when the json file is loaded by the needimport directive. It re-orders the needs IDs from the json file.
If there would be a configuration to keep the order this would also work.
Otherwise also your idea of providing a user-function will work.
Okay, looks like the sorting is already kept.
I think the problem was based on Python 2.x, which does not guarantee to keep the sorting of a dict.
As far as I know Python 3.x does.
As Sphinx-Needs dropped support for Python 2.x, this problem should have been solved automatically.
This a is an important proof that time safes all problems ;)
Activity
danwos commentedon Jan 20, 2019
Thanks for reporting this great idea.
But honestly I have no clue how a naturally sorting can be implemented, as the need-id can be everything. I think the way a sorting algorithm should work depends deeply on the project itself.
E.g. in one of our projects we have REQ_A_1.2, SPEC_A_1.2.1, SPEC_A_1.2.2.
Maybe we could allow the registration of a self-written function, so that an author could implement every possible sorting. But I'm not sure if this use case is really common.
I suggest a workaround here: Use needs-id-regex to force the authors to use numbers with 3 digits.
So NEED_1 must be written as NEED_001. The already implemented sorting should work as needed now.
danielbacara commentedon Jan 25, 2019
My use case is to automatically import the requirements from a database to sphinx, using the directive needimport. This works very well. I really like the sphinx-needs.
Furthermore I already sorted the json file so that, the needs are naturally sorted in the file. The problem is when the json file is loaded by the needimport directive. It re-orders the needs IDs from the json file.
If there would be a configuration to keep the order this would also work.
Otherwise also your idea of providing a user-function will work.
danwos commentedon Jun 22, 2021
Okay, looks like the sorting is already kept.
I think the problem was based on Python 2.x, which does not guarantee to keep the sorting of a dict.
As far as I know Python 3.x does.
As Sphinx-Needs dropped support for Python 2.x, this problem should have been solved automatically.
This a is an important proof that time safes all problems ;)
🔧 Import sphinx-codelinks into the workspace as packages/sphinx-codel…