Skip to content

ruff format or ruff check returns "nested alternate groups are not allowed" error #9381

Description

@niccolomineo

I am attempting to exclude this dir from inspection:

extend-exclude = [
    "__pycache__",
]

but I am getting:

$ python3 -m ruff format .
ruff failed
  Cause: error parsing glob '/Users/me/project/{{cookiecutter.project_dirname}}/__pycache__': nested alternate groups are not allowed

Any ideas?

On a side note, according to this experiment, this syntax should be valid

extend-exclude = [
    "[{][{]cookiecutter[.]project_dirname[}][}]/__pycache__",
]

but it still gets me the error above.

Activity

  1. added
    bugAn issue describing something that isn't working, or a PR that fixes a bug
    on Jan 4, 2024
  2. charliermarsh commented on Jan 4, 2024

    @charliermarsh
    Member

    To clarify, the whole config is:

    extend-exclude = [
        "__pycache__",
    ]

    Is that right? And you're running from the /Users/me/project/{{cookiecutter.project_dirname}} directory?

  3. niccolomineo commented on Jan 4, 2024

    @niccolomineo
    Author

    The whole config is:

    extend-exclude = [
        "__pycache__",
        ".vscode*",
    ]
    

    and I am running from Users/me/project/.

    {{cookiecutter.project_dirname}} is a subdir in that path.

  4. charliermarsh commented on Jan 4, 2024

    @charliermarsh
    Member

    Got it, thanks!

  5. niccolomineo commented on Jan 4, 2024

    @niccolomineo
    Author

    Got it, thanks!

    Thank YOU! Are you able to confirm it is a bug and not something I have to tweak on my side?

  6. charliermarsh commented on Jan 4, 2024

    @charliermarsh
    Member

    From the description it looks like a bug. What you could do though is omit that directory entirely:

    extend-exclude = [
        "[{][{]cookiecutter.project_dirname[}][}]",
    ]
  7. charliermarsh commented on Jan 4, 2024

    @charliermarsh
    Member

    (Taken from: #7959 (comment))

  8. niccolomineo commented on Jan 4, 2024

    @niccolomineo
    Author

    From the description it looks like a bug. What you could do though is omit that directory entirely:

    extend-exclude = [
    
        "[{][{]cookiecutter.project_dirname[}][}]",
    
    ]
    

    Unfortunately I need to target specific subdirs of that unusual dir, so that's not viable for me.

  9. niccolomineo commented on Jan 5, 2024

    @niccolomineo
    Author

    Hi @charliermarsh, you might be already aware of this, but this is occurring with the base ruff command as well, not just with ruff format.

  10. added
    cliRelated to the command-line interface of Ruff or ty
    configurationRelated to settings and configuration of Ruff or ty
    and removed
    cliRelated to the command-line interface of Ruff or ty
    on Jan 8, 2024
  11. changed the title [-]`ruff format` returns "nested alternate groups are not allowed" error[/-] [+]`ruff format` or `ruff check` returns "nested alternate groups are not allowed" error[/+] on Jan 8, 2024
  12. GitRon commented on Oct 29, 2024

    @GitRon

    We have the same issue in combination with cookiecutter 😕 The curly brackets seem to be a problem.

  13. knowfahad commented on Jan 31, 2025

    @knowfahad

    Any update on this?

  14. lucasfijen commented on Feb 21, 2025

    @lucasfijen

    Yep I'm running in exactly the same in combination with cookiecutter.
    In my case it's with the per-file-ignores, but that probably translates to the same underlying issue

    I have a folder structure:

    .
    ├── pyproject.toml
    └── {{ cookiecutter.repo_name }}
        ├── tests
        │   └── maintest.py
        ├── main.py
        └── pyproject.toml
    
    

    Where my pyproject.toml contains this setting that is causing the issue, removing this line fixes the error

    [tool.ruff.lint.per-file-ignores]
    "tests/*" = ["F811"]

    Then running ruff from the root using cookiecutter format . will cause:

    ruff failed
      Cause: error parsing glob '/workspaces/reponame/{{cookiecutter.repo_name}}/tests/*': nested alternate groups are not allowed
    
  15. ntBre commented on Feb 21, 2025

    @ntBre
    Contributor

    Does anyone have a link to a repo or gist where I could reproduce this? I'm trying to take a look but having some trouble reproducing it locally with this file tree:

    .
    ├── ruff.toml
    └── {{cookiecutter.project_dirname}}
        ├── __pycache__
        │   └── try.py
        └── try.py
    

    We use globset for most of our path globs, which has the comment "Nesting {...} is not currently allowed" in the docs, so I think the curly braces are definitely the problem.

    For now the best workarounds are still "escaping" the curly braces with square brackets ([{]) or backslashes (\{, if you're not on Windows), but I agree that it would be nice if we had some heuristics for detecting this automatically.

  16. lucasfijen commented on Feb 21, 2025

    @lucasfijen

    Thank you for taking your time to looking into it! This monday I should have some time to setup a small example repo for you to make it reproducible.

    The issue with this cookiecutter example is that the glob part with the curly brackets is not included in the ignore list field, as that part should be relative paths. However the curly brackets part are included when running ruff from the root (for this example we might need a second pyproject.toml above the ccokiecutter.project_dirname to get it reproduced.

    This explanation might not be very clear, I'll work on an example repo for you:)

  17. lucasfijen commented on Feb 24, 2025

    @lucasfijen

    @ntBre as promised I created a repository to showcase the issue here.

  18. ntBre commented on Feb 24, 2025

    @ntBre
    Contributor

    @lucasfijen Thank you so much! I cloned the repo and can now reproduce!

  19. added a commit that references this issue on Mar 3, 2025
    d93ed29
  20. added a commit that references this issue on May 1, 2026
    6b5ad2f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn issue describing something that isn't working, or a PR that fixes a bugconfigurationRelated to settings and configuration of Ruff or ty

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions