-
Notifications
You must be signed in to change notification settings - Fork 9
Atom
-
Install Atom and the ide-python package:
brew cask install atom apm install atom-ide-ui apm install ide-python
-
Create a Python virtualenv and install
pyls-black
along with its dependencies:# Create a directory to keep your virtualenvs in mkdir -p ~/.virtualenvs # Create a new virtualenv python3 -m venv ~/.virtualenvs/ide-python # Install pyls-black in the newly created virtualenv ~/.virtualenvs/ide-python/bin/python3 -m pip install pyls-black
Note: this will create a virtualenv in
~/.virtualenvs/ide-python
but the exact location is up to you! -
Set the Python path in
ide-python
:Atom → Preferences → Packages →
ide-python
→ Under Settings → Python ExecutableIt should be set to the full path to the Python executable created in the previous step:
/Users/rupert/.virtualenvs/ide-python/bin/python3
(replace/Users/rupert
with the path to your home folder -~
is not expanded).An alternative is to update your Atom config file directly:
# config.cson "*": "ide-python": python: "/Users/rupert/.virtualenvs/ide-python/bin/python3"
-
pyls-black
should now be ready to use! When you open a Python file, the Python Language Server (pyls
) will be started in the background. You can then format your code withblack
by:- Right-clicking in the editor and choosing Format Code from the context menu
- Or using the
⌘⇧C
keyboard shortcut - Or opening the command palette
⌘⇧P
and choosing the Code Format - Format Code command
atom-ide-ui
can also be configured to format on save.
The pyls-black
plugin will use your project's existing pyproject.toml
file if it has one.
Atom → Preferences → Packages → atom-ide-ui
→ Under Code Formatting → Format on Save
Alternatively you can update your Atom config file directly:
# config.cson
"*":
"atom-ide-ui":
"atom-ide-code-format":
formatOnSave: true
Most issues can be debugged using the logs but you'll need to enable them first:
- View → Developer → Toggle Developer Tools
⌥⌘I
- Click on the Console tab and type
atom.config.set('core.debugLSP', true)
to enable debugging - Restart Atom
⌘Q
for the config change to take effect - Re-open the Developer Tools (see step 1)
- When you open a Python file you should see some log messages in the console