Git Product home page Git Product logo

readme-coverage-badger's Introduction

Welcome to README Coverage Badger ๐Ÿ‘‹

PyPi PyPI - Python Version Build Status codecov pre-commit.ci status Updates PyPI - Downloads GitHub commits since latest release (by SemVer)

License Code style: black Conventional Commits Commitizen friendly

Generates a coverage badge using coverage.py and the shields.io service. Your README file is then updated with the generated badge.

demo.gif

Source Code: github.com/engineervix/readme-coverage-badger

Contents generated with DocToc

Why this project?

There are so many excellent coverage badge generation tools out there, why do we need another one? Well, at the time of writing this package (circa early 2021), all the existing tools (for example, coverage-badge) I had come across ended at generating SVG/PNG files/strings/Base64 images. What you do with this remains entirely up to you.

Now, it is often much easier to simply use online services such as codecov.io and coveralls.io. These services are free for open source projects, but require a monthly subscription for private repos. Many times, we work on private repos, and we wanna be able to automatically have coverage badges in our READMEs. What if you are unable to pay such subscription fees, or maybe you don't want to use a SaaS? Your solution becomes to generate your own badge!

This is where this project comes in. It automatically generates your project's coverage badge using the shields.io service, and then updates your README accordingly, in just one command! That's all it does, resonating with the Unix philosophy of doing one thing and doing it well. The main idea for this came from istanbul-badges-readme, which does exactly the same thing for JavaScript projects. You will see that these two projects have quite a lot in common.

After using istanbul-badges-readme, I searched for a python alternative but couldn't find anything suitable. The closest I found was coverage-badge, and if you look at this project's code, you will see a lot of similarities with coverage-badge!

If what you're looking for is a powerful, general purpose badge generation tool for your projects, then you should probably check out projects like anybadge and genbadge.

Features

  • automatically generates your project's coverage badge using the shields.io service, and then updates your project's README with the newly generated badge
  • simple CLI tool (readme-cov) with helpful messages
  • tested on python 3.6 to 3.9 with coverage โ‰ฅ 84%
  • free software: BSD-3-Clause license
  • generates different colours depending on the coverage percentage. Optionally generate plain colour (green) regardless of percentage
  • minimal external dependencies โ€“ this tool only has 2 external dependencies; Coverage.py (obviously!) and colorama (for cross-platform coloured terminal output)

The table below shows the coverage thresholds, associated colours and examples of generated badges:

Coverage Colour Example
0 โ‰ค coverage < 40 red Code Coverage Red
40 โ‰ค coverage < 60 orange Code Coverage Orange
60 โ‰ค coverage < 75 yellow Code Coverage Yellow
75 โ‰ค coverage < 90 yellowgreen Code Coverage Yellow Green
90 โ‰ค coverage < 95 green Code Coverage Green
95 โ‰ค coverage โ‰ค 100 brightgreen Code Coverage Bright Green

Installation

pip install readme-coverage-badger

Usage

Note: Before using the tool, ensure that you insert a string of the form ![Code Coverage]() or ![Code Coverage](anything here) in your project's README.

readme-cov [-h] [-v] [-p]

optional arguments:
  -h, --help     show the help message and exit
  -v, --version  show program's version number and exit
  -p, --plain    Plain colour mode. Standard green badge.

The tool operates on the basis of the following assumptions:

  • you have a README.md or README file at the root of your project
  • your README file is in markdown format. I know, some Pythonistas prefer restructuredtext! Sadly, this isn't supported (yet)
  • Somewhere in your your README is a string in the form: ![Code Coverage]() or ![Code Coverage](anything here). This is what gets updated in-place (using re.sub()) when the script runs.
  • the script is called from the root of your project repo, which has coverage.py already configured, and the coverage already updated (you have already run your tests prior to running the script)
  • If the coverage badge in your README file is already up to date, your README file won't be updated, you will only be notified

๐Ÿ’ป Development

First things first

Getting Started

