Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create sharable configuration presets for isort #970

Closed
sobolevn opened this issue Jul 20, 2019 · 4 comments
Closed

Create sharable configuration presets for isort #970

sobolevn opened this issue Jul 20, 2019 · 4 comments
Labels
enhancement New feature or request

Comments

@sobolevn
Copy link
Member

sobolevn commented Jul 20, 2019

Problem

I am writing quite a complex flake8 plugin with lots of configuration options.
Moreover, I also depend on a lot of other plugins as dependencies. Including flake8-isort.

Here's how my configuration looks like for an end user, contents of setup.cfg:

[isort]
# See https://github.com/timothycrosley/isort#multi-line-output-modes
multi_line_output = 3
include_trailing_comma = true
default_section = FIRSTPARTY
# Is the same as 80 in flake8:
line_length = 79

I do not want my users to copy-paste these settings for several reasons:

  1. They usually make mistakes in this simple action :slight_smile:
  2. I am losing control over the default configuration: I will not be able to change something in their defaults even if I want to
  3. It brings a lot of copy-paste. That's totally inconvenient to use and maintain. One new feature or a bug might force you to go trough all your X project and edit the configuration.

Real world use-cases

Several other linters have this feature. Some of them even consider it as a key feature.

When working for EsLint for example, one can just create a module with a single javascript file and reuse it everywhere.

I propose the same for flake8.
Each user can create its own set of rules for an organisation / set of projects and reuse it without this amount of copy-paste.

Implementation details

Things to point out:

  1. It is not a breaking change, everything so work as-is, no major version bump is required
  2. Without new feature everything should work as-is
  3. New configuration option should take the lowest priority over existing config options

Configuration priority

Higher takes the priority over lower:

  1. CLI flags
  2. setup.cfg / .isort.cfg
  3. New option: --sharable-configuration

Creating new sharable configuration

I guess that reusing entry points here is the best option.

# setup.py
# ...

setup(
   name='my-flake8-config'
   entry_points={
        'isort.configuration': [
            'myconfig = some.path:ConfigurationClass',
        ],
    },

Then:

  1. Installing: pip install my-isort-config
  2. Running: isort --sharable-configuration=myconfig
  3. Done!

Configuration class API

I am not sure about this. But my vision would be something like:

# some/path.py

class ConfigurationClass(object):
    def sharable_configuration(self):
        return {
           'default_section': 'FIRSTPARTY',
           # and any other options for `[isort]` section
        }

Conclusion

This feature allows to transfer configuration in a reliable and clean way, brings no breaking changes, follows the best practices of other lint tools.

Original issue from wemake-python-styleguide: wemake-services/wemake-python-styleguide#164
The same feature I proposed for flake8: https://gitlab.com/pycqa/flake8/issues/555

I am super excited to help! @timothycrosley what do you think?

@timothycrosley timothycrosley added the enhancement New feature or request label Jan 8, 2020
@timothycrosley timothycrosley added good first issue Good for newcomers and removed good first issue Good for newcomers labels Feb 9, 2020
@timothycrosley
Copy link
Member

I would love to have something like this! Ideally, it would hook into the new profiles feature, simply adding a new profile when a sharable configuration was installed. @sobolevn are you still interested in working on this?

@sobolevn
Copy link
Member Author

I am sorry, but I don't think that I have time for this 😞

This might also be related:

  1. We use nitpick to sync the configuration between our projects: https://nitpick.readthedocs.io/en/latest/
  2. Here's how we store this configuration in our styleguide repository: https://github.com/wemake-services/wemake-python-styleguide/blob/master/styles/isort.toml

@timothycrosley
Copy link
Member

This is fixed in develop (see: https://github.com/timothycrosley/isort/tree/develop/example_shared_isort_profile) and will be released in version 5.2.0.

Thanks!

~Timothy

@timothycrosley
Copy link
Member

This was just deployed with version 5.2.0 of isort. Thanks!

~Timothy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants