jongracecox / anybadge Goto Github PK
View Code? Open in Web Editor NEWA Python project for generating badges for your projects, with a focus on simplicity and flexibility.
License: MIT License
A Python project for generating badges for your projects, with a focus on simplicity and flexibility.
License: MIT License
Hi, just a question.. somehow I am unable to produce simple texted badge like:
label : value_as_any_text something like this:
I've tried in terminal but got back error message that -v is expected to be number. If someone can point me in right direction what I am missing here, that would be fantastic. Thank you.
Describe the solution you'd like
Anybadge has two sections in a badge: the label and the value. In GitLab there are labels
which have one section. We may also want badges with more than 2 sections. It would be nice to be generic enough to support badges with any number of sections.
Sections could be represented in styles (see #61)
Switch README doc to .rst
so that we only need one file for GitHub and for PyPi.
I love anybadge and use it regularly to create any kind of badges for my projects in gitlab ci (primarily because it is small, and dependencies are installed quickly).
Today I wanted to create a badge with color "blue" - but blue doesn't exist in the default list of colors.
I've used a detour to add "blue" to anybadge, e.g.:
python -c "import anybadge; anybadge.COLORS['blue'] = '#1182C3'; print(anybadge.COLORS.get('blue'))"
However, this seems rather cumbersome and it is also not documented.
Is there an alternative to using custom color codes I perhaps missed?
I am running pylint with a gitlab runner.
The problem is, that the anybadge command fails with 'no such file or directory'.
Maybe in anybadge.py is a w+ needed?
(Sorry for this horrible code paste but GitHub did not recognise the backticks here.
with open(path, mode='w') as file_handle:
$ sed -n 's/^Your code has been rated at ([-0-9.])/./\1/p' pylint.txt
8.67
$ echo $score
8.67
$ echo "Pylint score was $score"
Pylint score was 8.67
$ anybadge --value=$score --file=public/pylint.svg pylint
Traceback (most recent call last):
File "/usr/local/bin/anybadge", line 10, in
sys.exit(main())
File "/usr/local/lib/python3.7/site-packages/anybadge.py", line 751, in main
badge.write_badge(args.file, overwrite=args.overwrite)
File "/usr/local/lib/python3.7/site-packages/anybadge.py", line 524, in write_badge
with open(path, mode='w') as file_handle:
FileNotFoundError: [Errno 2] No such file or directory: '/builds/.../.../public/pylint.svg\
While running setup.py
I get the following error:
Traceback (most recent call last):
File "setup.py", line 18, in <module>
', '.join([e.message for e in errors]))
ValueError: ('README.md contains errors: ', 'Bullet list ends without a blank line; unexpected unindent., Bullet list ends without a blank line; unexpected unindent., Bullet list ends without a blank line; unexpected unindent., Bullet list ends without a blank line; unexpected unindent., Bullet list ends without a blank line; unexpected unindent., Bullet list ends without a blank line; unexpected unindent., Bullet list ends without a blank line; unexpected unindent., Bullet list ends without a blank line; unexpected unindent., Bullet list ends without a blank line; unexpected unindent., Bullet list ends without a blank line; unexpected unindent., Bullet list ends without a blank line; unexpected unindent., Bullet list ends without a blank line; unexpected unindent., Bullet list ends without a blank line; unexpected unindent., Bullet list ends without a blank line; unexpected unindent., Bullet list ends without a blank line; unexpected unindent., Bullet list ends without a blank line; unexpected unindent., Bullet list ends without a blank line; unexpected unindent., Bullet list ends without a blank line; unexpected unindent., Bullet list ends without a blank line; unexpected unindent., Bullet list ends without a blank line; unexpected unindent., Bullet list ends without a blank line; unexpected unindent., Error parsing content block for the "list-table" directive: two-level bullet list expected, but row 2 does not contain a second-level bullet list.')
The command I am using is:
python3 setup.py bdist_wheel
After installing 1.1.1 of anybadge, querying anybadge.version
returns 0.1.0.dev2
.
from anybadge import Badge, version
badges = [
Badge('version', version),
Badge('pylint', 1.23, thresholds={
2:'red', 4: 'orange', 8: 'yellow', 10: 'green'}),
Badge('awesomeness', '100%'),
Badge('pylint', 9, thresholds={
2:'red', 4: 'orange', 8: 'yellow', 10: 'green'})
]
from flask import Flask
app = Flask(__name__, static_folder='.')
@app.route('/')
def root():
return ' <br> '.join([b.badge_svg_text for b in badges])
app.run(host='0.0.0.0', port='3000')
While looking at fixed-widths
branch for #24, I noticed that integer values seemed to get marked as float
instead of int
as intended. Since it's a simple fix, I didn't think it needed a full PR, but I can make one if you'd like.
diff --git a/anybadge.py b/anybadge.py
index 5cc9f04..5dd00b3 100755
--- a/anybadge.py
+++ b/anybadge.py
@@ -307,12 +307,11 @@ class Badge(object):
Returns: type
"""
+ if self.value_is_int:
+ return int
if self.value_is_float:
return float
- elif self.value_is_int:
- return int
- else:
- return str
+ return str
@property
def label_width(self):
Test:
python ./anybadge.py -l "test" -v "1234" -f ./test.svg -o
Describe the bug
When 1.10.0 release was created the CI pipeline should have deployed to PyPi, but it didn't.
To Reproduce
Cut a release and wait...
Expected behavior
Travis pipeline should have deployed to PyPi
** Python version: (please complete the following information)**
** Operating system: (please complete the following information)**
Add the ability to change the text color.
Add options:
--text-color
for all text on the badge
--text-color=black
for passing single color--text-color=#010101|#f2f2f2
for passing left and right colors--label-text-color
for label text--value-text-color
for value textDescribe the bug
When I use command anybadge -l "Version" -v 1.10 -f version.svg -c blue
I got 1.1 on the badge.
To Reproduce
Just run anybadge -l "Version" -v 1.10 -f version.svg -c blue
Expected behavior
The version should be 1.10 on the badge
** Python version: (please complete the following information)**
I use docker image python:3.7.15-alpine.
** Operating system: (please complete the following information)**
** Additional information **
The same behaviour with 1.20, 1.30, 1.100 etc but 1.18, 1.21 works properly. Seems something wrong with last 0 symbol...
It would be a nice touch to be able to add semver as thresholds in a pattern "-c green 2.4.5=orange 2.4.0=red" so that anything below or equal to 2.4.0 would be red, anything between 2.4.5 and 2.4.0 would be orange and anything over 2.4.5 (2.4.6 for example) would be green.
Love the library. Been using it a lot!
I recently had a need/desire to put a long piece of text in a badge and found that there was lots of padding around the value.
anybadge
actually made:badge = anybadge.Badge(label='CppCheck',
value='err: 2 | warn: 9 | info: 99 | style: 365',
default_color='red',
num_padding_chars=0)
badge.write_badge('cppcheck.svg', overwrite=True)
Any way to get rid of the extra whitespace?
Cheers!
Is your feature request related to a problem? Please describe.
Support more extreme customization and configuration - allow more flexible templating and styling.
Describe the solution you'd like
In order to allow more customization and nuanced styles the badge class should be able to be subclassed, or maybe separate out aspects of the style into a separate class (BadgeStyle
). The style class could be responsible for calculations, allowing the main badge package to deal with the macro aspects of generation.
Describe alternatives you've considered
Could use Jinja2 templates (which support math functions)
Additional context
Ideas originating from discussion with @miff2000 in #51.
Describe the bug
I was using anybadge like this:
$ python -m anybadge ...
Until 1.9.0, this was supported. However, since 1.11.1, this no longer works.
To Reproduce
$ python -m anybadge
../bin/python: No module named anybadge.__main__; 'anybadge' is a package and cannot be directly executed
Expected behavior
The anybadge cli should be executed just as when anybadge
is called directly.
$ anybadge
usage: anybadge [-h] [-l LABEL] -v VALUE [-m VALUE_FORMAT] [-c COLOR] [-p PREFIX] [-s SUFFIX] [-d PADDING] [-lp LABEL_PADDING] [-vp VALUE_PADDING] [-n FONT]
[-z FONT_SIZE] [-t TEMPLATE] [-st STYLE] [-u] [-f FILE] [-o] [-r TEXT_COLOR] [-e]
...
anybadge: error: the following arguments are required: -v/--value
** Python version: (please complete the following information)**
** Operating system: (please complete the following information)**
Missing this makes anybadge.server
not importable, breaking anybadge-server sli.
is there anyway to host and update the svg badge file created by anybadge dynamically on github so we can embed it on README? I couldn't figure out a working solution.. need some guidance. thanks!
It would be nice to have the option to include logos in badges.
Recently just started getting this error in my linux CI jobs and am also able to reproduce it locally on macOS
% python3 -m anybadge
Traceback (most recent call last):
File "/opt/homebrew/Cellar/[email protected]/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 187, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/opt/homebrew/Cellar/[email protected]/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 146, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/opt/homebrew/Cellar/[email protected]/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 110, in _get_module_details
__import__(pkg_name)
File "/opt/homebrew/lib/python3.10/site-packages/anybadge/__init__.py", line 2, in <module>
from .badge import Badge
File "/opt/homebrew/lib/python3.10/site-packages/anybadge/badge.py", line 13, in <module>
from .templates import get_template
ImportError: cannot import name 'get_template' from 'anybadge.templates' (unknown location)
% python3 -m pip show anybadge
Name: anybadge
Version: 1.11.0
Summary: Simple, flexible badge generator for project badges.
Home-page: https://github.com/jongracecox/anybadge
Author: Jon Grace-Cox
Author-email: [email protected]
License:
Location: /opt/homebrew/lib/python3.10/site-packages
Requires: packaging
Required-by:
% python3 --version
Python 3.10.5
Today our CI broke with the latest version in pipy.
I saw some fix commits on the repo, not sure if it was published into pipy.
Thanks!
Traceback (most recent call last):
File "/builds/faradaysec/faraday/faraday_venv/bin/anybadge", line 10, in <module>
sys.exit(main())
File "/builds/faradaysec/faraday/faraday_venv/local/lib/python2.7/site-packages/anybadge.py", line 755, in main
value_format=args.value_format, text_color=args.text_color)
File "/builds/faradaysec/faraday/faraday_venv/local/lib/python2.7/site-packages/anybadge.py", line 191, in __init__
value_text = str(self.value_type(value))
ValueError: invalid literal for int() with base 10: '10.00'
Templates can be used through command line usage, but not available through Python code. This issue is to surface the templates when creating a Badge class instance. For example:
b = Badge('pylint', 2.22, template='pylint')
The "brightgreen" color doesn't look very nice, so should be removed from the list of available colors, and from the pylint and coverage defaults.
It could be nice to support emojis in badges.
My use case is that I often create badges for simple links, and in this case the label could just be the emoji ๐:
anybadge --label='๐' --value='doc' --color=orange
anybadge --label='๐' --value='pypi' --color=blue
But it could be used for other use cases.
Include something like this into the documentation:
Is your feature request related to a problem? Please describe.
Make it easier to include emojis in badges by allowing :emoji:
text in labels and values to be converted into the emoji character.
Some developer IDEs and consoles make it difficult to include emojis, so this would make it easier.
Describe the solution you'd like
Add new dependency: https://pypi.org/project/emoji/
Use emoji.emojize()
on labels and values to switch emoji text to an emoji character.
Ensure that emojize
is run before calculating badge dimensions.
Describe alternatives you've considered
Additional context
Relates to #43 and suggested by @roipoussiere
Hey!
First of all, thanks for creating this! It's fantastic and is really simple to use / import. I also love the fact you included a webserver for it, ace!
I wanted to ask, what your thoughts are on splitting out the single anybadge.py
file into separate files? You'll see I've added PR #50 to support a new format called GitLab Scoped
, and would like to add other formats in future. As the file will grow exponentially as a result, it seemed to me to be a good time to externalise the Badge
class.
We can then add other classes (e.g., GitLabScopedBadge
) easily and import the class as needed, perhaps based on the --style
flag.
I don't want to set off and do that work though unless you're happy and the PR is likely to be accepted of course ๐
Let me know what you think anyway.
Cheers
Hi there, I'm trying to use code snippet from README.md:
import anybadge
# Define thresholds: <2=red, <4=orange <8=yellow <10=green
thresholds = {2: 'red',
4: 'orange',
6: 'yellow',
10: 'green'}
badge = anybadge.Badge('pylint', 2.22, thresholds=thresholds)
badge.write_badge('pylint.svg')
And getting ImportError: cannot import name 'Badge' from 'anybadge'
error.
Reproduced in both Python 2.7 and 3.7 environments, I used Docker:
FROM python:3.7
RUN apt-get update -y && \
apt-get install nano -y && \
pip install anybadge && \
pip list
COPY . /opt
RUN python /opt/anybadge.py
..and anybadge.py
with code above
Is your feature request related to a problem? Please describe.
When using your awesome project in typed project/library, it is better that anybadge is typed strictly.
Describe the solution you'd like
I think package's python_requires
should be >=3.7
(or at least >=3.5
) to add type hints and drop EOL'd versions.
And I suggest to setup mypy (or pyre) with setup.cfg and add it to CI steps.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.