Skip to main content

Code Quality: Enforcing the PEP8 with flake8

 

What’s PEP8? And why it’s important? 


PEP8 (Python Enhancement Proposal 0008) is a document that makes it easy for developers to get familiar with Python coding conventions.
It describes and explains the bold lines that you should consider when developing your code in Python.

Why it’s important?

Imagine that you’re working in a team with other people, you don’t know each other, you don’t know how each one of you think and take decisions.
You’ll have to work on these people’s code, you’ll need to understand the basic layout that these people follow when they want to implement their code.
So, what it’s going to be like when everyone has his own method? Catastrophic codebase, right? Here the PEP8 comes and saves the day for you and your team!
It helps you standardize a set of rules to be followed every time you’re going to change the codebase to implement new features or to review some other existing ones.


 

WOW, is it unbreakable?


Like many other standards, PEP8 can be easily violated! PEP8 is a great way to come over the conflicts that may happen when you, and your team have no solid standards. But what if it’s the situation when you’re dealing with an existing project with its own standards? It’s recommended that you follow the standards of the project instead. The ultimate goal of standards in the end is the unification of methods people implement their code with.

 

Ensure quality with Flake8


The flake8 package that helps you checking the code-style and ensuring the quality. It’s maintained by PyCQA, an organization for code quality tools (and plugins) for the Python programming language.
Simple usage of Flake8 with your Python project:


Install the package with your default Python version:

python -m pip install flake8


Be sure to install flake8 with the correct version of Python you aim to use the tool with.

Using the package with your current project


# To check a specific file.

flake8 path/to/code/to/check.py
# or to use it with a whole directory
flake8 path/to/code/

You should see something like this:




Every line contains the line and starting character, and the validation message. Cool, right? You can find more about features and plugins available from the official docs.

 

Make the most of Flake8 in your development flow


Flake8 can be super useful when it’s injected in your development flow, using the concept of version control hooks. It’s a powerful advantage when you want to make sure that everyone’s code in your team meets the standards. It’s a way of applying the flake8 validation process before any commit is pushed to your original codebase. You can also use this feature to preventing commits that don’t pass the validation process. This one is extremely useful when you’re using some kind of CI (Continuous Integration) processor in your development flow.

Comments

Popular posts from this blog

سبر أغوار العقل البشري - نظرية العقل كصفحة الفارغة لچون لوك

نستكمل اليوم رحلة فلسفية أخرى والتي هي بمثابة مغامرة جريئة! منذ فترة قريبة، كنا نستكشف فكرة المعرفة الفطرية، التي أذهلت الفلاسفة العباقرة ذوي الأفكار الثورية. سابقًا، تعرضنا بشيء من التفصيل المبسّط لمفكرين عظماء مثل إيمانويل كانط . وهو من شاكلة المفكرين المثاليين الذين اعتقدوا أنّ عقولنا تأتي إلى العالم مزوّدة بمبادئ أولى عن المفاهيم التي نعاصرها في عالمنا.، والتي تُدعى بالمعرفة الفطرية. ( رابط الفيديو الذي يتحدث عن نظرة إيمانويل كانط للمعرفة الفطرية ) . الآن سنغير المسار قليلًا. وسنتجه إلى الفريق المقابل للفلاسفة المثاليين، وعلى رأس هذا الفريق هناك "چ ون لوك " وهو مرشدنا في مهمة اليوم الجريئة. إنه بمثابة المحقق الجاد في عالم الأفكار. لوك ، الفيلسوف والطبيب الشهير، يتحدى فكرة المعرفة الفطرية، ويقول أن عقولنا تكون عبارة عن ألواح فارغة عندما نولد، دون أي معرفة فطرية. في هذه المقالة، سوف ننظر عن كثب إلى فكرة المعرفة الفطرية ولكن من زاوية مختلفة، التي يمكننا أن نسميها بزاوية الفلسفة " الماديّة ". يقول لوك إننا لا ندخل إلى العالم بأفكار مُدمجة بشكل فطري، بل نتعلم الأشيا...

Unlocking the Mind's Mysteries: The mind as a blank page (Tabula Rasa Theory)

Picture this: our philosophical journey is like a grand adventure. We've been exploring the idea of innate knowledge, something that has fascinated intelligent folks who think about big ideas. Before, we soared through the clouds of fancy thoughts with thinkers like Immanuel Kant . They believed that our minds held secret wisdom from the start. But now, we're changing course. Imagine John Locke as our guide on a daring quest. He's like a detective in the world of ideas. Locke, a famous philosopher, challenges the notion of innate knowledge. He says our minds are blank slates when we're born, with no secret knowledge. In this article, we're getting focused. We will look closely at the idea of innate knowledge but from a different angle - what we call "materialism." Locke says we don't pop into the world with built-in ideas. Instead, we learn stuff through our senses and by watching and experimenting. Join us for an exciting journey as we compare these ...

Tech-Driven Isolation: Exploring the Price of Constant Connectivity

In the heart of a bustling metropolis, Sarah was surrounded by the rhythmic hum of life. Tall skyscrapers reached for the heavens, and neon billboards painted the night sky with a kaleidoscope of colors. It was a city that never slept, a city where people were always on the move, and connectivity was a way of life. As Sarah navigated the streets, her smartphone clutched firmly in hand, she seemed like any other denizen of this digital age. Emails, messages, and social media notifications beckoned for her attention, promising connection and instant gratification. Yet, amid this whirlwind of digital activity, Sarah felt strangely disconnected. She recalled a time when friendships were nurtured over heartfelt conversations at cozy cafes, laughter echoed through living rooms during game nights, and the art of letter writing was a cherished form of expression. But now, screens have become intermediaries, replacing genuine human connections with fleeting glimpses into each other's lives....