Skip to main content

guardrails

Project description

Python application License: MIT codecov

Guardrails for python projects

What is the project intended to solve?

Project will help to consolidate clean coding practices at the developers desk by a single call which consolidates (linting, copy paste detection, Dead code, Test coverage, Cyclomatic complexity, Mutation testing)

Technology stack

  1. Python with few python packages
  2. jscpd https://www.npmjs.com/package/jscpd

Dependencies

Python 3.8
NodeJS 10
JSCPD 3.2.1

[packages]

pip

mutmut

pytest

Lizard

vulture

codecov

pytest-cov

pylint

glob2

Install, Usage & Configuration

  1. Install the tool using pip install guardrails
  2. Install jscpd https://www.npmjs.com/package/jscpd
  3. update the guardrail.ini file, content of which is listed below
[folder]
# Fields under folder config are mandatory, if not provided, 
# will be considering the path of this ini file

# Comma seperated source folders if more than one directory
source_folder = .\EagleVision\eaglevision
# Comma seperated test folders if more than one directory
test_folder = .\EagleVision\test
pytest_root = .\EagleVision\test
report_folder = ..\opensource\python_guardrails\guardrails_report
jscpd_root = .\EagleVision

[python]
python = python
# path to the .pylintrc file if specific linting or leave empty after =
pylint_rc_file = .\EagleVision\.pylintrc

[coverage]
# path to the .coveragerc file if specific cverage config or leave empty after =
coverage_rc_file =

[gates]
# gate values are absolute integers
# duplicate to ken count
jscpd_duplicate_token = 20
# Jscpd allowed % duplication
jscpd_allowed_duplication = 7
# coverage gating %
coverage_percentage = 85
# Allowed mutats %
allowed_mutants_percentage = 20
# cyclomatic complexity allowed value
cyclomatic_complexity_allowed = 10
# minimum deadcode confidence
min_deadcode_confidence = 50

[ignore]
# pylint ignore to be added in the pylintrc file
# Add files or directories matching the regex patterns to the blacklist. The
# regex matches against base names, not paths.
# Ignore all .py files under the 3rdparty subdirectory.

# ignore-patterns=**/3rdparty/**/*.py

# Comma seperated folders if more than one directory or leave empty after = for example cyclomatic_complexity_exclude = "*guardrails.py", "*guardrail_globals.py"
# more details @https://pypi.org/project/lizard/1.17.7/
cyclomatic_complexity_exclude =
# Comma seperated source folders if more than one directory or leave empty after = for example jscpd_ignore = "**/*.min.js,**/*.map"
# More details @ https://www.npmjs.com/package/jscpd#ignored-blocks
jscpd_ignore = 
# Comma seperated source folders if more than one directory or leave empty after = for example If you want to ignore a whole file or directory, use the --exclude parameter (e.g., --exclude *settings.py,docs/
# more details @ https://pypi.org/project/vulture/#description
dead_code_ignore =

# whitelist deadcode (relative path to whitelist.py) [.\path\whitelist.py] or leave it empty after = 
dead_code_whitelist = 

[others]
# Comma seperated language if more than one, for CPD reporting
programming_language = python

[options]
# option can be either true or false
linting=false
cpd=false
coverage=false
mutation=false
deadcode=false
cyclomatic_complexity=false
  1. To call from commandline
python -m guardrails --p path\to\guardrail.ini #ini file created for respective project

Sample execution report

#####Guardrails for python programs#####
Passed linting gate
====================================
Execution Time: 111.103ms
Passed JSCPD gating
====================================
================================================= test session starts =================================================
platform win32 -- Python 3.7.3, pytest-4.6.9, py-1.8.0, pluggy-0.12.0
rootdir: C:\public_repo\python_guardrails
plugins: allure-pytest-2.8.5, cov-2.7.1, html-2.0.1, metadata-1.8.0, pylint-0.14.1
collected 1 item

test\test_sample.py .                                                                                            [100%]

----------- coverage: platform win32, python 3.7.3-final-0 -----------
Coverage HTML written to dir Sample_proj_cov


============================================== 1 passed in 0.19 seconds ===============================================
Passed testing using pytest
====================================
Name                 Stmts   Miss  Cover
----------------------------------------
source\__init__.py       0      0   100%
source\sample.py         3      0   100%
----------------------------------------
TOTAL                    3      0   100%
Passed test coverage gating
====================================

- Mutation testing starting -

These are the steps:
1. A full test suite run will be made to make sure we
   can run the tests successfully and we know how long
   it takes (to detect infinite loops for example)
2. Mutants will be generated and checked

Results are stored in .mutmut-cache.
Print found mutants with `mutmut results`.

Legend for output:
🎉 Killed mutants.   The goal is for everything to end up in this bucket.
⏰ Timeout.          Test suite took 10 times as long as the baseline so were killed.
🤔 Suspicious.       Tests took a long time, but not long enough to be fatal.
🙁 Survived.         This means your tests needs to be expanded.

mutmut cache is out of date, clearing it...
1. Running tests without mutations
⠇ Running... Done

2. Checking mutants
⠹ 2/2  🎉 2  ⏰ 0  🤔 0  🙁 0
Passed mutation testing gate
====================================
Passed Dead code gating
====================================
Passed Cyclomatic complexity gating
====================================

Report & Log

  • Report will be collected at the report_folder folder mentioned in the guardrail.ini file
  • Log file will be generated inside the guardrails package installation with name guardrails.log

Contact / Getting help

Brijesh Krishnan <brijesh.krishnank@philips.com>

Sannihith Reddy <sannihith.reddyp@philips.com>

License

The MIT License (MIT) Copyright © [2020] Koninklijke Philips N.V, https://www.philips.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

guardrails-2b2.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

guardrails-2b2-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file guardrails-2b2.tar.gz.

File metadata

  • Download URL: guardrails-2b2.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.21.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.1

File hashes

Hashes for guardrails-2b2.tar.gz
Algorithm Hash digest
SHA256 11ac7640388f13e59309c4502c91701a05786bdda9d9d6001ec8d7b1714a1440
MD5 21e6d4bc9138c6d8ea90a010edabc72a
BLAKE2b-256 be04005f1b77dd04a461ae45f6fdaf36657342a2f6e1657b45a994a5580d3fba

See more details on using hashes here.

File details

Details for the file guardrails-2b2-py3-none-any.whl.

File metadata

  • Download URL: guardrails-2b2-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.21.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.1

File hashes

Hashes for guardrails-2b2-py3-none-any.whl
Algorithm Hash digest
SHA256 c06368753204aa2b013f4cbbd0178b67d0ab221c226443f0a25f8199f851f605
MD5 8679bccd710f6a1d16f13ca2ab7dd256
BLAKE2b-256 998ddcc4e7c825fc660ffd9fe6f4935516fc15c394b6d7bfd0b021a641c2d0de

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page