• Stars
    star
    13
  • Rank 1,509,361 (Top 30 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 7 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python FMT is a python linter/formatter/checker for TextMate.

Version Plaftorm Python 3.7+ macOS macOS macOS macOS macOS macOS Code style: black

Python FMT bundle for TextMate

Hit + S I’ll handle the rest!

This little TextMate bundle helps you to write better and safer Python code. Using TextMate’s before/after event callbacks to check/format/lint your Python code. Integrated tools are:

Tool Descriptiopn
isort Sorts import statements
black Format source code
pylint Check errors before run it!
flake8 Linting, checking source code with ease!

Update

2022-10-24

  • black formatter now checks for local config: ~/.black. Good for working with single/individual files! Just copy from pyproject.toml or create new one!

Before Python FMT for TextMate

Before Python FMT for TextMate bundle

After Python FMT for TextMate

After Python FMT for TextMate

After pylint/flake8 running

After Python FMT for TextMate

Error information

After Python FMT for TextMate


Installation

Checker your Python binary. You need Python 3+.

$ which python
/Users/vigo/.pyenv/shims/python                  # or
$ pyenv which python
/Users/vigo/.pyenv/versions/3.7.0/bin/python

You need to set TM_PYTHON_FMT_PYTHON_PATH variable (TextMate > Preferences > Variables) and set the value according to the result above. If TM_PYTHON exists, bundle will fall back to TM_PYTHON value as python executable.

You can set TextMate Variable via;

$ defaults write com.macromates.TextMate environmentVariables \
    -array-add "{enabled = 1; value = \"$(command -v python)\"; name = \"TM_PYTHON_FMT_PYTHON_PATH\"; }"

You need to restart TextMate to take effect.

$ cd ~/Library/Application\ Support/TextMate/Bundles/
$ git clone https://github.com/vigo/textmate2-python-fmt.git Python-FMT.tmbundle

If your project already contains lint/format config files (such as .pylintrc etc...) or packages (such as pylint, flake8 binaries etc..) You don’t need to install anything. Just create .tm_properties and fill the config variables. Try with + T (option + T)

For global usage, you can install python packages and config files for any python file/project:

$ cd Python-FMT.tmbundle/
$ mkvirtualenv textmate-python-fmt
$ pip install -r requirements.txt

When you open any single python file or project, when you hit save, bundle checks for local or global linter binaries and config files.

Now, you can add all the config files inside of the textmate-python-fmt env:

$ cdvirtualenv # or
$ cd ~/.virtualenvs/textmate-python-fmt
$ pylint --generate-rcfile > pylintrc
$ touch isort flake8

All the pylint messages are available via;

$ pylint --list-msgs

You can create

  • .isort.cfg
  • .pylintrc
  • .flake8
  • pyproject.toml

via + T and choose from list!

Now you can set TM_ variables:

TM_PYTHON                               /Users/YOUR-USER-NAME/.pyenv/versions/3.8.0/bin/python
TM_PYTHON_FMT_PYLINTRC                  /Users/YOUR-USER-NAME/.virtualenvs/textmate-python-fmt/pylintrc
TM_PYTHON_FMT_PYLINT_EXTRA_OPTIONS      --disable missing-module-docstring,missing-function-docstring
TM_PYTHON_FMT_BLACK_DEFAULTS            --skip-string-normalization --target-version py38 --quiet
TM_PYTHON_FMT_PYLINTRC                  /Users/YOUR-USER-NAME/.virtualenvs/textmate-python-fmt/pylintrc
TM_PYTHON_FMT_FLAKE8_DEFAULTS           --config /Users/YOUR-USER-NAME/.virtualenvs/textmate-python-fmt/flake8
TM_PYTHON_FMT_ISORT_DEFAULTS            --settings-file /Users/YOUR-USER-NAME/.virtualenvs/textmate-python-fmt/isort

This variable setup helps you to run/check/lint your python code without any project requirement. For bigger apps/projects please consider using of .tm_properties file. Hit + T to create!

Bundled flake8 plugins are:

  • flake8-bandit: For writing secure code!
  • flake8-blind-except: Checks for blind, catch-all except: statements.
  • flake8-bugbear: A plugin for Flake8 finding likely bugs and design problems in your program.
  • flake8-builtins: Check for python builtins being used as variables or parameters
  • flake8-print: Checks for print statements in python files.
  • flake8-quotes: Install this if you are single quote person like me!
  • flake8-string-format: Checks for strings and parameters using str.format
  • flake8-return: Checks return statements.

Current package versions are:

black==22.6.0
isort==5.10.1
pylint==2.15.0
flake8==5.0.4
flake8-bandit==4.1.1
flake8-blind-except==0.2.1
flake8-bugbear==22.8.23
flake8-builtins==1.5.3
flake8-commas==2.1.0
flake8-plugin-utils==1.3.2
flake8-print==5.0.0
flake8-quotes==3.3.1
flake8-return==1.1.3
flake8-string-format==0.3.0

Now you can restart TextMate!


Hot Keys and Snippets

Hot Keys and TAB Completions Description
+ { Bypass selection while formatting with black. This adds # fmt: off and # fmt: on to beginning and ending of selection.
Used James Edward Gray II’s commenting tool which ships with TextMate.
noq + Choose desired bypass method
envi + Inserts helpful environment variables if you are editing on .tm_properties file. Try :)
disable + Inserts # TM_PYTHON_FMT_DISABLE, put this in to first line if you want to disable this bundle
+ T Create .tm_properties or linter config files

TextMate Variables

Variable Information
TM_PYTHON_FMT_PYTHON_PATH Binary location of your python executable :)
TM_PYTHON_FMT_VIRTUAL_ENV Good for isort. Use .tm_properties file to set this. If set, passes --virtual-env to isort with given value
TM_PYTHON_FMT_ISORT Binary location for isort. To set custom binary, enter full path here. Example: /path/to/isort
TM_PYTHON_FMT_ISORT_DEFAULTS Unless .isort.cfg doesn’t exists, this parameters will be used if provided
TM_PYTHON_FMT_BLACK Binary location for black. To set custom binary, enter full path here. Example: /path/to/black
TM_PYTHON_FMT_BLACK_DEFAULTS Unless pyproject.toml doesn’t exists, this parameters will be used if provided
TM_PYTHON_FMT_FLAKE8 Binary location for flake8. To set custom binary, enter full path here. Example: /path/to/black
TM_PYTHON_FMT_FLAKE8_DEFAULTS Unless .flake8 or setup.cfg doesn’t exists, this parameters will be used as defaults for flake8 configuration
TM_PYTHON_FMT_PYLINT Binary location for pylint. To set custom binary, enter full path here. Example: /path/to/pylint
TM_PYTHON_FMT_PYLINTRC Location of pylintrc or .pylintrc file if you like to set
TM_PYTHON_FMT_PYLINT_EXTRA_OPTIONS You can pass additional options/params to pylint.
TM_PYTHON_FMT_DISABLE You this variable if you need to disable this bundle temporarily
TM_PYTHON_FMT_DEBUG Enable debug mode
TM_PYTHON_FMT_DISABLE_ISORT Disables isort import sorting
TM_PYTHON_FMT_DISABLE_BLACK Disables black formatting
TM_PYTHON_FMT_DISABLE_FLAKE8 Disables flake8 checks
TM_PYTHON_FMT_DISABLE_PYLINT Disables pylint checks

