emacs-python-black
emacs-python-black copied to clipboard
Run black in specific project directory
I want to run black in the root dir of projectile project. I am trying to do this because right now, black will not pick up the pyproject.toml
configurations.
i think you're jumping to conclusions too quickly 🙃
i think your problem is not caused by this emacs package because black already takes care of what your describe:
https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#where-black-looks-for-the-file
@wbolster thanks for responding. I don't think this is an invalid issue. From reformatter docs,
When called, the reformatter will use PROGRAM and any ARGS to reformat the current buffer. The contents of the buffer will be passed as standard input to the reformatter, which should output them to standard output.
This means black is parsing stdin
. So, from black docs,
If you’re formatting standard input, Black will look for configuration starting from the current working directory.
But since the configuration is not in the cwd, black doesn't properly use pyproject.toml.
black
also has a --stdin-filename
flag:
--stdin-filename TEXT The name of the file when passing it through
stdin. Useful to make sure Black will
respect --force-exclude option on some
editors that rely on using stdin.
it seems this file is also used to find the project root, as this call to find_project_root()
shows:
https://github.com/psf/black/blob/d4a85643a465f5fae2113d07d22d021d4af4795a/src/black/init.py#L469
@ayys can you try out #14 please?
i'm not actually sure it's needed though. i read this:
If you’re formatting standard input, Black will look for configuration starting from the current working directory.
… as ‘will start looking from the current working directory upwards’, which is the desired behaviour