Skip to content

Make list_files() traversal deterministic - #88

Merged
pquentin merged 1 commit into
python-trio:masterfrom
hedgert:deterministic-list-files
Jul 31, 2026
Merged

Make list_files() traversal deterministic#88
pquentin merged 1 commit into
python-trio:masterfrom
hedgert:deterministic-list-files

Conversation

@hedgert

@hedgert hedgert commented Jul 31, 2026

Copy link
Copy Markdown

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.

@pquentin pquentin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM.

Comment thread tests/test_unasync.py
def list_files(startpath):
output = ""
for root, dirs, files in os.walk(startpath):
dirs.sort()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to read the docs to convince myself that this had any effect with the default topdown=True. Thanks, TIL.

@pquentin
pquentin merged commit 3a0a3be into python-trio:master Jul 31, 2026
23 checks passed
@trio-bot

trio-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

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:

  • Github will automatically subscribe you to notifications on all our repositories. (But you can unsubscribe again if you don't want the spam.)

  • You'll be able to help us manage issues (add labels, close them, etc.)

  • You'll be able to review and merge other people's pull requests

  • You'll get a [member] badge next to your name when participating in the Trio repos, and you'll have the option of adding your name to our member's page and putting our icon on your Github profile (details)

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!

@hedgert
hedgert deleted the deterministic-list-files branch July 31, 2026 13:43
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