pylint now shows every available error. You can set extra options to display compile-time errors only via TM_PYTHON_FMT_PYLINT_EXTRA_OPTIONS set the value to: (TextMate > Preferences > Variables.) or .tm_properties. Space delimited arguments required...

--errors-only

flake8 and pylint using same error output format:

LINE_NUMBER || COLUMN_NUMBER || ERROR_CODE || ERROR_MESSAGE

Example .tm_properties usage:

TM_PYTHON_FMT_VIRTUAL_ENV=/Users/YOU/.virtualenvs/YOUR_VENV   # or
TM_PYTHON_FMT_VIRTUAL_ENV=$HOME/.virtualenvs/YOUR_VENV        # or
                                                              # It’s ok to use shell variables and TextMate variables but
                                                              # never user like this: `~/.virtualenvs/ENV`
TM_PYTHON_FMT_PYLINT_EXTRA_OPTIONS=--py3k
TM_PYTHON_FMT_PYLINTRC=$TM_PROJECT_DIRECTORY/.pylintrc        # or
TM_PYTHON_FMT_PYLINTRC=/path/to/.pylintrc                     # or

Now bundle checks for ~/.pylintrc. First checks local pylintrc, then checks TM_PYTHON_FMT_PYLINTRC variable. This overrides local pylintrc if TM_PYTHON_FMT_PYLINTRC is set.

