Skip to content

Instantly share code, notes, and snippets.

@adamghill
Last active August 2, 2019 18:00
Show Gist options
  • Save adamghill/6a9690aea3a20f1ce705d7df794ed2f2 to your computer and use it in GitHub Desktop.
Save adamghill/6a9690aea3a20f1ce705d7df794ed2f2 to your computer and use it in GitHub Desktop.
Opinionated guide to Python development in Sublime Text
root = true
[*]
end_of_line = lf // Helps keep Windows, Mac, Linux on the same page since they handle end of line differently
charset = utf-8
trim_trailing_whitespace = true // Auto-trims trailing whitespace
insert_final_newline = true // Auto-adds a blank newline to the end of a file
[*.scss]
indent_size = 2 // More common to see 2 spaces in SCSS, HTML, and JS
[*.html]
indent_size = 2
[*.js]
indent_size = 2
[*.py]
indent_style = space
indent_size = 4
default_section = THIRDPARTY
known_first_party = project
known_django = django
sections = FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
lines_after_imports = 2
multi_line_output = 3
include_trailing_comma = 1
[flake8]
max-line-length = 80
select = C,E,F,W,B,B950
ignore = E501
// User keybindings
[
{ "keys": ["command+'"], "command": "pytest_toggle_panel" },
{ "keys": ["command+shift+'"], "command": "pytest_run_test_under_cursor"},
{ "keys": ["command+alt+'"], "command": "pytest_toggle_phantoms"},
]
// User preferences
{
"show_panel_on_build": false
}
{
"folders": [
{
"path": "."
}],
"settings": {
"python_interpreter": ".venv/bin/python",
"PyTest": {
"mode": "auto",
"options": "--quiet --tb=short --showlocals --last-failed",
"pytest": "${project_path}/.venv/bin/pytest",
"show_phantoms": false
},
"sublack.black_on_save": true
}
}
{
"shell_cmd": "isort --quiet --atomic $file && black --quiet $file"
}

My current setup for Python development fixes up the current file with black on save. flake8 fixes are displayed inline with SublimeLinter. isort is tied to a Build System that gets triggered when Command+B is pressed. Not the most elegant solution, but it works. The PyTest package is used to run tests on save and gives a red/green status bar output.

  1. pip3 install --user black isort flake8 pytest
  2. Make sure that the Python3 bin directory is exported in your shell with something like export PATH=${PATH}:/Users/<your username>/Library/Python/3.7/bin in ~/.bash_profile
  3. Add "shell_cmd": "black --quiet $file && isort --quiet --atomic $file" to a new Build System named "Python Formatter"
  4. Add "show_panel_on_build": false to the User settings
  5. Copy over the project.sublime-settings, .flake8, and .editorconfig files into the root of your project
  6. Install the following packages:
  1. Optional: To run unit tests on every save, install the PyTest package and add the PyTest keybindings and sublime settings
  2. Optional: Install Modific to see git changes in the gutter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment