告诉 pydev 从分析中排除整个包?

发布于 2024-09-17 12:48:59 字数 318 浏览 3 评论 0原文

今天我的任务是从我的 pydev django 项目中删除小红色 X。大多数情况下,这涉及修复 pydev 的导入问题。

我使用 South 进行数据库迁移。 South(如果你不知道)生成 python 模块,而 pydev 不喜欢它们。我不想编辑南代码,因为它已生成。

有没有办法指示 pydev 从分析中排除某些包?除了整个模块之外,类似 #@UndefinedVariable 的东西?理想情况下,我想忽略名为“migrations”的包。

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".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夜吻♂芭芘 2024-09-24 12:48:59

在 South,我在 south/management/datamigration.pysouth/management/schemamigration.py 中的模板中添加了“#@PydevCodeAnalysisIgnore”。它不会让我忽略整个包,但足以满足我的目的。

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.

内心激荡 2024-09-24 12:48:59

是的,您可以将 #@PydevCodeAnalysisIgnore 放在要忽略的每个文件的开头,但这意味着您正在向 IDE 进行编码,这不是最佳实践。我更喜欢更改我的项目设置,以便

  1. Eclipse 忽略一些麻烦的模式(通过添加到首选项 -> PyDev -> 编辑器 -> 代码分析 -> 未定义
  2. 一些麻烦的文件被 Eclipse 忽略(通过向项目属性 -> 资源 -> 资源过滤器 -> 添加过滤器添加排除过滤器...

在您的特定情况下,我遇到了完全相同的问题,并且决定将南方迁移排除在 Eclipse 项目之外。在我需要编辑这些自动生成的文件的少数情况下,我没有使用 Eclipse。

更新:
另一种选择是右键单击您的项目并选择 PyDev ->删除错误标记 - 但如果有任何您不想隐藏的错误,请不要这样做!

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!

各自安好 2024-09-24 12:48:59

我有很多生成的代码。为了避免 PyDev 投诉,我按如下方式对这些模块进行后处理(bash 脚本):

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

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
和影子一齐双人舞 2024-09-24 12:48:59

虽然在禁用单个迁移文件进行分析方面与这个问题没有直接关系,但 PyDev 内置的代码分析在 Windows 上让我真正头痛,而相同的项目和设置在 Mac OS 上没有问题。这让我想到了这个问题,即如何禁用某些资源的分析。项目有一个大文件夹部分,并使用 Eclipse 排除此资源 -> (文件夹)->属性->资源->过滤(排除)甚至没有帮助。

排除和使用 PyLint 修复了极其缓慢的构建时间。 YMMV。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文