Skip to content

needimport: Sort the imported needs using natural sort order #82

Closed

Description

@danielbacara

Hi,

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.

Activity

  1. danwos commented on Jan 20, 2019

    @danwos
    Member

    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.

  2. danielbacara commented on Jan 25, 2019

    @danielbacara
    Author

    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.

  3. added this to the 0.7.0 milestone on Jun 18, 2021
  4. danwos commented on Jun 22, 2021

    @danwos
    Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions