jorgenschaefer/elpy

Elpy fails to detect Black if a project module has a name conflicting with Black's modules.

Opened this issue · 0 comments

j3pic commented

Summary

The ’black’ formatter is not installed, please install it using ‘elpy-config’ or choose another one using ‘elpy-formatter’

I found that this error happens in some buffers but not others. The cause is python prepending '' to sys.path when
called with the -c option, which Elpy does in the function elpy-config--package-available-p and probaby in other
places.

Steps to reproduce

  1. Configure Elpy to use Black for formatting.
  2. Create a directory containing two files: formatme.py and secrets.py.
  3. Ensure that importing secrets.py will result in an error.
  4. Try to format code in formatme.py using elpy-format-code.

When Elpy tries to check for Black by importing it with python -c "import black", it will
fail because Black contains a module called secrets.py, but it'll import your erroneous version
because of '' getting prepended to sys.path.

To stop '' from getting prepended to sys.path, it is necessary to write the Python command
to be executed to a file and them have Python execute the file.

Result of (elpy-config)

# Paste it here

Elpy configuration in my init.el

# Paste it here