[code-quality] Searching multiple setup.cfg files for flake8 section?

Ian Cordasco graffatcolmingov at gmail.com
Tue Jul 7 15:36:52 CEST 2015


Hey Willy,

Responses in-line:

On Tue, Jul 7, 2015 at 4:05 AM, Willy Wu via code-quality
<code-quality at python.org> wrote:
> Hey all,
>
> We use flake8 at Dropbox and are pretty happy with it.  But one small issue
> is the way that flake8 configuration gets discovered.  We use the
> per-project configuration via setup.cfg files which are checked into source
> control, but flake8 only considers the first setup.cfg in the directory path
> (regardless of whether it contains a flake8 section or not).  This forces us
> to duplicate our [flake8] configuration across all of our various
> setup.cfgs.
>
> Said in crude ascii form, this is a simplified version of our project
> layout:
> - repo root
>   |- setup.cfg (default values)
>   \- subservice #1
>     \- setup.cfg (which has non-flake8 overrides for subservice #1)
>   \- subservice #2
>     \- setup.cfg (which similarly contains non-flake8 overrides for
> subservice #2)

So... to be clear... you're putting all of your Flake8 configuration
in "repo root/setup.cfg" but you have other setup.cfg files in
sub-directories. How are you running Flake8 (or perhaps, where are you
running Flake8) such that it picks up the setup.cfg files in the
sub-directories? Am I correct in assuming that you are running it in
that sub-directory? If not, can you give me the command-invocation
that triggers this?

> But before I go off trying to patch flake8 code, is there relevant
> background on why you guys don't try to discover the first setup.cfg with a
> flake8 section, but instead just consider the first encountered setup.cfg?
> We've seen teams accidentally break flake8 checking whenever they add
> setup.cfg files for non-flake8 projects, and the "fix" is to copy/paste the
> flake8 section into those new files.

The easiest answer is simplicity. Flake8 piggy-backs off of pep8 when
it comes to finding config files and consuming them.

I think there were a couple of people who had requested that we search
through all parent directories until we could find no parent directory
to search for configuration files, but I hope you can understand why
that is not feasible in the slightest. I believe the two places we
search by default are:

- Current working directory
- User's home directory

Traversing sub-directories is a little bit less offensive, but still
not optimal. There is the option to specify the config file
explicitly, but that doesn't help our users that much unless they have
some (honestly bizarre) setup where they're using something like
autoenv + shell aliases for flake8, e.g., autoenv could pick up the
right config file path when changing into a directory and `flake8` is
aliased to `/path/to/flake8 --config=$ENVVARWITHPATH`

That's definitely a bit over-the-top and not exactly user-friendly.

> Or alternatively, should we be doing something different with our project
> layout as a workaround?  It's entirely possible that we should be
> configuring things differently overall...?

That's tough to say honestly. I don't really feel like it's my place
(or anyone else's place) to tell you how to structure your project
layouts. That decision should be 100% in your court.

I'd still like to know a bit more about exactly how you're invoking
flake8 in this case. I don't have a clear enough understanding of the
problem to really be very helpful.

Cheers,
Ian


More information about the code-quality mailing list