ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 15 Jun 2021 15:29:20 +0200SageMath code auto-formattinghttps://ask.sagemath.org/question/57558/sagemath-code-auto-formatting/ Hello there!
Are there any known code formatters for SageMath code, such as `yapf` and `black` are for Python code? If not, is it possible to make a fork of, say, `yapf` which recognises the special SageMath syntax?
It makes sense that this would be possible since SageMath code is essentially an extension of Python; however I have no idea how one would go about actually doing so.Tue, 15 Jun 2021 15:19:12 +0200https://ask.sagemath.org/question/57558/sagemath-code-auto-formatting/Answer by tmonteil for <p>Hello there!</p>
<p>Are there any known code formatters for SageMath code, such as <code>yapf</code> and <code>black</code> are for Python code? If not, is it possible to make a fork of, say, <code>yapf</code> which recognises the special SageMath syntax?
It makes sense that this would be possible since SageMath code is essentially an extension of Python; however I have no idea how one would go about actually doing so.</p>
https://ask.sagemath.org/question/57558/sagemath-code-auto-formatting/?answer=57559#post-id-57559If you plan do write programs within a few files, you can use Python tools as such code will be pure Python. The "special Sagemath syntax" is made possible by the preparser, which is intended to be used in interactive mode (command line and notebooks), not within a serious program. Note that the source code of Sage itself is made of pure Python and Cython, it is not preparsed.
Tue, 15 Jun 2021 15:29:20 +0200https://ask.sagemath.org/question/57558/sagemath-code-auto-formatting/?answer=57559#post-id-57559