Tell pydev to exclude an entire package from analysis?

眉间皱痕 提交于 2020-01-13 04:37:07

问题


Today I'm on a mission to remove little red X's from my django project in pydev. Mostly, this involves fixing import problems with pydev.

I'm using South for database migrations. South (if you don't know) generates python modules, and pydev doesn't like them. I don't want to edit the south code since it's generated.

Is there a way to instruct pydev to exclude certain packages from analysis? Something like #@UndefinedVariable, except for the entire module? Ideally I'd like to ignore packages named "migrations".


回答1:


In South, I have added a "#@PydevCodeAnalysisIgnore" to the templates in south/management/datamigration.py and south/management/schemamigration.py. It doesn't let me ignore entire packages, but serves my purposes well enough.




回答2:


I have lots of generated code. To avoid PyDev complaints, I postprocess those modules as follows (bash script):

for file in `find gen -name '*.py'`; do
    mv $file $file.bak
    echo '#@PydevCodeAnalysisIgnore' > $file
    cat $file.bak >> $file
    rm $file.bak
done



回答3:


Yes, you can put #@PydevCodeAnalysisIgnore at the beginning of each file that you want to ignore, but that means that you're coding to your IDE, which isn't best practice. I prefer instead to change my project settings so that

  1. some troublesome patterns are ignored by Eclipse (by adding to Preferences -> PyDev -> Editor -> Code Analysis -> Undefined)
  2. some troublesome files are ignored by Eclipse (by adding an exclude filter to Project Properties -> Resource -> Resource Filters -> Add Filter...)

In your particular case, I had the exact same problem and decided to exclude South migrations from the Eclipse project. On the few occasions that I needed to edit these auto-generated files, I didn't use Eclipse.

UPDATE: One other option is to right click on your project and select PyDev -> Remove error markers -- but don't do this if there are any errors that you don't want hidden!



来源:https://stackoverflow.com/questions/3605180/tell-pydev-to-exclude-an-entire-package-from-analysis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!