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

Fix comment formatting for slurm/pbs cluster directives. #960

Closed
wants to merge 2 commits into from

Conversation

asford
Copy link

@asford asford commented Aug 3, 2019

This change slightly updates black's comment formatting logic for a non-PEP8 edge case frequently encountered in HPC batch schedulers.

These tools use block comments that immediately follow the #! header to provide default configuration parameters for a batch scheduler of the form #SBATCH or #PBS and, unfortunately, don't support a pep8 compatible # SBATCH or # PBS syntax.

This change special cases comments beginning with these directives, as there isn't a clear way to resolve these requirements within black's existing syntax. As the directive must follow the shebang, # fmt: off escape hatches aren't a viable solution and (interestingly) don't prevent block comment reformatting in black's current implementation.

Though this is a low-usage edge case, I hope the precedent from #68 will apply.

lexaf added 2 commits August 3, 2019 05:43
Update make_comment logic to ignore #SBATCH and #PBS comment
directives, akin to existing logic for sphinx comment directives.

Workaround for issue in which '# fmt: off' directives do not affect
comment reformatting. Additionally, '#PBS' directives *must* occur
immediately after shebang lines, preventing the use of '# fmt: off'.
@asford
Copy link
Author

asford commented Sep 6, 2019

Friendly ping. @JelleZijlstra @zsol, would you mind commenting on this PR?

@JelleZijlstra
Copy link
Collaborator

I don't feel strongly about this. On the one hand it's a pretty simple change, on the other hand it seems inelegant to hardcode support for ever more kinds of obscure pragma syntax.

@asford
Copy link
Author

asford commented Sep 8, 2019

I agree that it's both simple and inelegant. My knee-jerk reaction here would be... configuration option, but that seems clearly clearly non-black-ish. Hard-coding a special case list here feels weird, though I firmly believe that black should do-the-right-thing somehow in this case.

Hopefully this falls under "practicality beats purity", but is there anything I can do in the patch to help smooth your concern? More clearly demarcate the special case list? Add documentation?

I've tried to find other pragma with the strict #pragma form that see use in python and haven't found any. I'm certain more might come up, but I don't think there's a massive list of special cases waiting in the wings. Nearly all comment-pragma I've seen allow (or require) a # pragma syntax., and tye strict #PBS form seems to be an artifact of the tools somewhat dated lineage.

@asford
Copy link
Author

asford commented Sep 17, 2019

@JelleZijlstra I now recognize your point on comment pragma. 🙏 While the case in #1014 doesn't exactly fall under this feature I think adding a special case here opens up a significant slippery slope.

I've open a meta-issue in #1024.

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

Successfully merging this pull request may close these issues.

2 participants