EmilStenstrom / django-components

Create simple reusable template components in Django.
MIT License
953 stars 59 forks source link

refactor: use sys.modules to get component file path #432

Closed JuroOravec closed 1 month ago

JuroOravec commented 1 month ago

Fix the issue identified in https://github.com/EmilStenstrom/django-components/discussions/425 by using sys.modules to obtain the path to the file where a component class was created.

EmilStenstrom commented 1 month ago

I wonder if it's possible to add a test for this? Of course ok if not practical.

JuroOravec commented 1 month ago

Ok I tried to write a test that's similar to the issue we've seen, so that there would be a component A whose template uses component B, whereas component B uses relative paths. But when I checked by undoing the changes of this MR, then the tests still passed. So the added tests doesn't really test against this specific issue. But I've included it anyway as it could catch some edge cases in the future.

JuroOravec commented 1 month ago

And thanks for the review!

EmilStenstrom commented 1 month ago

Merged and released in 0.65: https://pypi.org/project/django-components/0.65/