Also, you can set project based configurations for all of the tools. Check their official documentations:


Contributor(s)


Contribute

All PR’s are welcome!

  1. fork (https://github.com/vigo/textmate2-python-fmt/fork)
  2. Create your branch (git checkout -b my-features)
  3. commit yours (git commit -am 'added killer options')
  4. push your branch (git push origin my-features)
  5. Than create a new Pull Request!

License

This project is licensed under MIT


Change Log

2021-04-27, Covid Days

Add disable option for each linter/formatter via TM_PYTHON_FMT_DISABLE_ prefix. You can quickly set those variables via tm_properties Helper > Disable linter/formatter from the bundle menu. envi +

  • TM_PYTHON_FMT_DISABLE_ISORT to disable isort
  • TM_PYTHON_FMT_DISABLE_BLACK to disable black
  • TM_PYTHON_FMT_DISABLE_FLAKE8 to disable flake8
  • TM_PYTHON_FMT_DISABLE_PYLINT to disable pylint

This was the request from nextmat - issue 7

Fix reset markers, now resets before anything goes on. Display enabled items at the end of the process.

2021-02-11

  • Add linter config generator: + T
  • Add config existence check, now you can’t overwrite file!
  • Remove config examples

2020-11-18

  • Add TM_PYTHON fall-back unless TM_PYTHON_FMT_PYTHON_PATH exists
  • Add virtualenv/config examples to README
  • Fix isort version display on debug mode.

2019-12-05

  • Add version information to debug text

2019-10-11

  • Add Rakefile for bump version tasks
  • Add missing environment variable description to README

2019-09-19

  • Add missing ENV_NAME identifier to .tm_properties creator snippet
  • Bump version: 3.5.5

2019-08-06

  • Add local ~/.pylintrc lookup feature
  • Add bumpversion config

2019-07-24

  • Skip pylint check unless pylintrc exists

2019-04-11

  • Create .tm_properties file to current working directory + T
  • Create .tm_properties file to project root directory + T

2019-04-05

  • Fix: pylint configuration
  • Fix: pylint result
  • New: Now shows pylint score
  • Update: Python packages

2019-03-22

  • You can create .tm_properties file
  • Extra snippets for tm_properties helper

2019-01-13

  • Put # TM_PYTHON_FMT_DISABLE as first line in to your code to disable bundle (or hit disable + )
  • When bundle is disabled from code or from env, nothing will pop! All silent now!

2019-01-08

  • Fix missing environment variable for python executable: TM_PYTHON_FMT_PYTHON_PATH
  • You can disable this bundle temporarily via TM_PYTHON_FMT_DISABLE variable.

2018-12-27

  • Now using TM_PYTHON_FMT_PYTHON_PATH instead of TM_PYTHON. You must fix this, otherwise your bundle will not work!

2018-12-23

  • TM_PYTHON_FMT_FLAKE8_DEFAULTS env-var for setting defaults for flake8
  • env + changed to envi + due to other TM bundle collision.
  • Bundle menu grouping for tm_properties helper

2018-11-29

  • TM_PYTHON_FMT_BLACK_DEFAULTS env-var for setting black defaults.
  • TM_PYTHON_FMT_ISORT_DEFAULTS env-var for setting isort defaults.
  • TM_PYTHON_FMT_DEBUG env-var for debugging.

2018-11-21

  • Monkeypatch: flake8-bandit causes warning: Possible nested set at position 1
  • Version bump to: 3.1.0

2018-11-19

  • Update: Added missing information on README.md
  • Update: Virtual Environmet support for pylint
  • Update: pylintrc support for pylint
  • Fix: isort:skip_file bug
  • Addition: env + for environment variables
  • Change: All the bypass declarations are using noq +
  • Version bump to: 3.0.5

2018-11-18

  • Upgrade: Rewritten from scratch. autopep8 removed.

2018-11-17

  • Update: black integration
  • flake8-commas removed.

2018-11-15

  • Update: setup.cfg config file support added.

2018-11-14

  • Fix: Added --trailing-comma for isort imports
  • Added: List of flake8 plugins

2018-10-28

  • TM_PYTHON_FMT_DEBUG if set, you’ll see running commands
  • Version is now 2.1.4

2018-10-24

  • Fix: Added missing git clone information
  • Fix: runners.
  • Version is now 2.1.3

2018-10-24

  • Bundle re-written from scratch
  • Now using callback.document.will-save and callback.document.did-save hooks
  • isort support added
  • Version is now 2.1.0

2017-07-02

  • Updated: README file. Added useful setup instructions.
  • Added: Badges :)

