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

Make it easy for third party patch to support pyproject.toml #1684

Closed
wants to merge 1 commit into from
Closed

Make it easy for third party patch to support pyproject.toml #1684

wants to merge 1 commit into from

Conversation

waketzheng
Copy link

I use pyproject-flake8 to make flake8 support pyproject.toml

For flake8>=5.0, code have to be:

class FixFilenames(ast.NodeTransformer):
    tuple_of_interest = ("setup.cfg", "tox.ini", ".flake8")

    modern = sys.version_info[0] >= 3 and sys.version_info[1] > 7

    inner_type = ast.Constant if modern else ast.Str
    inner_type_field = "value" if modern else "s"

    fix_applied = False

    def visit_Tuple(self, node: ast.Tuple) -> ast.Tuple:
        if all(isinstance(el, self.inner_type) for el in node.elts) and set(
            self.tuple_of_interest
        ) == {getattr(el, self.inner_type_field) for el in node.elts}:
            node.elts.append(
                self.inner_type(**{self.inner_type_field: "pyproject.toml"})
            )
            ast.fix_missing_locations(node)
            self.fix_applied = True
        return node
    ...

But if there is a var as: CONFIG_FILES = ("setup.cfg", "tox.ini", ".flake8")
Code of the pyproject-flake8 patch to extend config files can be as simple as:

flake8.options.config.CONFIG_FILES += ('pyproject.toml',)

@asottile
Copy link
Member

dupe #1634

@asottile asottile closed this Sep 12, 2022
@PyCQA PyCQA locked as resolved and limited conversation to collaborators Sep 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants