Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running PEP8 checks from Python

Tags:

python

pep8

I can not run PEP8 checks from a Python script.

I don't want explicitly run pep8.exe, because I want to automate this checks, and pep8 executable can lay in different places on different platforms.

like image 468
Felix Avatar asked Mar 20 '15 09:03

Felix


People also ask

Does Pylint check PEP8?

Pylint: looks for errors, enforces a coding standard that is close to PEP8, and even offers simple refactoring suggestions. Flake8: wrapper around PyFlakes, pycodestyle and McCabe; this will check Python source code for errors and violations of some of the PEP8 style conventions.

Does PyCharm check for PEP8?

So, as you can see, PyCharm supports PEP8 as the official Python style guide. If you explore the list of inspections ( Ctrl+Alt+S - Inspections), you will see that PyCharm launches the pep8.py tool on your code, and pinpoints the code style violations.

How do I check my autopep8?

Using autopep8autopep8 --in-place --aggressive --aggressive --recursive . Once done, if you use pycodestyle to check your code again, most warnings should be gone, but most likely not all of them, some you might need to fix manually. pycodestyle . So there you have it, your code should now comply with PEP 8!


1 Answers

PEP8 advanced usage covers using pep8 inside Python script.

Quoting an example:

import unittest
import pep8


class TestCodeFormat(unittest.TestCase):

    def test_pep8_conformance(self):
        """Test that we conform to PEP8."""
        pep8style = pep8.StyleGuide(quiet=True)
        result = pep8style.check_files(['file1.py', 'file2.py'])
        self.assertEqual(result.total_errors, 0,
                         "Found code style errors (and warnings).")
like image 90
Łukasz Rogalski Avatar answered Sep 21 '22 03:09

Łukasz Rogalski