Git Product home page Git Product logo

python-genbadge's Introduction

python-genbadge

Generate badges for tools that do not provide one.

Python versions Build Status Tests Status Coverage Status Flake8 Status

Documentation PyPI Downloads Downloads per week GitHub stars codecov

This is the readme for developers. The documentation for users is available here: https://smarie.github.io/python-genbadge/

Want to contribute ?

Contributions are welcome ! Simply fork this project on github, commit your contributions, and create pull requests.

Here is a non-exhaustive list of interesting open topics: https://github.com/smarie/python-genbadge/issues

nox setup

This project uses nox to define all lifecycle tasks. In order to be able to run those tasks, you should create python 3.7 environment and install the requirements:

>>> conda create -n noxenv python="3.7"
>>> activate noxenv
(noxenv) >>> pip install -r noxfile-requirements.txt

You should then be able to list all available tasks using:

>>> nox --list
Sessions defined in <path>\noxfile.py:

* tests-2.7 -> Run the test suite, including test reports generation and coverage reports.
* tests-3.5 -> Run the test suite, including test reports generation and coverage reports.
* tests-3.6 -> Run the test suite, including test reports generation and coverage reports.
* tests-3.8 -> Run the test suite, including test reports generation and coverage reports.
* tests-3.7 -> Run the test suite, including test reports generation and coverage reports.
- docs-3.7 -> Generates the doc and serves it on a local http server. Pass '-- build' to build statically instead.
- publish-3.7 -> Deploy the docs+reports on github pages. Note: this rebuilds the docs
- release-3.7 -> Create a release on github corresponding to the latest tag

Running the tests and generating the reports

This project uses pytest so running pytest at the root folder will execute all tests on current environment. However it is a bit cumbersome to manage all requirements by hand ; it is easier to use nox to run pytest on all supported python environments with the correct package requirements:

nox

Tests and coverage reports are automatically generated under ./docs/reports for one of the sessions (tests-3.7).

If you wish to execute tests on a specific environment, use explicit session names, e.g. nox -s tests-3.6.

Editing the documentation

This project uses mkdocs to generate its documentation page. Therefore building a local copy of the doc page may be done using mkdocs build -f docs/mkdocs.yml. However once again things are easier with nox. You can easily build and serve locally a version of the documentation site using:

>>> nox -s docs
nox > Running session docs-3.7
nox > Creating conda env in .nox\docs-3-7 with python=3.7
nox > [docs] Installing requirements with pip: ['mkdocs-material', 'mkdocs', 'pymdown-extensions', 'pygments']
nox > python -m pip install mkdocs-material mkdocs pymdown-extensions pygments
nox > mkdocs serve -f ./docs/mkdocs.yml
INFO    -  Building documentation...
INFO    -  Cleaning site directory
INFO    -  The following pages exist in the docs directory, but are not included in the "nav" configuration:
  - long_description.md
INFO    -  Documentation built in 1.07 seconds
INFO    -  Serving on http://127.0.0.1:8000
INFO    -  Start watching changes
...

While this is running, you can edit the files under ./docs/ and browse the automatically refreshed documentation at the local http://127.0.0.1:8000 page.

Once you are done, simply hit <CTRL+C> to stop the session.

Publishing the documentation (including tests and coverage reports) is done automatically by the continuous integration engine, using the nox -s publish session, this is not needed for local development.

Packaging

This project uses setuptools_scm to synchronise the version number. Therefore the following command should be used for development snapshots as well as official releases: python setup.py sdist bdist_wheel. However this is not generally needed since the continuous integration engine does it automatically for us on git tags. For reference, this is done in the nox -s release session.

Merging pull requests with edits - memo

Ax explained in github ('get commandline instructions'):

git checkout -b <git_name>-<feature_branch> master
git pull https://github.com/<git_name>/python-genbadge.git <feature_branch> --no-commit --ff-only

if the second step does not work, do a normal auto-merge (do not use rebase!):

git pull https://github.com/<git_name>/python-genbadge.git <feature_branch> --no-commit

Finally review the changes, possibly perform some modifications, and commit.

python-genbadge's People

Contributors

famura avatar nefrob avatar smarie avatar texnofobix avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

python-genbadge's Issues

support coverage badge generation from pytest --junitxml file

It would be great if we could leverage the same xml from the pytest report generation to generate the coverage badge without needing to install the coverage module.

currently the workflow would be:

# generate reports:
# test report
pytest --cov-report=html:reports/coverage --junitxml=reports/coverage/pytest_coverage.xml
# coverage report
coverage xml -o reports/coverage/coverage.xml

# generate badges
# tests badge
genbadge tests -i < reports/coverage/pytest_coverage.xml -o reports/badges/tests-badge.svg
# coverage badge
genbadge coverage -i reports/coverage/coverage.xml -o reports/badges/coverage-badge.svg

is it possible to consolidate these steps?

pytest --cov-report=html:reports/coverage --junitxml=reports/coverage/pytest_coverage.xml
genbadge tests coverage -i reports/coverage/pytest_coverage.xml -o reports/coverage/

where -o reports/coverage/ will generate badges with default names, and specifying names would require badges to be generated individually.

appreciate the project!
Thanks very much

Issue when using Pillow 10

I just noticed an issue with this library when using Pillow 10: 'FreeTypeFont' object has no attribute 'getsize'.

