hhatto / autopep8

A tool that automatically formats Python code to conform to the PEP 8 style guide.
https://pypi.org/project/autopep8/
MIT License
4.56k stars 288 forks source link

Should be able to run autopep8 independently of global pycodestyle config #716

Open Kache opened 10 months ago

Kache commented 10 months ago

I'm an existing user of pycodestyle and I'm trying to adopt autopep8 in a new project. I want to be able to use autopep8 "cleanly" on its own, independently of pycodestyle config, because otherwise I'd have to manage and consider the interactions between config files of autopep8 and pycodestyle.

Although the README.md says:

The section must be [tool.autopep8], and pyproject.toml takes precedence over any other configuration files.

It turns out that's not really the case when ~/.config/pycodestyle exists. There are two related sub-issues, in this regard.

internal pycodestyle invocation loads external config

autopep8 behavior depends on the behavior of the internal pycodestyle invocation, which will load global pycodestyle config. Thus, config in pyproject.toml does not take full precedence, leading to confusing behavior.

Did some cursory reading, seems like adding the right options to pep8_options can instruct pycodestyle not to read its own configuration and only use what's passed in.

Cannot disable global-config via pyproject.toml

CLI invocation works:

autopep8 --global-config ""

But in pyproject.toml the setting is useless:

[tool.autopep8]
global-config = ""

Because read_config() will load pycodestyle config before read_pyproject_toml() runs, thus config in pyproject.toml does not take precedence.

Use Case

One way out of this is to stop using a ~/.config/pycodestyle, which I use as my "user Python linting settings" outside of any particular project. However, I think these issues should be addressed somehow b/c this is likely a fairly common use case.

Your Environment