Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reload dir behavior #2598

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

stinovlas
Copy link

Summary

This PR fixes the behavior of --reload-dir to match the documentation. The documentation states:

  --reload-dir PATH               Set reload directories explicitly, instead
                                  of using the current working directory.

also:

--reload-dir <path> - Specify which directories to watch for python file changes. May be used multiple times. If unused, then by default the whole current directory will be watched. If you are running programmatically use reload_dirs=[] and pass a list of strings.

However, the current implementation always adds Path.cwd() to list of watched directories. This is undesirable and contradicts the documentation. Path.cwd() should only be added as a default when no --reload-dir is specified.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • No documentation update is required.

Comment on lines -66 to -69
if Path.cwd() not in directory.parents:
self.reload_dirs.append(directory)
if Path.cwd() not in self.reload_dirs:
self.reload_dirs.append(Path.cwd())
Copy link

Choose a reason for hiding this comment

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

I think that in order to correctly match the documentation you still need to add the cwd when config.reload_dirs is empty, so the code that you removed can be replaced with:

if not config.reload_dirs:
    self.reload_dirs.append(Path.cwd())

Copy link
Author

Choose a reason for hiding this comment

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

That's what I had there earlier, but it seems that Path.cwd() is added somewhere else in the chain, this function never actually receives empty config.reload_dirs, which is why I wasn't able to test this in any sensible way.

Copy link

Choose a reason for hiding this comment

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

You're right, it's probably just added when initializing the config in that case. As a minor thing, I would still change this code a little bit to use Path.cwd() instead of Path(os.getcwd()) so that it's also easier to search where that is added in the chain.

Screenshot 2025-03-21 at 13 20 57

@adhami3310
Copy link

i tried doing so in #2583 but it seems the maintainer has better things to do :/ since then i moved to a different library that handled reload dir in a sensible way

@Kludex
Copy link
Member

Kludex commented Mar 21, 2025

i tried doing so in #2583 but it seems the maintainer has better things to do :/ since then i moved to a different library that handled reload dir in a sensible way

Pretty rude considering your company leverages the contributions I've made to the ecosystem.

@adhami3310
Copy link

Pretty rude considering your company leverages the contributions I've made to the ecosystem.

Everyone appreciates your contributions! We're also trying to contribute back :)

If you're busy with other things, that's ok. Everyone's been there, I've been there. I think, however, one should aim to communicate with their community on the timescale they expect things to happen. If the community finds an issue in the project they want to fix, and they offer the fix to you, it's (I'm not going to say common) decency to acknowledge them. In the same way you expect people to appreciate your contributions make them feel like their contributions are appreciated.

I talk in ideas of course, who among us is perfect.

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.

4 participants