- Project Setup
- Run Pylint Check Locally [.py]
- Run Black Tool Locally [.py]
- Run mypy Tool Locally [.py]
- Run Unit Tests Locally [.py]
- Code Coverage [.py]
- Run All Quality Checks
- Releasing
If you need to build the project locally, follow the steps for dedicated solution:
- Security Solution: Running Locally
This project uses Pylint for static code analysis. Pylint analyses your code without actually running it. It checks for errors, enforces coding standards, and looks for code smells.
Pylint displays a global evaluation score for the code, rated out of a maximum score of 10.0. We are aiming to keep our code quality high above the score 9.0.
Run Pylint on all files that are currently tracked by Git in the project.
pylint $(git ls-files '*.py')To run Pylint on a specific file, follow the pattern pylint <path_to_file>/<name_of_file>.py.
Example:
pylint src/security/promote_alerts.pyThis is an example of the expected console output after running the tool:
************* Module main
main.py:30:0: C0116: Missing function or method docstring (missing-function-docstring)
------------------------------------------------------------------
Your code has been rated at 9.41/10 (previous run: 8.82/10, +0.59)
This project uses Black for code formatting. Black aims for consistency, generality, readability and reducing git diffs. The coding style used can be viewed as a strict subset of PEP 8.
The root project file pyproject.toml defines the Black tool configuration. In this project we accept a line length of 120 characters.
Run Black on all files that are currently tracked by Git in the project.
black $(git ls-files '*.py')To run Black on a specific file, follow the pattern black <path_to_file>/<name_of_file>.py.
Example:
black src/security/promote_alerts.pyThis is an example of the expected console output after running the tool:
All done! ✨ 🍰 ✨
1 file reformatted.
This project uses mypy which is a static type checker for Python.
Type checkers help ensure that you're using variables and functions in your code correctly. With mypy, add type hints (PEP 484) to your Python programs, and mypy will warn you when you use those types incorrectly.
mypy configuration is in the pyproject.toml file.
Run mypy on all files in the project.
mypy .To run mypy check on a specific file, follow the pattern mypy <path_to_file>/<name_of_file>.py.
Example:
mypy src/security/promote_alerts.pyThis is an example of the expected console output after running the tool:
Success: no issues found in 1 source file
Unit tests are written using the Pytest framework.
Execute all tests located in the tests directory:
pytest tests/Run a single test file:
pytest tests/security/test_collect_alert.py -qRun a single test function (node id):
pytest tests/security/test_collect_alert.py::test_collect_successful -qThis project uses pytest-cov to generate test coverage reports. The objective of the project is to achieve a minimum score of 80%.
To generate the coverage report, run the following command:
pytest tests/ --cov=src --cov-fail-under=80 --cov-report=htmlSee the coverage report on the path:
open htmlcov/index.htmlUse the Makefile to run all quality gates at once:
For Python related checks run:
make py-qaThis runs Black (formatting check), Pylint (static analysis), mypy (type checking), and pytest (unit tests with coverage) sequentially.
This project uses GitHub Actions for deployment draft creation. The deployment process is semi-automated by a workflow defined in .github/workflows/release_draft.yml.
- Trigger the workflow: The
release_draft.ymlworkflow is triggered on workflow_dispatch. - Create a new draft release: The workflow creates a new draft release in the repository.
- Finalize the release draft: Edit the draft release to add a title, description, and any other necessary details.
- Publish the release: Once the draft is ready, publish the release to make it publicly available.