Make list_files() traversal deterministic - #88
Conversation
| def list_files(startpath): | ||
| output = "" | ||
| for root, dirs, files in os.walk(startpath): | ||
| dirs.sort() |
There was a problem hiding this comment.
I had to read the docs to convince myself that this had any effect with the default topdown=True. Thanks, TIL.
|
Hey @hedgert, it looks like that was the first time we merged one of your PRs! Thanks so much! 🎉 🎂 If you want to keep contributing, we'd love to have you. So, I just sent you an invitation to join the python-trio organization on Github! If you accept, then here's what will happen:
If you want to read more, here's the relevant section in our contributing guide. Alternatively, you're free to decline or ignore the invitation. You'll still be able to contribute as much or as little as you like, and I won't hassle you about joining again. But if you ever change your mind, just let us know and we'll send another invitation. We'd love to have you, but more importantly we want you to do whatever's best for you. If you have any questions, well... I am just a humble Python script, so I probably can't help. But please do post a comment here, or in our chat, or on our forum, whatever's easiest, and someone will help you out! |
list_files() is used by test_project_structure_after_customized_build_py_packages to compare the source package layout with the generated package layout.
The helper currently relies on the traversal order returned by os.walk(). Since os.walk() does not guarantee the order of sibling directories or files, two identical directory trees can produce different textual representations, causing the test to fail even though the generated package structure is correct.
This change sorts both dirs and files before traversal, making the comparison deterministic while preserving the intent of the test.