ariebovenberg / slotscheck

🎰 Ensure your __slots__ are working properly
https://slotscheck.rtfd.io
MIT License
89 stars 8 forks source link

Usage with django #278

Open sobolevn opened 1 day ago

sobolevn commented 1 day ago

Hi 👋

I want to integrate slotscheck to my django project. But, looks like that this is not possible right now. Because slotscheck imports code and does not run django.setup() before importing models (and some other stuff).

I propose adding pre_exec config value, so one can provide something like:

[tool.slotscheck]
pre-exec = '''
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'yourapp.settings')
import django
django.setup()
'''

And pre-exec will be called before the actual analysis begin. What do you think?

ariebovenberg commented 1 day ago

@sobolevn thanks for posting. Looks like a common use case 👍 , and pre-exec looks like a sensible way to address it. I'll have try around with it to see if it works out.