First, fork this repository, then fire up your command prompt and ...

  1. Clone the forked repository
  2. Navigate to the cloned project directory: cd readme_coverage_badger
  3. activate your python virtual environment and pip install --upgrade pip
  4. Install dependencies: pip install -r requirements_dev.txt
  5. Setup pre-commit by running pre-commit install followed by pre-commit install --hook-type commit-msg. Optionally run pre-commit run --all-files to make sure your pre-commit setup is okay.

At this stage, hopefully everything should be working fine, and you should be able to start hacking on the project.

You can run the application via invoke run or

python readme_coverage_badger/__main__.py

Tests

Simply run pytest or invoke test to run tests in your virtual environment.

Test other Python versions by running tox.

Code Formatting

  • Run invoke lint to run flake8, black, isort and mypy on the code.
  • If you get any errors from black and/or isort, run invoke lint --fix or invoke lint -f so that black and isort can format your files. Alternatively, just run pre-commit. You can take a look at .pre-commit-config.yaml.

Author

๐Ÿ‘ค Victor Miti

๐Ÿค Contributing

Contributions, issues and feature requests are most welcome! A good place to start is by helping out with the unchecked items in the TODO section of this README!

Feel free to check the issues page and take a look at the contributing guide before you get started. In addition, please note the following:

  • if you're making code contributions, please try and write some tests to accompany your code, and ensure that the tests pass. Also, were necessary, update the docs so that they reflect your changes.
  • commit your changes via cz commit. Follow the prompts. When you're done, pre-commit will be invoked to ensure that your contributions and commits follow defined conventions. See pre-commit-config.yaml for more details.
  • your commit messages should follow the conventions described here. Write your commit message in the imperative: "Fix bug" and not "Fixed bug" or "Fixes bug." This convention matches up with commit messages generated by commands like git merge and git revert. Once you are done, please create a pull request.

Show your support

Please give a โญ๏ธ if this project helped you!

โœ… TODO

core

  • Cater for not only markdown but also restructuredtext, and automatically detect if a file's syntax is markdown or restructuredtext if no extension given
  • Provide option to generate badge in HTML format
  • Provide option to generate to stdout and skip substitution in a README file. This could be useful if you're using the tool in a script and you just want the result so that you can use it elsewhere.
  • Allow for flexibility in choosing whatever colours one wants
  • Allow for specifying Alt Text on the badge URL, for example ![Alt Text]() or ![Alt Text](anything here)
  • Make the codebase fully typed
  • Improve the Tests by parametrizing fixtures and test functions
  • improve CI/CD to cater for GNU/Linux, Mac OS X and Windows
  • Create pre-commit hook

docs

  • Add a screenshot / demo in this README
  • Create standalone documentation for hosting either on Github Pages or readthedocs. This README is already detailed enough to serve as documentation!

other

  • It would be fun if we had some kind of a badger logo!

๐Ÿ“ License

Copyright ยฉ 2021 Victor Miti.

This project is licensed under the terms of the BSD-3-Clause license.


This README was generated with โค๏ธ by readme-md-generator


readme-coverage-badger's People

Contributors

dependabot[bot] avatar engineervix avatar pre-commit-ci[bot] avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

readme-coverage-badger's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/dispatch.yml
  • actions/checkout v3
  • actions/setup-python v2
  • codecov/codecov-action v2
  • actions/checkout v3
  • actions/setup-python v2
  • softprops/action-gh-release v1
  • ubuntu 20.04
.github/workflows/greetings.yml
  • actions/first-interaction v1
.github/workflows/main.yml
  • actions/checkout v3
  • actions/setup-python v2
  • codecov/codecov-action v2
  • actions/checkout v3
  • actions/setup-python v2
  • softprops/action-gh-release v1
  • ubuntu 20.04
pep621
pyproject.toml
setup-cfg
setup.cfg
  • coverage <6

  • Check this box to trigger a request for Renovate to run again on this repository

Initial Update

The bot created this issue to inform you that pyup.io has been set up on this repo.
Once you have closed it, the bot will open pull requests for updates as soon as they are available.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.