2017-05-14

  • Updated: Success tooltip message now shows maximum characters value
  • Updated: Screenshot of before-and-after-flake8.png
  • Changed: Overriding default save keys ( + S) was a bad idea :)

2017-05-13

  • First release :)

2017-05-06

  • Initial commit

More Repositories

1

git-puf-noktalari

Günlük hayatta kullandığımız revizyon kontrol sistemi GIT ile ilgili küçük ipuçlarını anlatan yeni mini kitabım.
Ruby
425
star
2

kommit

Build your commit message without touching or editing your code!
Shell
204
star
3

ruby101-kitap

Türkçe Ruby kitabı
Ruby
197
star
4

dinozorus

1990'lı yıllara damgasını vuran efsane televizyon oyunu Dinozorus. Amiga 1200 - AGA
Assembly
134
star
5

turk-scene-tarihi

80'lerin ortasında başlayan, günümüz bilgisayar kültürünün neredeyse başlangıç noktası olan Türk SCENE/DEMOSCENE tarihçesi
85
star
6

lyk-2017

Linux Yaz Kampı 2017'de anlattığım konular.
41
star
7

django2-project-template

Django project/application starter for lazybones :)
Python
39
star
8

statoo

`statoo` is a super simple http GET tool for checking site health
Go
33
star
9

textmate-twitterbootstrap.tmbundle

TextMate bundle for Twitter's Bootstrap
HTML
33
star
10

awesome-c64

Commodore 64 related links such as C64 tools for Mac/Linux/PC, demoscene related stuff, coding tools, C64 utilities etc...
31
star
11

textmate-octopress.tmbundle

TextMate bundle for Octopress blog engine. http://octopress.org/
29
star
12

django-admin-list-filter

Dead simple autocompletion for Django admin `list_filter`.
Python
22
star
13

gh_issues

Manage GitHub issues from command-line (read only!)
Ruby
22
star
14

dotfiles-light

Just another but `lighter` version of BASH environment
Shell
20
star
15

dotfiles-universal

My old BASH dot-files... Try new one!
Shell
13
star
16

textmate2-gfm-preview

GitHub Flavored Markdown Preview for TextMate 2
CSS
13
star
17

django-project-template

Project starter for Django 1.11.4 ... Batteries included :)
Python
9
star
18

textmate-hosts.tmbundle

TextMate bundle for /etc/hosts file
9
star
19

dotfiles-fever

Elegant BASH environment for macOS, Ubuntu and Gentoo
Shell
8
star
20

textmate-window-manager

Window manager/arranger for oldskool TextMate (1.5)
Shell
7
star
21

