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 ...