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

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

Open
j3pic opened this issue Jul 6, 2023 · 0 comments

Comments

@j3pic
Copy link

j3pic commented Jul 6, 2023

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
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

No branches or pull requests

1 participant