question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Config values from `tool.flakeheaven.base` are not being overridden when configuring specific plugins

See original GitHub issue

Issue

The changes introduced in #115 break overriding of config values when using the tool.flakeheaven.base option.

For example, if a project’s pyproject.toml previously disabled pylint from a base config like so:

[tool.flakeheaven]
base = "https://raw.githubusercontent.com/flakeheaven/flakeheaven/master/pyproject.toml"
...
[tool.flakeheaven.plugins]
...
pylint = ["-*"]

in 2.0.0 that override is ignored and the value from the base pyproject.toml is used, as below:

https://github.com/flakeheaven/flakeheaven/blob/24f3ba08b9fc4d798d61c3a10b6a07a6a70e4817/pyproject.toml#L135

Fix

Instead of manually deep updating specific parts of the config dict, it might be better to add a deep update function and use that to build the dict. This resolves the issue and has the added benefit of not needing to be updated if more entries which require deep updating are added in the future.

def _deep_update(old_dict, new_dict) -> Dict[str, Any]:
    for key, value in new_dict.items():
        if isinstance(value, collections.abc.Mapping):
            old_dict[key] = _deep_update(old_dict.get(key, {}), value)
        else:
            old_dict[key] = value
    return old_dict


def _merge_configs(*configs) -> Dict[str, Any]:
    config: Dict[str, Any] = defaultdict(dict)
    for subconfig in configs:
        _deep_update(config, subconfig)

    return dict(config)

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
rwwivcommented, Jul 5, 2022

@pwoolvett I’ve corrected the issue, this is specifically when using tool.flakeheaven.base

You can reproduce this by slightly modifying the script you provided:

import difflib
import sys
import tempfile
from pathlib import Path

import toml
from flakeheaven.commands._lint import NAME, VERSION, FlakeHeavenApplication

TOML = """\
[tool.flakeheaven]
base = "https://raw.githubusercontent.com/flakeheaven/flakeheaven/master/pyproject.toml"
[tool.flakeheaven.plugins]
pylint = ["-*"]
"""


def check(argv):
    app = FlakeHeavenApplication(program=NAME, version=VERSION)
    app.initialize(argv)
    config = vars(app.options)["plugins"]
    print(config)


with tempfile.NamedTemporaryFile(mode="w", suffix=".toml") as pyproject:
    pyproject.write(TOML)
    pyproject.flush()
    check(["--config", pyproject.name])

check([])

which produces this output: (EDITED for output when run outside of project context)

{'pylint': ['+F*', '+E*', '-E0611', '-E1101', '-E0401', '-E1102', '-E1123'], 'pycodestyle': ['+*'], 'pyflakes': ['+*'], 'flake8-commas': ['+*'], 'flake8-quotes': ['+*']}
{'pyflakes': ['+*'], 'pycodestyle': ['+*']}
0reactions
gonecommented, Jul 20, 2022

I think I"m able to replicate this - pylint runs always regardless of config on 2 but respects configuration on 1.0.2

Read more comments on GitHub >

github_iconTop Results From Across the Web

flakeheaven plugins --config=myconfig.toml isn't honoured #65
When i run flakeheaven plugins --config=myconfig.toml and expect to see my settings picked up instead I see all my plugins as red with...
Read more >
Configuring flake8 plugin when using flakeheaven
After changing the configuration file, clear the cache and then run flakeheaven again. Clearing the cache can be forced by setting the env ......
Read more >
Config — FlakeHell 0.8.0 documentation
Here you can configure everything for FlakeHell. Use it. CLI options. Plugins¶. In pyproject.toml you can specify [tool.
Read more >
flakeheaven - PyPI
flakeheaven is a python linter built around flake8 to enable inheritable and complex toml configuration. This project is a fork of FlakeHell. FlakeHell...
Read more >
Configuring Flake8 — flake8 6.0.0 documentation
cfg , tox.ini , or .flake8 . Values set at the command line have highest priority, then those in the project configuration file ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found