PyCQA / flake8

flake8 is a python tool that glues together pycodestyle, pyflakes, mccabe, and third-party plugins to check the style and quality of some python code.
https://flake8.pycqa.org
Other
3.39k stars 306 forks source link

local-plugins relative paths are resolved relative to all paths not just the one the path directive is found #759

Open asottile opened 3 years ago

asottile commented 3 years ago

In GitLab by @graingert on Jul 13, 2020, 08:57

Please describe how you installed Flake8

pre-commit of course

Please provide the exact, unmodified output of flake8 --bug-report

{
  "dependencies": [],
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.8.2",
    "system": "Linux"
  },
  "plugins": [
    {
      "is_local": false,
      "plugin": "flake8-tidy-imports",
      "version": "4.1.0"
    },
    {
      "is_local": false,
      "plugin": "flake8_coding",
      "version": "1.3.2"
    },
    {
      "is_local": false,
      "plugin": "mccabe",
      "version": "0.6.1"
    },
    {
      "is_local": false,
      "plugin": "pycodestyle",
      "version": "2.6.0"
    },
    {
      "is_local": false,
      "plugin": "pyflakes",
      "version": "2.2.0"
    }
  ],
  "version": "3.8.3"
}

Please describe the problem or feature

the paths are resolved relative to all paths not just the one the path directive is found in eg:

.
└── foo
    ├── bar
    │   ├── baz
    │   └── .flake8
    ├── baz
    └── .flake8
[flake8:local-plugins]
...
paths = ./baz

when running flake8 --append-config=foo/bar/.flake8 --append-config=foo/.flake8 flake8 will add foo/baz and foo/bar/baz to LocalPlugins.paths

asottile commented 3 years ago

In GitLab by @graingert on Jul 13, 2020, 09:00

here the code is looking at all the base dirs of all the config files, and doesn't associate the configs' path to the config file it was found in:

https://gitlab.com/pycqa/flake8/blob/a7be77f761a4c29121d6bb6f61c11902281f9105/src/flake8/options/config.py#L345-371

asottile commented 3 years ago

In GitLab by @graingert on Jul 13, 2020, 09:01

moved from https://gitlab.com/pycqa/flake8/-/merge_requests/442

/cc @ericvw @asottile

asottile commented 3 years ago

In GitLab by @ericvw on Jul 13, 2020, 09:19

Yeah, this is similar to #517, which has been non-trivial in working towards.

The configuration handling is a bit convoluted and I've been trying to work towards having a common place where path normalization occurs relative to the configuration file. I haven't spent much time on the plugin configuration. However, for other options, the core problem is the configuration files are all merged together first, and then path normalization occurs. It's not as straight-forward to re-order the steps.

The code you linked to here may be easier to change because get_local_plugins() seems to special case the paths option and is aware of each configuration file's location.

asottile commented 3 years ago

In GitLab by @ericvw on Jul 13, 2020, 09:35

This is the same as #517, more or less. ConfigFileFinder.local_configs_with_files() is called, which merges all options into one configuration object :cry:.

asottile commented 3 years ago

In GitLab by @ericvw on Jul 13, 2020, 09:43

Unfortunately, I've been lacking spare cycles lately. I'll see if I can find some towards making more progress in this area.

Thanks for raising the issue because it's useful for me to know where path normalization occurs :).

Without knowing all your configuration options, a workaround to this issue is to have separate flake8 invocations for each directory tree which has flake8 configuration files.