SublimeText2 and SublimeLinter --Syntax check for Python3--

1. Define a new Linter

SublimeLinter/sublimelinter/modules/python3.py

python3.py


import re
from base_linter import BaseLinter, INPUT_METHOD_FILE


CONFIG = {
    'language': 'Python3',
    'executable': 'flake8',
    'test_existence_args': ['--version'],
    'lint_args': '{filename}',
    'input_method': INPUT_METHOD_FILE #Only when saving. INPUT if you want to check in real time_METHOD_TEMP_Make it FILE
}


class Linter(BaseLinter):
    def parse_errors(self, view, errors, lines, errorUnderlines, violationUnderlines, warningUnderlines, errorMessages, violationMessages, warningMessages):
        for line in errors.splitlines():
            match = re.match(r'^.+:(?P<line>\d+):(?P<offset>\d*):?\s+(?P<error>.+)', line)
            if match:
                error, line, offset = match.group('error'), match.group('line'), match.group('offset')
                if not error.startswith('E501'):
                    self.add_message(int(line), lines, '[{0}: {1}]'.format(offset, error), errorMessages)

E501 is excluded if you like.

2. Create a syntax called Python3

cd ~/Library/Application Support/Sublime Text 2/Packages/Python
cp Python.tmLanguage Python3.tmLanguage

I'm not sure, so I changed only name and scopeName to Python3 and source.python3 OK if Python3 appears in Set Syntax

3. Sublime Linter configuration file

{
    "sublimelinter_executable_map": {
        "python3": "Path to flake8 for python3"
    }
}
  1. fleke8

Die if non-ASCII file in utf-8 file

The workaround is to set the environment variable PYTHONIOENCODING to utf-8 and LC_CTYPE to en_US.utf-8. For Mac users, write in /etc/launchd.conf. If you don't like the impact, you can write your own startup script (equivalent to the flake8 command) and write the encoding settings inside. Set the internal environment so that sys.getdefaultencoding () =='utf-8', locale.getpreferredencoding (False) =='utf-8'.

Die with bytes

This looks like a bug in flake8. flake8 / pyflakes.py: per 319

NUM = STR =	ELLIPSIS = ignore

I added BYTES to it and it worked.

Recommended Posts

SublimeText2 and SublimeLinter --Syntax check for Python3--
Ruby and Python syntax ~ branch ~
Python # How to check type and type for super beginners
Check for memory leaks in Python
Check for external commands in python
New syntax for Python 3.8 [assignment formula]
Check and move directories in Python
Differences in syntax between Python and Java
Check and receive Serial port in Python (Port check)
6 Python libraries for faster development and debugging
Find and check inverse matrix in Python
Differences between Ruby and Python (basic syntax)
[Python of Hikari-] Chapter 05-09 Control syntax (use of for statement and while statement properly)
2016-10-30 else for Python3> for:
python [for myself]
[Explanation for beginners] TensorFlow basic syntax and concept
Python nan check
Instant method grammar for Python and Ruby (studying)
Causal reasoning and causal search with Python (for beginners)
python grammar check
(Windows) Causes and workarounds for UnicodeEncodeError on Python 3
[Updating] Python Syntax cheat sheet for Java shop
with syntax (Python)
[Python for Hikari] Chapter 09-02 Classes (Creating and instantiating classes)
[Python / Chrome] Basic settings and operations for scraping
PDF files and sites useful for learning Python 3
Python syntax-control syntax
Install Python and libraries for Python on MacOS Catalina
Check the processing time and the number of calls for each process in python (cProfile)
Rock-paper-scissors poi in Python for beginners (answers and explanations)
Initial settings for using Python3.8 and pip on CentOS8
[Python for Hikari-] Chapter 06-04 Functions (arguments and return value 3)
Searching for pixiv tags and saving illustrations using Python
Extendable skeletons for Vim using Python, Click and Jinja2
Python text reading for multiple lines and one line
I tried pipenv and asdf for Python version control
List of Python libraries for data scientists and data engineers
Building a Docker working environment for R and Python
[Python] Measures and displays the time required for processing
Benchmark for C, Java and Python with prime factorization
Python netCDF4 read speed and nesting of for statements
[Python for Hikari-] Chapter 07-01 Exception Handling (Errors and Exceptions)
[Python] Output battles and combinations (nesting for statements and if statements)
Preferences for playing Wave in Python PyAudio and PortAudio
Python learning memo for machine learning by Chainer Chapters 1 and 2
Problems and countermeasures for Otsu's binarization overflow in Python
Write tests in Python to profile and check coverage
[Introduction for beginners] Reading and writing Python CSV files
English-English dictionary confrontation for Python and AI related English
[Python for Hikari-] Chapter 06-01 Functions (Intrinsic Functions and Function Definitions)
Compile and install MySQL-python for python2.7 on amazon linux
About creating and modifying custom themes for Python IDLE
[Python for Hikari-] Chapter 06-03 Functions (arguments and return value 2)
Recursively search for files and directories in Python and output
[Python] Chapter 05-01 Control syntax (comparison operator and conditional branching)
[Python of Hikari-] Chapter 05-05 Control syntax (for statement-multiple loops-)
[python] Compress and decompress
About Python for loops
Python and numpy tips
[Python] pip and wheel
Python basics ② for statement