Git Product home page Git Product logo

anybadge's People

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  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  avatar  avatar  avatar

anybadge's Issues

question - how to produce badge like label : text

Hi, just a question.. somehow I am unable to produce simple texted badge like:

label : value_as_any_text something like this:

text badge

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.

Support badges with 1-N sections (not just name/value)

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)

Based on discussion with @miff2000 in #51.

Add documentation for using custom color codes

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?

Gitlab CI: No such file or directory

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\

Setup failing with errors in README.md

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

Creating multiple badges in a single Python session results in incorrect badge length

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')

image

Integer printed as float

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

Before:
before

After fix:
after

Ability to generate only value badges

Right now if I try to generate a badge with an empty label, it is going to be this way:
image

It is possible to generate without the gray part?

Thank you!

PyPi deploy not working

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)**

  • 3.9

** Operating system: (please complete the following information)**

  • Linux

Add ability to choose text color

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 text

Version 1.10 leads to 1.1

Describe 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

Screenshots
image
image

** Python version: (please complete the following information)**
I use docker image python:3.7.15-alpine.

** Operating system: (please complete the following information)**

  • Linux alpine

** 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...

Feature Request: SemVer support for thresholds

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.

Extra padding around long Value text.

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.

What I wanted:

  • Badge width: about 280
  • Text X: about 170

expected

What anybadge actually made:

  • Badge width: 357
  • Text X: 210

actual

What I wrote:

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!

Allow sub-classing badges to change style/structure

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.

Anybadge can no longer be called as a module

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)**

  • 3.10.2

** Operating system: (please complete the following information)**

  • Mac OS

host the svg created by anybadge

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!

Add logo support

It would be nice to have the option to include logos in badges.

ImportError: cannot import name 'get_template' from 'anybadge.templates' (unknown location)

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

ValueError: invalid literal for int() with base 10: '10.00'

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'

Enable use of templates through python API

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')

Add documentation on how to include emojis

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.

Use python emoji package to support :emoji: format emojis

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

  • Embed emoji svg characters directly into the project
  • Allow images / other svgs to be embedded

Additional context

Relates to #43 and suggested by @roipoussiere

Thoughts on splitting out into modules

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

ImportError: cannot import name 'Badge' from 'anybadge'

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

Drop Python<3.5 and introduce type hints

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.

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.