Compare commits

...

3 Commits

Author SHA1 Message Date
Clemens Schwaighofer
717080a009 Add Text ANSI colors class 2025-07-09 08:54:29 +09:00
Clemens Schwaighofer
19197c71ff README file name fix 2025-07-08 17:50:33 +09:00
Clemens Schwaighofer
051b93f2d8 TLS update in the Readme file 2025-07-08 17:46:00 +09:00
4 changed files with 127 additions and 10 deletions

View File

@@ -39,8 +39,8 @@ explicit = true
```
```sh
uv build --native-tls
uv publish --index egra-gitea --token <gitea token> --native-tls
uv build
uv publish --index egra-gitea --token <gitea token>
```
## Test package
@@ -48,7 +48,7 @@ uv publish --index egra-gitea --token <gitea token> --native-tls
We must set the full index URL here because we run with "--no-project"
```sh
uv run --with corelibs --index egra-gitea=https://git.egplusww.jp/api/packages/PyPI/pypi/simple/ --no-project --native-tls -- python -c "import corelibs"
uv run --with corelibs --index egra-gitea=https://git.egplusww.jp/api/packages/PyPI/pypi/simple/ --no-project -- python -c "import corelibs"
```
### Python tests
@@ -72,15 +72,15 @@ uv run pytest --cov=corelibs
In the test-run folder usage and run tests are located
```sh
uv run --native-tls test-run/progress/progress_test.py
uv run test-run/progress/progress_test.py
```
```sh
uv run --native-tls test-run/double_byte_string_format/double_byte_string_format.py
uv run test-run/double_byte_string_format/double_byte_string_format.py
```
```sh
uv run --native-tls test-run/timestamp_strings/timestamp_strings.py
uv run test-run/timestamp_strings/timestamp_strings.py
```
## How to install in another project
@@ -88,7 +88,7 @@ uv run --native-tls test-run/timestamp_strings/timestamp_strings.py
This will also add the index entry
```sh
uv add corelibs --index egra-gitea=https://git.egplusww.jp/api/packages/PyPI/pypi/simple/ --native-tls
uv add corelibs --index egra-gitea=https://git.egplusww.jp/api/packages/PyPI/pypi/simple/
```
## Python venv setup
@@ -104,3 +104,13 @@ Install all neded dependencies
```sh
uv sync
```
## NOTE on TLS problems
> [!warning] TLS problems with Netskope
If the Netskope service is running all uv runs will fail unless either --native-tls is set or the enviroment variable SSL_CERT_FILE is set, see blow
```sh
export SSL_CERT_FILE='/Library/Application Support/Netskope/STAgent/data/nscacert_combined.pem'
```

View File

@@ -1,9 +1,9 @@
# MARK: Project info
[project]
name = "corelibs"
version = "0.7.0"
version = "0.8.0"
description = "Collection of utils for Python scripts"
readme = "ReadMe.md"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"jmespath>=1.0.1",

View File

@@ -0,0 +1,84 @@
"""
Basic ANSI colors
Set colors with print(f"something {Colors.yellow}colorful{Colors.end})
bold + underline + color combinations are possible.
"""
class Colors:
"""
ANSI colors defined
"""
# General sets
bold = '\033[1m'
underline = '\033[4m'
end = '\033[0m'
reset = '\033[0m'
# Define ANSI color codes as class attributes
black = "\033[30m"
red = "\033[31m"
green = "\033[32m"
yellow = "\033[33m"
blue = "\033[34m"
magenta = "\033[35m"
cyan = "\033[36m"
white = "\033[37m"
# Define bold/bright versions of the colors
black_bold = "\033[1;30m"
red_bold = "\033[1;31m"
green_bold = "\033[1;32m"
yellow_bold = "\033[1;33m"
blue_bold = "\033[1;34m"
magenta_bold = "\033[1;35m"
cyan_bold = "\033[1;36m"
white_bold = "\033[1;37m"
# BRIGHT, alternative
black_bright = '\033[90m'
red_bright = '\033[91m'
green_bright = '\033[92m'
yellow_bright = '\033[93m'
blue_bright = '\033[94m'
magenta_bright = '\033[95m'
cyan_bright = '\033[96m'
white_bright = '\033[97m'
@staticmethod
def disable():
"""
No colors
"""
Colors.bold = ''
Colors.underline = ''
Colors.end = ''
Colors.reset = ''
# normal
Colors.black = ''
Colors.red = ''
Colors.green = ''
Colors.yellow = ''
Colors.blue = ''
Colors.magenta = ''
Colors.cyan = ''
Colors.white = ''
# bold/bright
Colors.black_bold = ''
Colors.red_bold = ''
Colors.green_bold = ''
Colors.yellow_bold = ''
Colors.blue_bold = ''
Colors.magenta_bold = ''
Colors.cyan_bold = ''
Colors.white_bold = ''
# bold/bright alt
Colors.black_bright = ''
Colors.red_bright = ''
Colors.green_bright = ''
Colors.yellow_bright = ''
Colors.blue_bright = ''
Colors.magenta_bright = ''
Colors.cyan_bright = ''
Colors.white_bright = ''
# __END__

View File

@@ -6,6 +6,7 @@ import sys
from decimal import Decimal, getcontext
from textwrap import shorten
from corelibs.string_handling.string_helpers import shorten_string, format_number
from corelibs.string_handling.text_colors import Colors
def __sh_shorten_string():
@@ -16,7 +17,7 @@ def __sh_shorten_string():
result = shorten_string(string, length, placeholder=placeholder)
print(f"IN: {string} -> {result}")
except ValueError as e:
print(f"Failed: {e}")
print(f"{Colors.red}Failed: {Colors.bold}{e}{Colors.end}")
try:
result = shorten(string, width=length, placeholder=placeholder)
print(f"IN: {string} -> {result}")
@@ -51,12 +52,34 @@ def __sh_format_number():
print(f"Format {number} ({precision}) -> {result}")
def _sh_colors():
for color in [
"black",
"red",
"green",
"yellow",
"blue",
"magenta",
"cyan",
"white",
]:
for change in ['', '_bold', '_bright']:
_color = f"{color}{change}"
print(f"Color: {getattr(Colors, _color)}{_color}{Colors.end}")
print(f"Underline: {Colors.underline}UNDERLINE{Colors.reset}")
print(f"Bold: {Colors.bold}BOLD{Colors.reset}")
print(f"Underline/Yellow: {Colors.underline}{Colors.yellow}UNDERLINE YELLOW{Colors.reset}")
print(f"Underline/Yellow/Bold: {Colors.underline}{Colors.bold}{Colors.yellow}UNDERLINE YELLOW BOLD{Colors.reset}")
def main():
"""
Test: corelibs.string_handling.string_helpers
"""
__sh_shorten_string()
__sh_format_number()
_sh_colors()
if __name__ == "__main__":