adamchainz/django-watchfiles

Python 3.8 support - 'PosixPath' object has no attribute 'is_relative_to'

Closed this issue · 4 comments

Python Version

3.8.10

Django Version

4.0.10

Package Version

0.1.0

Description

Hi there. Thanks for this amazing package. I went through the pain of attempting to install Watchman before stumbling on to this project (I'm pretty far down the rabbit hole at this point trying to save some CPU cycles on our local machines...).

We're running python 3.8 which the readme says should be supported. But I'm running into an issue

|   File "/usr/local/lib/python3.8/site-packages/watchfiles/main.py", line 286, in <setcomp>
|     changes = {c for c in changes if watch_filter(c[0], c[1])}
|   File "/usr/local/lib/python3.8/site-packages/django_watchfiles/__init__.py", line 67, in file_filter
|     if path.is_relative_to(directory):
| AttributeError: 'PosixPath' object has no attribute 'is_relative_to'

It looks like the package is using is_relative_to which seems like it was only introduced in python 3.9 according to the python docs https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.is_relative_to

I'm not sure if I'm missing something here so would appreciate if you could provide any insight.

Cheers

Yes, this is true. The package is still alpha quality and not properly tested. Can you suggest a fix? If not, I can't say when I'll be able to prioritize working on this.

Yea no worries. I was just hoping I was missing something simple ha. As I mentioned I'm deep down the rabbit hole now so it's either get this to work or install Watchman... (and we both know how fun that is going to be).

I had a quick look at it and I think I see a simple solution that would get it to work on 3.8. I'll try to test it out today and get a PR up.

Fix released in 0.1.1, thanks! One of these days, I’ll get around to adding tests, but if you’d like to try, that would be great!

Thanks! Appreciate the prompt response on this one. I was tempted to have a go at adding a test to cover this but unfortunately I don't really have the spare time at the moment.