I ended up downgrading to Pillow 9.5 and things worked okay. Hopefully I can help others if they hit the same error.

Support Python 3.12

Python 3.12 no longer installs setuptools into virtual environments. setuptools is still used by genbadge. Please consider removing the dependency on setuptools or adding it explicitly as a requirement. Similar cases here.

Add an option to provide an alternative badge title/label or to remove it completely

from #6 suggested by @achieveOrbit

Note that

But it is not necessary to align those with the command option.

If this moves further (PRs accepted) we still need to agree on choice of option name. Unfortunately -t ("threshold" in the tests command) and -l ("local" in all commands) are already used. Of course click allow us to not specify a short command, we could only accept a long command. But that would be a little sad...

What about -n/--name ?

I'm open to suggestions here :)

local generator always shows green

Excuse my lack of detail as I am currently on mobile. After trying the svg version setting color="red" creates a green badge.

from genbadge import Badge

b = Badge(left_txt="foo", right_txt="bar", color="red")
print(b)
b.write_to("tmp_badge.svg", use_shields=False)

output from print is:

[ foo | bar ]  color: red

svg shows:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="58" height="20" role="img" aria-label="foo: bar">
	<title>foo: bar</title>
	<linearGradient id="s" x2="0" y2="100%">
		<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
		<stop offset="1" stop-opacity=".1"/>
	</linearGradient>
	<clipPath id="r">
		<rect width="58" height="20" rx="3" fill="#fff"/>
	</clipPath>
	<g clip-path="url(#r)">
		<rect width="29" height="20" fill="#555"/>
		<rect x="29" width="29" height="20" fill="#97ca00"/>
		<rect width="58" height="20" fill="url(#s)"/>
	</g>
	<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110">
		<text aria-hidden="true" x="155.0" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="190">foo</text>
		<text x="155.0" y="140" transform="scale(.1)" fill="#fff" textLength="190">foo</text>
		<text aria-hidden="true" x="425.0" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="190">bar</text>
		<text x="425.0" y="140" transform="scale(.1)" fill="#fff" textLength="190">bar</text>
	</g>
</svg>

which #97ca00 is not red.

Bug report: `genbadge coverage` throws a ZeroDivisionError for coverage.xml generated with no `--cov-branch` option

When coverage.xml is outputted via no --cov-branch option, genbadge coverage throws a ZeroDivisionError.

% genbadge coverage -i coverage.xml                                                                                                                                                                                                                                                                                                       feature/grib-to-dynamodb ✱ ◼
Traceback (most recent call last):
  File "/usr/local/bin/genbadge", line 8, in <module>
    sys.exit(genbadge())
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/genbadge/main.py", line 169, in gen_coverage_badge
    cov_stats = get_coverage_stats(coverage_xml_file=input_file)
  File "/usr/local/lib/python3.9/site-packages/genbadge/utils_coverage.py", line 82, in get_coverage_stats
    cov_stats = parse_cov(coverage_xml_file)
  File "/usr/local/lib/python3.9/site-packages/genbadge/utils_coverage.py", line 119, in parse_cov
    return CovParser().parse(source)
  File "/usr/local/lib/python3.9/site-packages/genbadge/utils_coverage.py", line 128, in parse
    return self.parse_root(root)
  File "/usr/local/lib/python3.9/site-packages/genbadge/utils_coverage.py", line 146, in parse_root
    if not is_close(cov.branch_rate, branch_rate):
  File "/usr/local/lib/python3.9/site-packages/genbadge/utils_coverage.py", line 40, in branch_rate
    return self.branches_covered / self.branches_valid
ZeroDivisionError: division by zero

Is there any option for genbadge coverage to work around?

AttributeError: module 'defusedxml' has no attribute 'ElementTree'

defusedxml is used as an optional dependency for the coverage command in order to protect against XML-based vulnerabilities.

Apparently on some python versions, the following fails

import defusedxml
xml = defusedxml.ElementTree.parse(source)

This seems to be because of the __init__.py of defusedxml: the ElementTree submodule is not listed in __all__ nor imported.

We could just import directly the submodule defusedxml.ElementTree to fix this.

No module named 'pkg_ressources'

After installing with pip install genbadge[all], running any genbadge command gives the following error:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Scripts\genbadge.exe\__main__.py", line 4, in <module>
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\genbadge\__init__.py", line 5, in <module>    
    from .utils_badge import Badge
  File "C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\genbadge\utils_badge.py", line 20, in <module>
    from pkg_resources import resource_string, resource_filename       
ModuleNotFoundError: No module named 'pkg_resources'

genbadge unable to read flake8 output.

I have tried giving no format option, and format=html. Both of them end up with same type of error/warning.
Is this is an encoding issue?.

/home/kabiraatmonallabs/to_githubcodes/addict-tracking-changes/.nox/badges/lib/python3.11/site-packages/genbadge/utils_flake8.py:119: UserWarning: Line in Flake8 statistics report does not match template and will be ignored: '\x1b[1msrc/addict_tracking_changes/init.py\x1b[m\x1b[36m:\x1b[m30\x1b[36m:\x1b[m1\x1b[36m:\x1b[m \x1b[1m\x1b[31mE303\x1b[m too many blank lines (3)'

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.