Skip to content

Implement deterministic ordering - #12

Open
anuj452005 wants to merge 6 commits into
medic:uplift_to_v1.10.0from
anuj452005:implement-deterministic-ordering
Open

Implement deterministic ordering#12
anuj452005 wants to merge 6 commits into
medic:uplift_to_v1.10.0from
anuj452005:implement-deterministic-ordering

Conversation

@anuj452005

Copy link
Copy Markdown

Implement CHT-specific customizations for pyxform update

This PR implements all the CHT-specific customizations needed for the pyxform update, ensuring backward compatibility with existing forms while incorporating the latest features from XLSForm/pyxform.

Changes Made

1. Deterministic Ordering of XML Attributes

  • Modified the node() function in utils.py to use sorted(kwargs.items()) instead of the default iteration
  • This ensures that XML attributes are consistently ordered alphabetically, regardless of the order they appear in the code
  • Regenerating a form XML that has not changed will no longer result in significant diffs due to attribute ordering

2. Instance Tag Values Copying

  • Modified the tag attribute handling in utils.py to allow tag attributes to pass through except when the tag attribute matches the element's tag name
  • This ensures that instance tag values are properly copied in the generated XML
  • Added a test file tests/test_instance_tag_values.py to verify this functionality

3. Language Tag Format

  • Added a configuration option in constants.py for language tag format
  • Modified the _translation_path method in survey_element.py to support the simplified format (e.g., label::en instead of label::/data/label:en)
  • Added a test file tests/test_language_tag_format.py to verify the simplified format is used

4. Empty Label Handling

  • Modified the xml_label_and_hint method in survey_element.py to handle empty labels
  • This allows forms with empty labels to be processed without errors
  • Added a test file tests/test_empty_label.py to verify empty labels are handled correctly

5. Verification of Existing Customizations

  • Added tests to verify that custom question types (db:person, db:clinic, etc.) are properly handled
  • Added tests to verify that meta sections have the tag="hidden" attribute

Documentation

  • Created a comprehensive migration guide in migration.md that explains:
    • The changes made in this PR
    • The benefits of each customization
    • Migration notes for form and application developers
    • Testing instructions

Testing

All tests are passing, including:

  • tests/test_deterministic_ordering.py
  • tests/test_instance_tag_values.py
  • tests/test_language_tag_format.py
  • tests/test_empty_label.py
  • tests/test_custom_question_types.py
  • tests/test_meta_section.py

Note: Some tests in the full test suite may fail due to ODK Validate issues, but these are not related to the implemented features and will be addressed separately.

Benefits

  • Maintains backward compatibility with existing CHT forms
  • Ensures consistent XML generation for better version control
  • Preserves all CHT-specific customizations
  • Provides a solid foundation for future updates

This PR addresses all the requirements outlined in the original issue, ensuring a smooth transition to the updated pyxform while preserving all CHT-specific functionality.

@JiyaGupta-cs

Copy link
Copy Markdown

Please reference the issue number

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.

2 participants