简体   繁体   English

如何查找未使用的django设置

[英]How to find not used django settings

In large project, settings file can be really huge. 在大型项目中,设置文件可能真的很大。 Sometimes after a few months of heavy development, it turns out that there are some variables in settings file, which are not used at all. 有时,经过几个月的大量开发,事实证明设置文件中有些变量根本没有使用。 This might happen after upgrading requirements, or just because someone forgot to remove setting after refactorization the code. 升级需求后可能会发生这种情况,或者只是因为有人在重构代码后忘记删除设置。

It is very difficult, to check which variables are not needed, because this action requires not only searching through all project files, but also through sources of packages. 检查不需要哪些变量非常困难,因为此操作不仅需要搜索所有项目文件,还需要搜索包的源。

Of course, even this not guarantee success, because always somewhere can be something like this: getattr(settings, '%s_%s' % (app_name, important_setting)) ... but this is another story. 当然,即使这样也不能保证成功,因为总是在某个地方可能是这样的: getattr(settings, '%s_%s' % (app_name, important_setting)) ...但这是另一回事了。

  1. Is there any IDE/analyzing tool capable of detecting that? 是否有任何IDE /分析工具能够检测到这一点?
  2. Is there a better way for checking this manually? 有更好的方法手动检查吗?
  3. What are the best practices, which helps avoiding this kind of situation 有哪些最佳实践,可以帮助避免这种情况

The good news is, that in project on which I am working on we tests almost everything, so after a deleting a specific setting, I can run tests, and check if this broke something... but I don't think, that relying only on this tests a reasonable. 好消息是,在我正在研究的项目中,我们几乎可以测试所有内容,因此在删除特定设置后,我可以运行测试,并检查是否有损坏……但是我不认为,仅在此测试上合理。

PyLint will help you with this. PyLint将为您提供帮助。 Check out docs and you will find what you need. 查看文档,您会找到所需的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM