Skip to content

Commit 015ceb6

Browse files
committed
Follow no-single-letter-names everywhere, remove redundant format code prefixes, reformat all docstrings & linting
1 parent 881ae5b commit 015ceb6

27 files changed

Lines changed: 1761 additions & 1349 deletions

.style.yapf

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
[style]
2+
ALLOW_SPLIT_BEFORE_DICT_VALUE = true
23
BASED_ON_STYLE = pep8
4+
BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF = 1
5+
BLANK_LINES_BETWEEN_TOP_LEVEL_IMPORTS_AND_VARIABLES = 2
6+
COALESCE_BRACKETS = true
37
COLUMN_LIMIT = 127
4-
ALLOW_SPLIT_BEFORE_DICT_VALUE = true
5-
SPLIT_BEFORE_FIRST_ARGUMENT = true
6-
SPLIT_BEFORE_LOGICAL_OPERATOR = true
7-
SPLIT_BEFORE_BITWISE_OPERATOR = true
8-
SPLIT_BEFORE_ARITHMETIC_OPERATOR = true
9-
SPLIT_BEFORE_DOT = true
10-
SPLIT_COMPLEX_COMPREHENSION = false
118
DEDENT_CLOSING_BRACKETS = true
12-
INDENT_CLOSING_BRACKETS = false
13-
COALESCE_BRACKETS = true
14-
EACH_DICT_ENTRY_ON_SEPARATE_LINE = false
15-
BLANK_LINES_BETWEEN_TOP_LEVEL_IMPORTS_AND_VARIABLES = 2
169
DISABLE_SPLIT_LIST_WITH_COMMENT = true
10+
EACH_DICT_ENTRY_ON_SEPARATE_LINE = false
11+
INDENT_CLOSING_BRACKETS = false
1712
SPACES_AROUND_SUBSCRIPT_COLON = false
1813
SPACES_BEFORE_COMMENT = 2
19-
BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF = 1
14+
SPLIT_BEFORE_ARITHMETIC_OPERATOR = true
15+
SPLIT_BEFORE_BITWISE_OPERATOR = true
16+
SPLIT_BEFORE_DOT = true
17+
SPLIT_BEFORE_FIRST_ARGUMENT = true
18+
SPLIT_BEFORE_LOGICAL_OPERATOR = true
19+
SPLIT_COMPLEX_COMPREHENSION = false

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121

2222
* Unified all error messages throughout the whole library, to always pass the given value if the error is caused by that value being invalid.
2323
* Added a new param `allow_space_value` to `Console.get_args()` and made `flag_value_sep` optional, which allows you to specify whether flags should be able to receive their values with a space in between (*e.g.* `--flag value` instead of just `--flag=value`).
24+
* Reformat all docstrings of the whole library.
25+
26+
**BREAKING CHANGES:**
27+
* Renamed `r`, `g`, `b` and `a` to `red`, `green`, `blue` and `alpha` everywhere in the library, to follow the no-single-letter-names convention.
28+
* Renamed `h`, `s` and `l` to `hue`, `sat` and `light` everywhere in the library, to follow the no-single-letter-names convention.
29+
* Renamed the `Console.w` and `Console.h` properties to `Console.width` and `Console.height`, to follow the no-single-letter-names convention.
30+
* Removed the `background:` and `bright:` prefixes from the library, so now you can just use the `bg:` and `br:` ones, for consistency.
2431

2532

2633
<span id="v1-9-7" />

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![](https://img.shields.io/pypi/v/xulbux?style=flat&labelColor=404560&color=7075FF)](https://pypi.org/project/xulbux) [![](https://img.shields.io/pepy/dt/xulbux?style=flat&labelColor=404560&color=7075FF)](https://clickpy.clickhouse.com/dashboard/xulbux) [![](https://img.shields.io/github/license/xulbux/python-lib-xulbux?style=flat&labelColor=405555&color=70FFEE)](https://github.com/xulbux/python-lib-xulbux/blob/main/LICENSE) [![](https://img.shields.io/github/last-commit/xulbux/python-lib-xulbux?style=flat&labelColor=554045&color=FF6065)](https://github.com/xulbux/python-lib-xulbux/commits) [![](https://img.shields.io/github/issues/xulbux/python-lib-xulbux?style=flat&labelColor=554045&color=FF6065)](https://github.com/xulbux/python-lib-xulbux/issues) [![](https://img.shields.io/github/stars/xulbux/python-lib-xulbux?label=★&style=flat&labelColor=604A40&color=FF9673)](https://github.com/xulbux/python-lib-xulbux/stargazers)
44

55
**`xulbux`** is a library that contains many useful classes, types, and functions,
6-
ranging from console logging and working with colors to file management and system operations.
6+
ranging from terminal logging and working with colors to file management and system operations.
77
The library is designed to simplify common programming tasks and improve code readability through its collection of tools.
88

99
For precise information about the library, see the library's [**documentation**](https://github.com/xulbux/python-lib-xulbux/wiki).<br>
@@ -17,28 +17,28 @@ For the libraries latest changes and updates, see the [**change log**](https://g
1717

1818
## Installation
1919

20-
Run the following commands in a console with administrator privileges, so the actions take effect for all users.
20+
Run the following commands in a terminal with administrator privileges, so the actions take effect for all users.
2121

2222
Install the library and all its dependencies with the command:
23-
```console
23+
```shell
2424
pip install xulbux
2525
```
2626

2727
Upgrade the library and all its dependencies to their latest available version with the command:
28-
```console
28+
```shell
2929
pip install --upgrade xulbux
3030
```
3131

3232
<br>
3333

3434
## CLI Commands
3535

36-
When the library is installed, the following commands are available in the console:
36+
When the library is installed, the following commands are available in the terminal:
3737

38-
| Command | Description |
39-
| :---------------- | :--------------------------------------------------------------- |
40-
| `xulbux-lib` | Show some information about the library. |
41-
| `xulbux-lib fc` | Parse and render a string's format codes as ANSI console output. |
38+
| Command | Description |
39+
| :---------------- | :---------------------------------------------------------------- |
40+
| `xulbux-lib` | Show some information about the library. |
41+
| `xulbux-lib fc` | Parse and render a string's format codes as ANSI terminal output. |
4242

4343
<br>
4444

@@ -131,7 +131,7 @@ from xulbux.color import rgba, hsla, hexa
131131
<tr>
132132
<td><a href="https://github.com/xulbux/python-lib-xulbux/wiki/format_codes"><img src="https://img.shields.io/badge/format__codes-B272FC?style=for-the-badge" alt="format_codes"></a></td>
133133
<td><code>FormatCodes</code> class, which includes methods to print and work with strings that contain<br>
134-
special formatting codes, which are then converted to ANSI codes for pretty console output.</td>
134+
special formatting codes, which are then converted to ANSI codes for pretty terminal output.</td>
135135
</tr>
136136
<tr>
137137
<td><a href="https://github.com/xulbux/python-lib-xulbux/wiki/json"><img src="https://img.shields.io/badge/json-B272FC?style=for-the-badge" alt="json"></a></td>

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def generate_stubs_for_package():
6161

6262
print(f"\nStub generation complete. ({generated_count} generated, {skipped_count} copied)\n")
6363

64-
except Exception as e:
65-
fmt_error = "\n ".join(str(e).splitlines())
64+
except Exception as exc:
65+
fmt_error = "\n ".join(str(exc).splitlines())
6666
print(f"[WARNING] Could not generate stubs:\n {fmt_error}\n")
6767

6868

src/xulbux/base/consts.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class ANSI:
9090
@classmethod
9191
def seq(cls, placeholders: int = 1, /) -> FormattableString:
9292
"""Generates an ANSI escape sequence with the specified number of placeholders."""
93+
9394
return cls.CHAR + cls.START + cls.SEP.join(["{}" for _ in range(placeholders)]) + cls.END
9495

9596
SEQ_COLOR: Final[FormattableString] = CHAR + START + "38" + SEP + "2" + SEP + "{}" + SEP + "{}" + SEP + "{}" + END
@@ -123,14 +124,6 @@ def seq(cls, placeholders: int = 1, /) -> FormattableString:
123124
"br:magenta",
124125
"br:cyan",
125126
"br:white",
126-
"bright:black",
127-
"bright:red",
128-
"bright:green",
129-
"bright:yellow",
130-
"bright:blue",
131-
"bright:magenta",
132-
"bright:cyan",
133-
"bright:white",
134127
}
135128
"""All color variants that can be used in formatting."""
136129

src/xulbux/base/decorators.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ def mypyc_attr(**kwargs: Any) -> Callable[[T], T]:
1818
or acts as a no-op decorator when `mypy_extensions` is not installed.\n
1919
This allows the use of `mypyc` compilation hints for compiling without making
2020
`mypy_extensions` a required dependency.\n
21-
-----------------------------------------------------------------------------------------
22-
- `**kwargs` -⠀keyword arguments to pass to `mypy_extensions.mypyc_attr` if available"""
21+
-------------------------------------------------------------------------------------------
22+
* `**kwargs` – keyword arguments to pass to `mypy_extensions.mypyc_attr` if available"""
23+
2324
try:
2425
from mypy_extensions import mypyc_attr as _mypyc_attr
2526
return _mypyc_attr(**kwargs)

src/xulbux/base/types.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,24 @@
4040

4141
class _RgbaObj(Protocol):
4242
"""Protocol for rgba-like color objects (structurally matches `rgba`)."""
43-
r: int
44-
g: int
45-
b: int
46-
a: Optional[float]
43+
red: int
44+
green: int
45+
blue: int
46+
alpha: Optional[float]
4747

4848
class _HslaObj(Protocol):
4949
"""Protocol for hsla-like color objects (structurally matches `hsla`)."""
50-
h: int
51-
s: int
52-
l: int
53-
a: Optional[float]
50+
hue: int
51+
sat: int
52+
light: int
53+
alpha: Optional[float]
5454

5555
class _HexaObj(Protocol):
5656
"""Protocol for hexa-like color objects (structurally matches `hexa`)."""
57-
r: int
58-
g: int
59-
b: int
60-
a: Optional[float]
57+
red: int
58+
green: int
59+
blue: int
60+
alpha: Optional[float]
6161

6262
Rgba: TypeAlias = Union[
6363
tuple[Int_0_255, Int_0_255, Int_0_255],
@@ -118,24 +118,24 @@ class ArgData(TypedDict):
118118

119119
class RgbaDict(TypedDict):
120120
"""Dictionary schema for RGBA color components."""
121-
r: Int_0_255
122-
g: Int_0_255
123-
b: Int_0_255
124-
a: Optional[Float_0_1]
121+
red: Int_0_255
122+
green: Int_0_255
123+
blue: Int_0_255
124+
alpha: Optional[Float_0_1]
125125

126126
class HslaDict(TypedDict):
127127
"""Dictionary schema for HSLA color components."""
128-
h: Int_0_360
129-
s: Int_0_100
130-
l: Int_0_100
131-
a: Optional[Float_0_1]
128+
hue: Int_0_360
129+
sat: Int_0_100
130+
light: Int_0_100
131+
alpha: Optional[Float_0_1]
132132

133133
class HexaDict(TypedDict):
134134
"""Dictionary schema for HEXA color components."""
135-
r: str
136-
g: str
137-
b: str
138-
a: Optional[str]
135+
red: str
136+
green: str
137+
blue: str
138+
alpha: Optional[str]
139139

140140
class MissingLibsMsgs(TypedDict):
141141
"""Configuration schema for custom messages in `System.check_libs()` when checking library dependencies."""
@@ -146,7 +146,7 @@ class MissingLibsMsgs(TypedDict):
146146
################################################## Protocol ##################################################
147147

148148
class ProgressUpdater(Protocol):
149-
"""Protocol for a progress updater function used in console progress bars."""
149+
"""Protocol for a progress updater function used in terminal progress bars."""
150150

151151
def __call__(self, current: Optional[int] = None, label: Optional[str] = None) -> None:
152152
"""Update the current progress value and/or label."""

src/xulbux/cli/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
def main() -> None:
55
"""Main entry point for the `xulbux-lib` CLI command."""
6+
67
match sys.argv[1] if len(sys.argv) > 1 else "":
78
case "fc":
89
from .tools import render_format_codes

src/xulbux/cli/help.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,27 @@
1010

1111
def get_latest_version() -> Optional[str]:
1212
"""Fetches the latest version of the library from PyPI."""
13+
1314
with _request.urlopen(URL) as response:
1415
if response.status == 200:
15-
data = _json.load(response)
16-
return data["info"]["version"]
16+
return _json.load(response)["info"]["version"]
1717
else:
1818
raise HTTPError(URL, response.status, "Failed to fetch latest version info", response.headers, None)
1919

2020

2121
def is_latest_version() -> Optional[bool]:
22-
"""Checks if the currently installed version of the
22+
"""Checks if the currently installed version of the<br>
2323
library is the latest one available on PyPI."""
24+
2425
try:
2526
if (latest := get_latest_version()) in {"", None}:
2627
return None
28+
2729
latest_v_parts = tuple(int(part) for part in (latest or "").lower().lstrip("v").split("."))
2830
installed_v_parts = tuple(int(part) for part in __version__.lower().lstrip("v").split("."))
31+
2932
return latest_v_parts <= installed_v_parts
33+
3034
except Exception:
3135
return None
3236

@@ -82,7 +86,9 @@ def is_latest_version() -> Optional[bool]:
8286

8387

8488
def show_help() -> None:
85-
"""CLI command function for `xulbux-lib` command, which shows some information about the library."""
86-
FormatCodes._config_console()
89+
"""CLI command function for `xulbux-lib` command,<br>
90+
which shows some information about the library."""
91+
92+
FormatCodes._config_terminal()
8793
print(CLI_HELP)
8894
Console.pause_exit(" [dim](Press any key to exit...)\n\n", pause=True)

src/xulbux/cli/tools.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33

44

55
def render_format_codes():
6-
"""CLI command function for `xulbux-lib fc` command, which allows you to parse
7-
and render a given string's format codes as ANSI console output."""
6+
"""CLI command function for `xulbux-lib fc` command, which allows you to parse<br>
7+
and render a given string's format codes as ANSI terminal output."""
8+
89
args = Console.get_args({"input": "before"})
910
vals = args.input.values[1:] # EXCLUDE THE COMMAND ITSELF
1011

1112
if not vals:
12-
FormatCodes.print("\n[_|i|dim]Provide a string to parse and render\n"
13-
"its format codes as ANSI console output.[_]\n")
13+
FormatCodes.print(
14+
"\n[_|i|dim]Provide a string to parse and render\n"
15+
"its format codes as ANSI terminal output.[_]\n"
16+
)
1417

1518
else:
1619
ansi = FormatCodes.to_ansi("".join(vals))

0 commit comments

Comments
 (0)