Skip to content

Commit

Permalink
Windows fmt compatibility
Browse files Browse the repository at this point in the history
Windows terminal colors support
Setup requirements from requirements.txt
  • Loading branch information
andgineer committed Mar 13, 2020
1 parent 0d352e3 commit f7c3936
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 15 deletions.
6 changes: 6 additions & 0 deletions bombard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import colorama


colorama.init() # On Windows will filter ANSI escape sequences out of any text sent to
# stdout or stderr, and replace them with equivalent Win32 calls.

__version__ = '1.19.1'


Expand Down
2 changes: 1 addition & 1 deletion bombard/bombardier.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from bombard.show_descr import markdown_for_terminal
from bombard.http_request import http_request, EXCEPTION_STATUS
from bombard import request_logging
from collections import Mapping
from typing import Mapping


log = logging.getLogger()
Expand Down
2 changes: 1 addition & 1 deletion bombard/request_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def setup_logging(level: int, log_file_name: Optional[str] = None):
formatter = RequestFormatter(
fmt=f'%(colour)s%(asctime)s %(requestid)s %(elapsed)s (thread %(threadid)s) '
f'%(requestname)s %(dir)s %(message)s{OFF}',
datefmt='%-d %b %H:%M:%S'
datefmt='%d %b %H:%M:%S'
)
handler.setFormatter(formatter)
handler.setLevel(level)
Expand Down
30 changes: 20 additions & 10 deletions bombard/terminal_colours.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@
source https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
You can use it function style
green('Hello!')
>>> green('Hello!')
'\\x1b[1;32mHello!\\x1b[0m'
Or include style
f'{YELLOW}Hello{OFF}, {RED}world{OFF}!'
>>> f'{YELLOW}Hello{OFF}, {RED}world{OFF}!'
'\\x1b[1;33mHello\\x1b[0m, \\x1b[1;31mworld\\x1b[0m!'
Under the hood this is colorama.
But I keep my wrapper in this module as legacy.
"""

GREEN = '\033[1;32;40m'
RED = '\033[1;31;40m'
DARK_RED = '\033[0;31;40m'
GRAY = '\033[1;30;40m'
BROWN = '\033[0;33;40m'
YELLOW = '\033[1;33;40m'
from colorama.ansi import code_to_chars, AnsiFore, AnsiStyle


GREEN = code_to_chars(f'{AnsiStyle.BRIGHT};{AnsiFore.GREEN}')
RED = code_to_chars(f'{AnsiStyle.BRIGHT};{AnsiFore.RED}')
DARK_RED = code_to_chars(f'{AnsiStyle.DIM};{AnsiFore.RED}')
GRAY = code_to_chars(f'{AnsiStyle.BRIGHT};{AnsiFore.BLACK}')
BROWN = code_to_chars(f'{AnsiStyle.DIM};{AnsiFore.YELLOW}')
YELLOW = code_to_chars(f'{AnsiStyle.BRIGHT};{AnsiFore.YELLOW}')

OFF = '\033[0m'
OFF = code_to_chars(AnsiStyle.RESET_ALL)


def paint_it(msg: str, colour: str) -> str:
Expand Down Expand Up @@ -49,4 +57,6 @@ def yellow(s: str) -> str:

if __name__ == "__main__":
import doctest
doctest.testmod()
fail, total = doctest.testmod(report=True)
if not fail:
print(f'... {total} test(s) passed')
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pyyaml>=5.1
pygments
colorama
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
with open("README.rst", "r") as fh:
long_description = fh.read()

with open('requirements.txt') as f:
requirements = f.read().splitlines()

import sys; sys.path.insert(0, '../'); import bombard

setuptools.setup(
Expand All @@ -22,9 +25,7 @@
url="https://bombard.readthedocs.io/en/latest/",
packages=setuptools.find_packages(),
include_package_data=True,
install_requires=[
'pyyaml>=5.1',
],
install_requires=requirements,
keywords='http load test parallel',
classifiers=[
"Programming Language :: Python :: 3",
Expand Down

0 comments on commit f7c3936

Please sign in to comment.