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".
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.
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
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
- some troublesome patterns are ignored by Eclipse (by adding to Preferences -> PyDev -> Editor -> Code Analysis -> Undefined)
- 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!
Although not directly related to this question in terms of disabling individual migration files from analysis, PyDev's built in code analysis was causing me real headaches here on Windows, when the same project and settings has no problem on Mac OS. This lead me to this question, on how disable analysis for certain resources. There is a large folder part of the project and excluding this resource using Eclipse -> (the folder) -> Properties -> Resources -> Filter (exclude) didn't even help.
Having the exclusion along with using PyLint fixed the insanely slow build times. YMMV.