Sublime Forum

Your tips and tricks for PEP8

#1

My friend had Sublime with PEP8 and it was extremely user friendly, pointing at errors but not too aggressive, and so on… To help newbie to understand and learn proper formatting.

So I downloaded it a week ago and it’s painful to use, leaving white boxes around the code and being not so user friendly, kinda hard to explain.

0 Likes

#2

I’m a little fuzzy on what you’re asking about. I don’t think the PEP-8 linting is available until you install SublimeLinter package and the accompanying pylint or pyflakes package. Is this what you’ve done?

0 Likes

#3

I have “SublimeLinter” but I didn’t have “pylint” nor “pyflakes”, neither did my friend have… It still works tho, it’s just the options are messed up and the default options are pain.

0 Likes

#4

It’s important to know that SublimeLinter is just a framework for linting, controlling how often it checks and handling the on-screen notifications. It also customizes colorschemes to check for scopes that SublimeLinter likes to use.

You also need to get the language specific extension. So for Python you’d want to install SublimeLinter as a base, and then install SublimeLinter-pylint (or possibly SublimeLinter-pep8 – there are a few varieties for Python).

Maybe this helps you out with getting it sorted.

0 Likes

#5

I always found SublimeLinter would work good for a time, then be broken for a while. I kind of got tired of fighting with it, so I now just run flake8 on my commits from command line before a commit. If I forget (which happens) Travis CI usually sends be an email so I can feel the proper shame I deserve :slight_frown:. Maybe SublimeLinter is better now, I don’t know.

0 Likes

#6

Yeah I’ll admit, I took out Python linting myself. The ratio of “functional useful alerts” to “style alerts” was sadly on the low side. I’m all for writing beautiful and maintainable code, but sorting through the alerts where I’d already mentally decided that a block was the way I wanted it to look to get to the useful ones was more time invested.

0 Likes

#7

That’s why in your project you add flake8 (or pep8 or other linter) config in your project to avoid things you don’t care about. I find it helpful, I just found I fought with SublimeLinter too much.

1 Like

#8

Has there been any change in the configuration of SublimeLinter - specifically the flake8 plugin? I have a Django project and I want to ignore ‘line too long’ warnings in only specific files. Previously I have done this by adding the comment # [SublimeLinter flake8-ignore: E501] to the top of those files but recently that is getting ignored.

Versions:
SublimeText 3.0 build 3143
SublimeLinter: 3.10.4
SubmlimeLinter-flake8 3.0.0
flake8 3.5.0 (mccabe: 0.6.1, pycodestyle: 2.3.1, pyflakes: 1.6.0) CPython 3.6.3 on Darwin

(I would provide all versions if I knew how to list them in a way that allowed me to cut and paste the list)

0 Likes

#9

You can also use LSP.

You can’t configure pep8 in it, but it reads your system configuration, so you can tweak that and it will respect your choices.

0 Likes

#10

A bit, but the core of it is unchanged and basically cannot be changed without starting over and breaking linters left and right. It’s in a tough spot. For my purposes it’s been pretty reliable though.

LSP though, has been wonderful for Python. It’s not my daily language, but it’s been pretty easy to set up and configure the listing it does.

0 Likes

#11

You should take a look at flake8 --install-hook=git https://flake8.readthedocs.io/en/latest/manpage.html. It will setup a git hook that runs the check pre commit. It’s fast too, because it only checks the staged files. SublimeLinter would get a huge performance boost by doing something similar e.g. only checking modified files and kkeping track of changes so there’s no need to check some files and not need to keep making git calls.

2 Likes

#12

The noise of diagnostics in LSP is too much for me. It doesn’t recongnise a flake8 file. You’ll need to switch to tox.ini and pyflakes doesn’t recognise most inline noqa comments, so you’ll get noise if you use those.

I don’t get the hype of LSP. I like the concept and maybe it’s implemented well in other editors, but in Sublime it’s pretty miserable. I had high hopes trying it out, but it just made things worse. If it didn’t make things worse and added even just a little value I’d keep turned on.

0 Likes

#13

It’s the python-language-server to blame for that. It doesn’t yet correctly read/handle configuration files. It makes use of all the pyflakes/pycodestyle/pydocstyle libraries as SublimeLinter does as well, but still needs some work.

The LSP itself can show only what the language-server provides.

0 Likes

#14

SublimeLinter works ok for me. There’s no noise like LSP.

I tried the python and php language servers. The php one is desperate. It doesn’t even have basic php completions like PHP Completions Kit. The Python one wasn’t much better. That’s the least of issues though.

0 Likes

#15

That’s cool if it’s for a project for your company (who ensure that across the company everyone’s environment is the same), or for your own private repo (where your own environment is well known), but not as good for a public repository.

With a public repository you cannot guarantee that their environment will look like you expect. For situation like this, CI is probably best. It keeps the entry bar low for contributors. I don’t have to dictate how their system is setup and I can just check the status in the pull request and tell them to go fix the changes.

0 Likes

#16

It’s not meant for a public repository, at least that’s not the way I meant for you to use it. It’s not anything to do with contributors either. They can use whatever tools they want.

You said:

Instead of needing to run flake8 on the command line, you can install the git hook (locally), and then you don’t ever need to run it on the command again (at least for that project). When you commit it’ll auto run pre commit. It means you’ll never commit code with flake8 violations again. Like you said, if you forget you’ll get CI notifications. With the git hook that won’t happen. You need to install the hook for every local repository, but it’s just one command, and it only needs to be done once. The git hook is a tiny file that says run flake pre commit.

1 Like

#17

That’s fair. That’s actually what my employer does with git hooks. It’s required to install it locally. I may look into it. Thanks.

1 Like