snakemake / snakefmt

The uncompromising Snakemake code formatter
MIT License
151 stars 29 forks source link

python 3.12: unable to format inconsistent use of tabs and spaces #205

Closed maarten-k closed 10 months ago

maarten-k commented 1 year ago

I am testing snakemake to run with Python 3.12-rc3 by running the tests of snakemake itself.

I ran into the following error:

~/git/snakemake/tests/test05$ snakefmt -d Snakefile 
  File "<string>", line 27
    threads: 2
              ^
TabError: inconsistent use of tabs and spaces in indentation

This is expected since this is clearly in the changelog of Python 3.12

Mixing tabs and spaces as indentation in the same file is not supported anymore and will raise a [TabError](https://docs.python.org/3.12/library/exceptions.html#TabError).

Snakemake itself is also unable to parse this file under Python 3.12. Removing the tabs/spaces issue from the snakefile solves both problems, but lowers the usability of snakefmt/snakemake to remove these issues by hand.

mbhall88 commented 1 year ago

Sorry I'm not quite sure what the issue is here? Are you asking for snakefmt to resolve the tab/space issue for you?

maarten-k commented 1 year ago

The issue is that this error does not occur under Python 3.11 and does occur under Python 3.12.

Are you asking for snakefmt to resolve the tab/space issue for you?

Yes, I think that tab/space formatting should be handled by snakefmt and not done by hand.

mbhall88 commented 1 year ago

Well TabError is raised because Python does not allow mixing tabs and spaces. (See this SO answer for a nice explanation).

Maybe we need a discussion about whether or not it is snakefmt's responsibility to deal with this. I'm a little bit hesitant to have snakefmt deal with this as I think it should be brought to the user's attention as it may indicate something going wrong in their editor or developer team.

In the meantime, seems like a lot of people use this to make the indentation consistent https://pypi.org/project/reindent/

bricoletc commented 1 year ago

I also think that it shouldn't be snakefmt's responsibility

mbhall88 commented 10 months ago

Feel free to reopen if you feel this warrants further discussion