Improve flexibility of how config is provided
Currently the only config refurb looks for in a file is in the path ./pyproject.toml. Some users need to provide config to refurb in other places.
Suggestion:
- Accept a command-line argument like
--config /path/to/my/refurb.toml - If no
--configargument is passed, a default value of./.refurb.tomlis used as refurb's dedicated default config file location. - For simplicity, refurb can emit an error if config is found in both the resolved
--configlocation as well as the project'spyproject.toml. But ideally, refurb would merge any config found in multiple files within the well-known search path in a well-defined order.
One example from my past experience where the merge behavior would be useful is a Python language sponsor who is responsible for all Python code in a company's monorepo, and who wants to set up refurb as a pre-commit hook for all the Python codebases, specifying a global config file for refurb to use, in addition to any local refurb config that individual codebase owners may later add. The suggested scheme would make it easier for the Python sponsor to adopt refurb company-wide, since the global config could be specified in one place (the same place that the global pre-commit hook is configured), rather than having to update N different pyproject.toml files for each of the N Python codebases.
Thanks for your consideration and for maintaining refurb!
Thank you for the kind words! This is similar to #15, but different in that it suggests Refurb should support nested config files. This wasn't a use case I had thought of, but something I could see being very useful for large projects. With that in mind, having a bunch of pyproject.toml files scattered everywhere might be confusing, so a dedicated .refurb.toml file might be better (though pyrpoject.toml would still be best at the root level).
I will have to do some brainstorming on how a config file resolution system like this should work, but at the very least having the able to specify a config file via a flag (like in #15) would be a good start.
Great you're open to this!
It occurs to me that users probably don't need to customize the file names that refurb looks for, only the directories refurb looks for them in.
In other words, rather than accepting some --config-file option (that could potentially be repeated), what if refurb accepted a --config-path option, which would be a colon-delimited list of directories in which to search for config inside either a .refurb.toml or a pyproject.toml, in the order given, with the default value being "."?
From what @nth10sd wrote in #15, this sounds like it would satisfy their use case, and it would also satisfy the example in this issue: the Python sponsor would pass --config-path="/shared:.", so that refurb would first try to load /shared/{.refurb.toml,pyproject.toml}, and then try to load ./{.refurb.toml,pyproject.toml}, applying any config found as it is found. The idea of a colon-delimited search path should certainly be familiar to anyone who's encountered PATH, PYTHONPATH, MANPATH, LD_LIBRARY_PATH, etc. (and I guess semicolon-delimited on Windows if that's important). What do you think?
Specifying --config-path would satisfy my usecase in #15 too. Not really the filenames - sometimes I run refurb in a different folder from where pyproject.toml is located.
I think that the config path idea is worth exploring more. I agree that the name of the file should be pretty standardized, since the path is what is actually important. Having / be the "project root" might be problematic if you have an absolute path, so I am curious how PYTHONPATH handles "the root of the project". Some additional ideas I have:
- Config files could automatically be found and applied, similar to how nested
.gitignorefiles ignore only the files in that sub-directory - Refurb should start its search from the root of the project, not the current directory
- Similar to how mypy does things, we could allow for changing the rules for specific sub-directories, all from the root config file.