【问题标题】:Vim Flake8 ignoring project config fileVim Flake8 忽略项目配置文件
【发布时间】:2016-06-16 15:35:20
【问题描述】:

vim-flake8 似乎忽略了我的项目特定配置文件。如果我从项目根目录中的命令行运行 flake8,它可以工作,但是当我打开 vim 并尝试对我的文件运行 flake8 时,它不会选择该设置。我知道这是因为它使用默认的 79 行长度,而不是我的项目特定的 120。

我读了这篇文章:flake8 not picking up config file,但似乎没有帮助。它提到了一年多前在 cmets 中修复的错误。

在我的项目根目录中,我有一个带有 [flake8] 部分的 .flake8 文件。

vim-flake8 如何确定项目根目录是什么以及在哪里查找配置文件?它只是使用打开 Vim 的目录吗?

【问题讨论】:

  • 你用的是什么版本的 Flake8?
  • 不管怎样,我是 Flake8 的维护者,并使用 syntastic 将其挂接到 vim 中。忽略项目配置,我没有问题。
  • 你试过设置路径吗?
  • 2.5.5 (pep8: 1.7.0, pyflakes: 1.0.0, mccabe: 0.4.0) CPython 2.7.6 on Linux

标签: python vim flake8


【解决方案1】:

我今天遇到了类似的问题,我通过将以下内容添加到我的~/.vimrc(或者实际上是我的~/.config/nvim/init.vim)文件中解决了这个问题:

let g:syntastic_python_flake8_config_file='.flake8'

这是基于 syntastic 在language-specific configuration files 上的官方文档。

【讨论】:

  • 对于任何寻找答案的人来说,这对我来说效果很好:) 请确保不要同时设置 g:syntastic_python_flake8_argsg:syntastic_python_flake8_config_file
【解决方案2】:

我今天遇到了同样的问题。 Flake8 从命令行运行良好,但在 vim 内部,每个配置文件似乎都被 syntastic 忽略了。在 vim 内部运行 flake8(使用 :!flake8)获取配置。

根据 Tomi 的回答,我通过添加来修复它

    let g:syntastic_python_flake8_args='--config=setup.cfg'

到我的 vim 配置,如果 vim 从项目根目录启动,它应该可以工作。仍然有点 hacky,但至少 flake8 配置保留在一个地方。

【讨论】:

    【解决方案3】:

    在我的 OSX 上也遇到了同样的问题,并部分解决了。拥有最新版本的 syntastic(今天的 git clone)和 flake8 3.0.4。 Vim 7.4。

    flake8 从命令行运行良好并选择了我的全局 ~/.config/flake8。如果我有配置文件,Vim 不会输出任何内容,但没有 flake8 配置文件也能正常工作。

    我通过将 flake8 配置不在文件系统中而是在我的 .vimrc 中部分解决了这个问题:

    let g:syntastic_python_flake8_args='--ignore=E203,E231'
    

    但这不是最好的解决方案,因为配置不共享。

    对于已启动的开发人员,当我启用调试时

    let g:syntastic_debug = 1
    

    我得到这个输出:

    syntastic: 4.516990: &shell = '/bin/bash', &shellcmdflag = '-c', &shellpipe = '2
    >&1| tee', &shellquote = '', &shellredir = '>%s 2>&1', &shellslash = 0, &shellte
    mp = 1, &shellxquote = '', &shellxescape = ''
    syntastic: 4.517587: UpdateErrors (auto): default checkers
    syntastic: 4.517927: CacheErrors: default checkers
    syntastic: 4.518502: g:syntastic_aggregate_errors = 0
    syntastic: 4.518666: getcwd() = '/Volumes/myproject/src'
    syntastic: 4.525418: CacheErrors: Invoking checker: python/flake8
    syntastic: 4.526113: SyntasticMake: called with options: {'errorformat': '%E%f:%
    l: could not compile,%-Z%p^,%A%f:%l:%c: %t%n %m,%A%f:%l: %t%n %m,%-G%.%#', 'make
    prg': 'flake8 main.py', 'env': {'TERM': 'dumb'}}
    syntastic: 4.727963: system: command run in 0.201426s
    syntastic: 4.729751: getLocList: checker python/flake8 returned 1
    syntastic: 4.730094: getLocList: checker python/flake8 run in 0.204568s
    

    【讨论】:

      【解决方案4】:

      我无法在我的 MacOS 上运行 g:syntastic_python_flake8_* 变体。

      对我有用的快捷方式是将符号链接添加到项目基目录:

      ln -s /path/to/common/.flake8 .flake8
      

      通过此链接,语法被转发到所需位置的 .flake8。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-08
        • 1970-01-01
        • 1970-01-01
        • 2018-06-17
        相关资源
        最近更新 更多