Building an environment to comply with the Python coding standard (PEP8) with Eclipse + PyDev

I want to be PEP8 compliant when coding Python in Eclipse (with as little effort as possible). Shows how to enable automatic checking of PEP8 and automatic conversion to PEP8 in Eclipse + PyDev.

What is PyDev

Eclipse plugin for Python.

http://www.pydev.org/index.html

PyDev is a Python IDE for Eclipse, which may be used in Python, Jython and IronPython development.

It comes with many goodies such as:

How to install in Eclipse

http://www.pydev.org/manual_101_install.html It is organized in an easy-to-understand manner with screenshots.

What is PEP8

Python coding conventions. See below for details.

PEP8 compliance check in Eclipse + PyDev

PyDev comes standard with pep8 and autopep8. With these two, PEP8 compliance check and automatic conversion to PEP8 can be performed.

pep8 A tool that checks for PEP8 compliance and outputs the violations. It can be used alone as a command line tool.

https://pypi.python.org/pypi/pep8

pep8 - Python style guide checker

pep8 is a tool to check your Python code against some of the style conventions in PEP 8.

autopep8 A tool that converts source code into a PEP8 compliant format. Easy to comply with PEP8. It can be used alone as a command line tool.

https://pypi.python.org/pypi/autopep8Use

A tool that automatically formats Python code to conform to the PEP 8 style guide

PyDev settings

Enable pep8

Window -> Preferences -> PyDev -> Editor -> Code Analysis so Check Do code analysis? On the ʻOptions` tab.

code_analysis_pep8_01.png

Check other than Don't run on the pep8.py tab.

code_analysis_pep8_02.png

Enable autopep8

Window -> Preferences -> PyDev -> Editor -> Code Style -> Code Formatter so ʻCheck Use autopep8.py for code formatting?`.

code_formatter.png

Setting to automatically execute autopep8 when saving

Window -> Preferences -> PyDev -> Editor -> Save Actions so ʻCheck Auto-format editor contents before saving?`.

auto_format.png

With this setting, even if you are not coding with PEP8 in mind When saving, autopep8 works and makes the code PEP8 compliant.

Points to note

Just running autopep8 does not make the code fully PEP8 compliant. However, it's mostly compliant, so it's easier than fixing everything manually. After running autopep8, a warning will be issued with pep8, so fix it manually.

bonus

Sort by import

Window -> Preferences -> PyDev -> Editor -> Save Actions of Sort imports on save? If you check the box, the import modules will be sorted in alphabetical order when saving. This is also set because it is troublesome to do it manually.

Recommended Posts

Building an environment to comply with the Python coding standard (PEP8) with Eclipse + PyDev
Comply with Python coding standard PEP8
[Python] Building an environment with Anaconda [Mac]
Let's summarize the Python coding standard PEP8 (1)
Let's summarize the Python coding standard PEP8 (2)
Building an environment that uses Python in Eclipse
Building an Anaconda environment for Python with pyenv
Introduction to Python "Re" 1 Building an execution environment
Python with eclipse + PyDev.
Notes from installing Homebrew to building an Anaconda environment for Python with pyenv
Building an environment for natural language processing with Python
Building an environment to use CaboCha with google colaboratory
Let's get started with Python ~ Building an environment on Windows 10 ~
Building an environment to execute python programs on AWS EC2
How to get into the python development environment with Vagrant
Run the program without building a Python environment! !! (How to get started with Google Colaboratory)
Building a virtual environment with Python 3
[Python] Explains how to use the format function with an example
[Pyenv] Building a python environment with ubuntu 16.04
Building a Python3 environment with Amazon Linux2
With PEP8 and PEP257, Python coding that is not embarrassing to show to people!
Note when creating an environment with python
Building a Python 3.6 environment with Windows + PowerShell
How to automatically check if the code you wrote in Google Colaboratory corresponds to the python coding standard "pep8"
I tried to streamline the standard role of new employees with Python
[Python coding standard] PEP 8 vs Google Style
The road to compiling to Python 3 with Thrift
To automatically send an email with an attachment using the Gmail API in Python
Let's try analysis! Chapter 8: Analysis environment for Windows created with Python and Eclipse (PyDev)
Introduction to Python Let's prepare the development environment
Prepare the execution environment of Python3 with Docker
Building a python environment with virtualenv and direnv
Building an environment for executing Python scripts (for mac)
Building a Python environment with WLS2 + Anaconda + PyCharm
Specify the Python executable to use with virtualenv
How to crop an image with Python + OpenCV
[Blender] Prepare the Blender script debugging environment (Eclipse + PyDev)
Say hello to the world with Python with IntelliJ
Install the python package in an offline environment
The easiest way to use OpenCV with python
Introduction to Python with Atom (on the way)
Try building an environment for MayaPython with VisualStudioCode
From Python environment construction to virtual environment construction with anaconda
Post an article with an image to WordPress with Python
An article summarizing the pitfalls addicted to python
[Python] Building an environment for competitive programming with Atom (input () can be used!) [Mac]
A story about how Windows 10 users created an environment to use OpenCV3 with Python 3.5
An easy way to pad the number with zeros depending on the number of digits [Python]
Make it easy to install the ROS2 development environment with pip install on Python venv
[Cloud9] Try to build an environment with django 1.11 of Python 3.4 without understanding even 1 mm
How to set the development environment for each project with VSCode + Python extension + Miniconda
I tried to build an environment for machine learning with Python (Mac OS X)
Try to solve the programming challenge book with python3
Recommendation of building a portable Python environment with conda
[Introduction to Python] How to iterate with the range function?
Try to solve the internship assignment problem with Python
The first algorithm to learn with Python: FizzBuzz problem
I tried to touch the CSV file with Python
I tried to solve the soma cube with python
[Python] How to specify the download location with youtube-dl
An introduction to Python distributed parallel processing with Ray