You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

abadge

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abadge - pypi Package Compare versions

Comparing version
2.0.0
to
2.1.0
+75
-33
abadge.egg-info/PKG-INFO
Metadata-Version: 1.0
Name: abadge
Version: 2.0.0
Version: 2.1.0
Summary: Generate badges/shields with pure HTML/CSS.

@@ -14,3 +14,3 @@ Home-page: https://github.com/Gustra/abadge

.. image:: abadge-discovered.png
.. image:: docs/abadge-discovered.png

@@ -134,2 +134,7 @@ Overview

:``shade``:
Whether to shade the color depending on distance between the thresholds.
Each R, G, and B color is calculated based on the fraction of the distance
of the value between the thresholds
Levels are handled by sorting the keys in the ``colors`` dict and comparing

@@ -144,42 +149,79 @@ the incoming value to each of the keys, starting with the key with the lowest

Examples::
Examples
--------
build_badge = Badge(thresholds={'build': {
'colors': {'SUCCESS': '#0f0',
'FAILURE': '#f00',
'UNSTABLE': '#ff0',
'ABORTED': '#f80',}},
'KPI': {
'order': 'str',
'colors': {'A': '#0f4',
'B': '#f04',
'C': '#f84',
'D': '#ff4',}},
'passrate': {
'colors': {0.3: '#f00',
0.6: '#c40',
0.8: '#4c0',},
'above': '#0f0',}})
One instance can be configure to product different label types::
print(build_badge('build', job.get_status()).to_html())
build_badge = Badge(thresholds={
'build': {
'colors': {'SUCCESS': '#0f0',
'FAILURE': '#f00',
'UNSTABLE': '#ff0',
'ABORTED': '#f80', }},
'KPI': {
'order': 'str',
'colors': {'A': '#0f4',
'B': '#f04',
'C': '#f84',
'D': '#ff4', }},
'passrate': {
'colors': {0.3: '#f00',
0.6: '#c40',
0.8: '#4c0', },
'above': '#0f0', }})
print(build_badge.to_html('build', 'UNSTABLE'))
# Using a non-existing value will use the value_background color
print(build_badge('build', 'SKIP').to_html())
print(build_badge('build', 'HOP', value_background='#888').to_html())
print(build_badge('passrate', test_passrate).to_html())
print(build_badge.to_html('build', 'SKIP'))
print(build_badge.to_html('build', 'HOP', value_background='#ccc'))
print(build_badge.to_html('passrate', 0.5))
.. image:: docs/example-build.png
If the color is not found in ``thresholds`` then the value will be looked
up in the ``value_backgrounds`` dict as a fallback::
build_badge = Badge(thresholds={'build': {
'colors': {'SUCCESS': '#0f0',
'FAILURE': '#f00',
'UNSTABLE': '#ff0',
'ABORTED': '#f80',}}},
value_backgrounds: {'SUCCESS': '#0f4',
'FAILURE': '#f04',
'UNSTABLE': '#f84',
'ABORTED': '#ff4',},)
print(build_badge('test', job.get_status()))
build_badge = Badge(thresholds={
'build': {
'colors': {'SUCCESS': '#0f0',
'FAILURE': '#f00',
'UNSTABLE': '#ff0',
'ABORTED': '#f80', }},
'value_backgrounds': {'SUCCESS': '#0f4',
'FAILURE': '#f04',
'UNSTABLE': '#f84',
'ABORTED': '#ff4'}})
print(build_badge.to_html('test', 'ABORTED'))
.. image:: docs/example-fallback.png
Shading does not produce color steps, but a shade between the colors in the
threshold. Shading only works for "float" and "int" types::
build_badge = Badge(thresholds={
'speed': {
'shade': True,
'colors': {0: '#0f0',
120: '#f00'}, # speed limit
'above': '#f08'}} # too fast!
)
print(build_badge.to_html('speed', 97))
# Here is the rainbow
build_badge = Badge(thresholds={
'rainbow': {
'shade': True,
'colors': {0.0: '#ff0000',
1.0: '#ffff00',
2.0: '#00ff00',
3.0: '#00ffff',
4.0: '#0000ff',
5.0: '#8000ff'}}})
for c in range(0, 11):
print(build_badge.to_html('rainbow', c / 2.0))
.. image:: docs/example-shading.png
Platform: UNKNOWN