devpod

Official website of devPod
HTML
6
star
22

apm-bash-completion

Bash completion for Atom Package Manager (apm)
Shell
6
star
23

stormssh-completion

Bash competion for `sshstorm` (https://github.com/emre/storm)
Shell
6
star
24

textmate2-ruff-linter

Ruff linter for TextMate2. Linter and auto fixer for python!
Perl
5
star
25

ugur.ozyilmazel.com-v5

Kişisel websitem V4.0
HTML
5
star
26

lsvirtualenvs

Small commandline tool for `virtualenvwrapper`
Go
4
star
27

ghstars

Show GitHub stars count for user!
Go
4
star
28

git-init-githubrepo

Create git repository for GitHub style
Go
4
star
29

textmate2-tailwind-css

Tailwind CSS support for TextMate 2
Ruby
4
star
30

golang-notlarim

Golang geliştirme ile ilgili aldığım notlar
Ruby
4
star
31

git-tips

Git versiyon kontrol sistemi ile ilgili Türkçe dökümantasyon ve ipuçları
JavaScript
4
star
32

dox2008

2007-2008 yıllarında İstanbul Bilgi Üniversitesi, web departmanı için hazırladığım javascript ve html/css eğitimleri
JavaScript
4
star
33

textmate2-power-tools

Some useful TextMate2 snippets, commands etc...
Ruby
3
star
34

inspect-go

Ruby-ish Object#inspect tryouts for Golang!
Go
3
star
35

putio

Command-Line client for put.io platform (unofficial)
Go
3
star
36

textmate2-64tass-bundle

64tass Bundle for TextMate 2
2
star
37

sayisal_captcha

Çok basit şekilde iki basamaklı sayılardan random toplama ya da çarpma üreten bir sistem
Ruby
2
star
38

learning-stimulus-02

I'm learning stimulus, this is example 02
JavaScript
2
star
39

vigo

I'm a hustler baby!
2
star
40

textmate2-gomodifytags

TextMate2 implementation of Fatih’s gomodifytags
Shell
2
star
41

ruby101-kitap-kod

Ruby101 kitabında geçen kod örnekleri
2
star
42

els

Unix `ls` command alternative via Ruby :)
Ruby
2
star
43

pg16_django

3. Programlama Günleri / Karabük - Django ile tanışma
Python
2
star
44

vigo.io

Personal website
HTML
2
star
45

learning-stimulus-01

I'm learning stimulus, this is example 01
JavaScript
1
star
46

textmate2-bootstrap3

Bootstrap 3's helpers for TextMate2
1
star
47

uptimerobot_cmd

Command-line client for Uptimerobot service
Ruby
1
star
48

stringutils-demo

A basic golang package for demo purpose only...
Go
1
star
49

textmate1-twitter-bs3.tmbundle

Twitter Bootstrap 3 bundle for TextMate1 (yes the oldest TextMate)
1
star
50

try_git

1
star
51

dji18njs

Modified and hardcore changed version of Django's i18n-javascript function. Can be usable as JavasScript Template engine. If you familiar with python's "format text" you will love this!
JavaScript
1
star
52

homebrew-lsvirtualenvs

brew tap for lsvirtualenvs
Ruby
1
star
53

homebrew-git-init-githubrepo

brew tap for `git-init-githubrepo`
Ruby
1
star
54

amiga-ascii.tmbundle

Oldskool Amiga ascii/azki/nfo/diz support for TextMate with real Amiga fonts
1
star
55

vigo.github.com

My developer home page...
HTML
1
star
56

ugur.ozyilmazel.com

Kişisel web sitem
HTML
1
star
57

textmate-nanorc.tmbundle

.nanorc bundle for TextMate
Ruby
1
star
58

homebrew-statoo

brew tap repo for `statoo`
Ruby
1
star
59

my-custom-textmate1-bundle

Many snippets and my custom scratch-pad for TextMate1.
CSS
1
star
60

homebrew-ghstars

Brew tap for ghstars cli
Ruby
1
star