Hi!
I鈥檇 like to format a list of command line arguments to pass to a command.
Before black, I鈥檇 have done
args = [
self.config.blast_path,
"-reward", "1",
"-gapopen", "-5",
"-gapextend", "-5",
"-outfmt", "6", # tabular
"-db", self.config.blast_dbpath,
]
But now black of course puts name and value each on one line.
How can I elegantly avoid that? I think this is too much noise:
args = [
self.config.blast_path,
*("-reward", "1"),
*("-gapopen", "-5"),
*("-gapextend", "-5"),
*("-outfmt", "6"), # tabular
*("-db", self.config.blast_dbpath),
]
But creating a whole function just to have nicer code is a bit much work:
```py
args = create_arglist(
self.config.blast_path,
reward=1,
...,
_long_arg_prefix="-",
)
Not sure about your sense of elegance (I'd be fine with the initial version TBH), but you could:
options = { "-reward": "1", "-outfmt", "6" } # ...
args = [ self.config.blast_path, *(options.items()) ]
_I wish we had black formatting code snippets in github comments_
@zsol that doesn't work:
In [1592]: options = { "-reward": "1", "-outfmt": "6" } # ...
...: args = [ "self.config.blast_path", *(options.items()) ]
In [1593]: args
Out[1593]: ['self.config.blast_path', ('-reward', '1'), ('-outfmt', '6')]
I suppose it could work if you itertools.chain it, but that's even more noise.
As for the original question, I'm not sure there's much Black could do here; we could hardly automatically detect that a list is intended as a command line and change formatting based on that.
Maybe disable formatting on the list:
# fmt: off
args = [
self.config.blast_path,
"-reward", "1",
"-gapopen", "-5",
"-gapextend", "-5",
"-outfmt", "6", # tabular
"-db", self.config.blast_dbpath,
]
# fmt: on
No. The canceling function should be automatic.
Maybe we can evaluate the alignment level by the position of commas and revert the formatting if the they vary more than the original block.
Run K-Means from range(1, 4) should be sufficient.
Except that the amount of lines also counts.