@@ -170,5 +170,46 @@ """

'float': lambda f: float(f), }
return casters[order]
return casters[value_type]
@classmethod
def _get_fraction(cls, min, max, value):
"""
Determine the fraction od a value between a min and max
:param min: value which is fraction 0.0
:param max: value which is fraction 1.0
:param value: min <= value <= max
:return: value's fraction between min and max
"""
if max == min:
return 0.0
return (value - min) / (max - min)
@classmethod
def _shade(cls, fraction, color1, color2):
"""
Shades the color between color1 and color2, based on the given
fraction.
:param fraction: distance between color1 and color2.
:param color1: color string in either #rgb or #rrggbb format
:param color2: color string in either #rgb or #rrggbb format
:return: new color string
"""
cols = []
for c in [color1, color2]:
if len(c) == 4:
cols.append([16 * int(i, 16) for i in list(c[1:])])
elif len(c) == 7:
cols.append([int(c[1:3], 16),
int(c[3:5], 16),
int(c[5:7], 16)])
else:
raise ValueError('{}: Error: neither 4 nor 7 characters long'
''.format(c))
shade = ['#']
for i in range(0, 3):
distance = cols[1][i] - cols[0][i]
shade.append('{:02x}'
''.format(int(cols[0][i] + distance * fraction)))
return ''.join(shade)
@classmethod
def _get_value_background(cls, config):

@@ -189,5 +230,14 @@ """

key=lambda v: caster(v))
last = thresholds[0]
for threshold in thresholds:
if caster(config['value']) <= caster(threshold):
if this.get('shade', None):
fraction = cls._get_fraction(last,
threshold,
caster(config['value']))
return cls._shade(fraction,
this['colors'][last],
this['colors'][threshold])
return this['colors'][threshold]
last = threshold
return this['above']

@@ -194,0 +244,0 @@ return this['colors'][config['value']]

+75
-33
Metadata-Version: 1.0
Name: abadge
Version: 2.0.0
Version: 2.1.0
Summary: Generate badges/shields with pure HTML/CSS.

@@ -14,3 +14,3 @@ Home-page: https://github.com/Gustra/abadge

.. image:: abadge-discovered.png
.. image:: docs/abadge-discovered.png

@@ -134,2 +134,7 @@ Overview

:``shade``:
Whether to shade the color depending on distance between the thresholds.
Each R, G, and B color is calculated based on the fraction of the distance
of the value between the thresholds
Levels are handled by sorting the keys in the ``colors`` dict and comparing

@@ -144,42 +149,79 @@ the incoming value to each of the keys, starting with the key with the lowest

Examples::
Examples
--------
build_badge = Badge(thresholds={'build': {
'colors': {'SUCCESS': '#0f0',
'FAILURE': '#f00',
'UNSTABLE': '#ff0',
'ABORTED': '#f80',}},
'KPI': {
'order': 'str',
'colors': {'A': '#0f4',
'B': '#f04',
'C': '#f84',
'D': '#ff4',}},
'passrate': {
'colors': {0.3: '#f00',
0.6: '#c40',
0.8: '#4c0',},
'above': '#0f0',}})
One instance can be configure to product different label types::
print(build_badge('build', job.get_status()).to_html())
build_badge = Badge(thresholds={
'build': {
'colors': {'SUCCESS': '#0f0',
'FAILURE': '#f00',
'UNSTABLE': '#ff0',
'ABORTED': '#f80', }},
'KPI': {
'order': 'str',
'colors': {'A': '#0f4',
'B': '#f04',
'C': '#f84',
'D': '#ff4', }},
'passrate': {
'colors': {0.3: '#f00',
0.6: '#c40',
0.8: '#4c0', },
'above': '#0f0', }})
print(build_badge.to_html('build', 'UNSTABLE'))
# Using a non-existing value will use the value_background color
print(build_badge('build', 'SKIP').to_html())
print(build_badge('build', 'HOP', value_background='#888').to_html())
print(build_badge('passrate', test_passrate).to_html())
print(build_badge.to_html('build', 'SKIP'))
print(build_badge.to_html('build', 'HOP', value_background='#ccc'))
print(build_badge.to_html('passrate', 0.5))
.. image:: docs/example-build.png
If the color is not found in ``thresholds`` then the value will be looked
up in the ``value_backgrounds`` dict as a fallback::
build_badge = Badge(thresholds={'build': {
'colors': {'SUCCESS': '#0f0',
'FAILURE': '#f00',
'UNSTABLE': '#ff0',
'ABORTED': '#f80',}}},
value_backgrounds: {'SUCCESS': '#0f4',
'FAILURE': '#f04',
'UNSTABLE': '#f84',
'ABORTED': '#ff4',},)
print(build_badge('test', job.get_status()))
build_badge = Badge(thresholds={
'build': {
'colors': {'SUCCESS': '#0f0',
'FAILURE': '#f00',
'UNSTABLE': '#ff0',
'ABORTED': '#f80', }},
'value_backgrounds': {'SUCCESS': '#0f4',
'FAILURE': '#f04',
'UNSTABLE': '#f84',
'ABORTED': '#ff4'}})
print(build_badge.to_html('test', 'ABORTED'))
.. image:: docs/example-fallback.png
Shading does not produce color steps, but a shade between the colors in the
threshold. Shading only works for "float" and "int" types::
build_badge = Badge(thresholds={
'speed': {
'shade': True,
'colors': {0: '#0f0',
120: '#f00'}, # speed limit
'above': '#f08'}} # too fast!
)
print(build_badge.to_html('speed', 97))
# Here is the rainbow
build_badge = Badge(thresholds={
'rainbow': {
'shade': True,
'colors': {0.0: '#ff0000',
1.0: '#ffff00',
2.0: '#00ff00',
3.0: '#00ffff',
4.0: '#0000ff',
5.0: '#8000ff'}}})
for c in range(0, 11):
print(build_badge.to_html('rainbow', c / 2.0))
.. image:: docs/example-shading.png
Platform: UNKNOWN

