pg.
1
INDEX
Contents: Page no
1. Pydocstyle -- 03
- Introduction
- Installation
- Usage
2. Output and CICD Integration -- 04
3. CICD Output and Conclusion -- 05
4. Flake8 -- 06
- Introduction
- Installation
- Usage
- Error codes
- Output
5. CICD Integration and Conclusion -- 07
pg. 2
Pydocstyle and Flake8
1. Pydocstyle:
1 Introduction:
Pydocstyle is a tool for checking compliance with Python docstring conventions, including the PEP
257 and PEP 8 style guides. It checks your Python code for issues related to docstrings, such as
missing docstrings, docstring formats, and more. Here is an overview of `pydocstyle` and how to use
it:
2 Installation:
You can install `pydocstyle` using `pip`, the Python package manager in VS code(for manual
testing):
Pip install pydocstyle
3 Usage:
After installing `pydocstyle`, you can use it to check your Python code by running it from the
command line. Make sure that your in correct directory where python files are located:
You can also check multiple files by providing multiple file paths. Use the command as below:
pg. 3
3. Output:
`pydocstyle` will analyze your code and reports any docstring-related issues. It categorizes issues
into different error codes. The error codes will provide information about what aspect of the
docstring needs attention. We have mentioned few error codes below for reference.
- `D100`: Missing docstring in a module.
- `D203`: 1 blank line required before the class docstring (PEP 257).
- `D213`: Multi-line docstring summary should start at the second line (PEP 257).
- `D406`: Section name should end with a newline (PEP 257).
Please verify the below link to explore remaining error/Violation codes:
[Link]
Below is the sample command which is an example of ignoring the error codes by using the option
`--ignore` in the analysis. This is also one of the feature in pydocstyle.
pydocstyle --ignore=D100,D101,D212,D417,D205 <path/directory>
For additional information, please refer the below link to know more about different commands that
are supported in Pydocstyle.
[Link]
4. Integration with CICD:
Pydocstyle has been successfully incorporated and integrated into our CI/CD pipeline through a
customized procedure. This setup guarantees that the code undergoes automatic examination for
errors and adherence to coding style standards prior to merging it into the main code repository. To
achieve this, we will employ the "unitTest" stage, which will involve executing .groovy scripts
containing a Docker image equipped with the Pydocstyle module.
Write the below code in your `[Link]` file.
The custom script looks like this for pydocstyle.
pg. 4
CICD output:
Conclusion:
By integrating pydocstyle into your CI/CD pipeline, you can automate the process of checking and
enforcing docstring conventions, which helps maintain code quality and consistency across your
Python projects. Below is the documentation link for your reference:
Usage — pydocstyle 0.0.0.dev0 documentation
pg. 5
2. Flake8
Introduction:
Flake8 is a Python tool that provides a way to lint your Python code for various style and quality
issues. It combines several other tools and plugins, including PyFlakes, pycodestyle (formerly known
as Pep8), and McCabe. Here is a brief overview of Flake8 and how to use it:
Installation:
You can install Flake8 using pip, which is the Python package manager:
Pip install flake8
Basic Usage:
After installation, you can run Flake8 on your Python code files. You typically run it from the
command line in your project directory. For example:
flake8 <path/directory>
This command will check entire directory for style and quality issues.
Error Codes:
Flake8 checks your code for various issues and assigns error codes to them. You can customize which
error codes to ignore or treat as errors in your configuration. For example:
- `E501`: Line too long (over 79 characters by default).
- `W291`: Trailing whitespace.
Please verify the below link to explore remaining error/Violation codes:
[Link]
For additional information, please refer the below link to know more about different commands that
are supported in Flake8.
[Link]
Output Format:
Below is the output format for common/[Link] file using flake8.
pg. 6
CICD Integration:
Flake8 has been successfully incorporated and integrated into our CI/CD pipeline through a
customized procedure. This setup guarantees that the code undergoes automatic examination for
errors and adherence to coding style standards prior to merging it into the main code repository. To
achieve this, we will employ the "unitTest" stage, which will involve executing .groovy scripts
containing a Docker image equipped with the Flake8 module.
The custom script looks like this for Flake8
Conclusion:
Flake8 is a versatile tool for maintaining code quality and style in Python projects. It helps you catch
issues early, maintain a consistent code style, and write more readable and maintainable code. Refer
to the official Flake8 documentation and the documentation for any plugins you use for more
detailed information and customization options:
Flake8: Your Tool For Style Guide Enforcement — flake8 6.1.0 documentation ([Link])
pg. 7
Thank You
pg. 8