@@ -6,3 +6,3 @@ abadge

.. image:: abadge-discovered.png
.. image:: docs/abadge-discovered.png

@@ -126,2 +126,7 @@ Overview

:``shade``:
Whether to shade the color depending on distance between the thresholds.
Each R, G, and B color is calculated based on the fraction of the distance
of the value between the thresholds
Levels are handled by sorting the keys in the ``colors`` dict and comparing

@@ -136,40 +141,77 @@ the incoming value to each of the keys, starting with the key with the lowest

Examples::
Examples
--------
build_badge = Badge(thresholds={'build': {
'colors': {'SUCCESS': '#0f0',
'FAILURE': '#f00',
'UNSTABLE': '#ff0',
'ABORTED': '#f80',}},
'KPI': {
'order': 'str',
'colors': {'A': '#0f4',
'B': '#f04',
'C': '#f84',
'D': '#ff4',}},
'passrate': {
'colors': {0.3: '#f00',
0.6: '#c40',
0.8: '#4c0',},
'above': '#0f0',}})
One instance can be configure to product different label types::
print(build_badge('build', job.get_status()).to_html())
build_badge = Badge(thresholds={
'build': {
'colors': {'SUCCESS': '#0f0',
'FAILURE': '#f00',
'UNSTABLE': '#ff0',
'ABORTED': '#f80', }},
'KPI': {
'order': 'str',
'colors': {'A': '#0f4',
'B': '#f04',
'C': '#f84',
'D': '#ff4', }},
'passrate': {
'colors': {0.3: '#f00',
0.6: '#c40',
0.8: '#4c0', },
'above': '#0f0', }})
print(build_badge.to_html('build', 'UNSTABLE'))
# Using a non-existing value will use the value_background color
print(build_badge('build', 'SKIP').to_html())
print(build_badge('build', 'HOP', value_background='#888').to_html())
print(build_badge('passrate', test_passrate).to_html())
print(build_badge.to_html('build', 'SKIP'))
print(build_badge.to_html('build', 'HOP', value_background='#ccc'))
print(build_badge.to_html('passrate', 0.5))
.. image:: docs/example-build.png
If the color is not found in ``thresholds`` then the value will be looked
up in the ``value_backgrounds`` dict as a fallback::
build_badge = Badge(thresholds={'build': {
'colors': {'SUCCESS': '#0f0',
'FAILURE': '#f00',
'UNSTABLE': '#ff0',
'ABORTED': '#f80',}}},
value_backgrounds: {'SUCCESS': '#0f4',
'FAILURE': '#f04',
'UNSTABLE': '#f84',
'ABORTED': '#ff4',},)
print(build_badge('test', job.get_status()))
build_badge = Badge(thresholds={
'build': {
'colors': {'SUCCESS': '#0f0',
'FAILURE': '#f00',
'UNSTABLE': '#ff0',
'ABORTED': '#f80', }},
'value_backgrounds': {'SUCCESS': '#0f4',
'FAILURE': '#f04',
'UNSTABLE': '#f84',
'ABORTED': '#ff4'}})
print(build_badge.to_html('test', 'ABORTED'))
.. image:: docs/example-fallback.png
Shading does not produce color steps, but a shade between the colors in the
threshold. Shading only works for "float" and "int" types::
build_badge = Badge(thresholds={
'speed': {
'shade': True,
'colors': {0: '#0f0',
120: '#f00'}, # speed limit
'above': '#f08'}} # too fast!
)
print(build_badge.to_html('speed', 97))
# Here is the rainbow
build_badge = Badge(thresholds={
'rainbow': {
'shade': True,
'colors': {0.0: '#ff0000',
1.0: '#ffff00',
2.0: '#00ff00',
3.0: '#00ffff',
4.0: '#0000ff',
5.0: '#8000ff'}}})
for c in range(0, 11):
print(build_badge.to_html('rainbow', c / 2.0))
.. image:: docs/example-shading.png