xulbux 1.6.7__tar.gz → 1.6.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of xulbux might be problematic. Click here for more details.

Files changed (47) hide show
  1. {xulbux-1.6.7/src/xulbux.egg-info → xulbux-1.6.9}/PKG-INFO +19 -40
  2. xulbux-1.6.9/README.md +132 -0
  3. {xulbux-1.6.7 → xulbux-1.6.9}/pyproject.toml +55 -20
  4. xulbux-1.6.9/src/xulbux/__init__.py +25 -0
  5. {xulbux-1.6.7 → xulbux-1.6.9}/src/xulbux/_cli_.py +4 -4
  6. xulbux-1.6.9/src/xulbux/xx_code.py +115 -0
  7. {xulbux-1.6.7 → xulbux-1.6.9}/src/xulbux/xx_color.py +91 -58
  8. {xulbux-1.6.7 → xulbux-1.6.9}/src/xulbux/xx_console.py +176 -40
  9. {xulbux-1.6.7 → xulbux-1.6.9}/src/xulbux/xx_data.py +60 -53
  10. {xulbux-1.6.7 → xulbux-1.6.9}/src/xulbux/xx_env_path.py +3 -19
  11. {xulbux-1.6.7 → xulbux-1.6.9}/src/xulbux/xx_file.py +18 -30
  12. {xulbux-1.6.7 → xulbux-1.6.9}/src/xulbux/xx_format_codes.py +60 -17
  13. xulbux-1.6.9/src/xulbux/xx_json.py +158 -0
  14. xulbux-1.6.9/src/xulbux/xx_path.py +167 -0
  15. {xulbux-1.6.7 → xulbux-1.6.9}/src/xulbux/xx_regex.py +6 -14
  16. {xulbux-1.6.7 → xulbux-1.6.9}/src/xulbux/xx_string.py +4 -1
  17. {xulbux-1.6.7 → xulbux-1.6.9}/src/xulbux/xx_system.py +1 -5
  18. {xulbux-1.6.7 → xulbux-1.6.9/src/xulbux.egg-info}/PKG-INFO +19 -40
  19. {xulbux-1.6.7 → xulbux-1.6.9}/src/xulbux.egg-info/SOURCES.txt +8 -3
  20. xulbux-1.6.9/tests/test_code.py +78 -0
  21. xulbux-1.6.9/tests/test_color.py +171 -0
  22. xulbux-1.6.9/tests/test_color_types.py +198 -0
  23. xulbux-1.6.9/tests/test_console.py +249 -0
  24. xulbux-1.6.9/tests/test_data.py +210 -0
  25. xulbux-1.6.9/tests/test_file.py +120 -0
  26. xulbux-1.6.9/tests/test_format_codes.py +62 -0
  27. xulbux-1.6.9/tests/test_json.py +202 -0
  28. xulbux-1.6.9/tests/test_path.py +160 -0
  29. xulbux-1.6.9/tests/test_string.py +160 -0
  30. xulbux-1.6.7/README.md +0 -132
  31. xulbux-1.6.7/src/xulbux/__init__.py +0 -57
  32. xulbux-1.6.7/src/xulbux/xx_code.py +0 -100
  33. xulbux-1.6.7/src/xulbux/xx_json.py +0 -103
  34. xulbux-1.6.7/src/xulbux/xx_path.py +0 -117
  35. xulbux-1.6.7/tests/test_color.py +0 -18
  36. xulbux-1.6.7/tests/test_color_types.py +0 -103
  37. xulbux-1.6.7/tests/test_console_info.py +0 -37
  38. xulbux-1.6.7/tests/test_data.py +0 -51
  39. xulbux-1.6.7/tests/test_format_codes.py +0 -42
  40. {xulbux-1.6.7 → xulbux-1.6.9}/LICENSE +0 -0
  41. {xulbux-1.6.7 → xulbux-1.6.9}/setup.cfg +0 -0
  42. {xulbux-1.6.7 → xulbux-1.6.9}/src/xulbux/_consts_.py +0 -0
  43. {xulbux-1.6.7 → xulbux-1.6.9}/src/xulbux.egg-info/dependency_links.txt +0 -0
  44. {xulbux-1.6.7 → xulbux-1.6.9}/src/xulbux.egg-info/entry_points.txt +0 -0
  45. {xulbux-1.6.7 → xulbux-1.6.9}/src/xulbux.egg-info/requires.txt +0 -0
  46. {xulbux-1.6.7 → xulbux-1.6.9}/src/xulbux.egg-info/top_level.txt +0 -0
  47. /xulbux-1.6.7/tests/test_env_vars.py → /xulbux-1.6.9/tests/test_env_path.py +0 -0
@@ -1,43 +1,21 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: xulbux
3
- Version: 1.6.7
3
+ Version: 1.6.9
4
4
  Summary: A Python library which includes lots of helpful classes, types and functions aiming to make common programming tasks simpler.
5
5
  Author-email: XulbuX <xulbux.real@gmail.com>
6
- License: MIT License
7
-
8
- Copyright (c) 2024 XulbuX
9
-
10
- Permission is hereby granted, free of charge, to any person obtaining a copy
11
- of this software and associated documentation files (the "Software"), to deal
12
- in the Software without restriction, including without limitation the rights
13
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
- copies of the Software, and to permit persons to whom the Software is
15
- furnished to do so, subject to the following conditions:
16
-
17
- The above copyright notice and this permission notice shall be included in all
18
- copies or substantial portions of the Software.
19
-
20
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
- SOFTWARE.
27
-
6
+ License-Expression: MIT
28
7
  Project-URL: Bug Reports, https://github.com/XulbuX/PythonLibraryXulbuX/issues
29
8
  Project-URL: Changelog, https://github.com/XulbuX/PythonLibraryXulbuX/blob/main/CHANGELOG.md
30
9
  Project-URL: Documentation, https://github.com/XulbuX/PythonLibraryXulbuX/wiki
31
10
  Project-URL: Homepage, https://github.com/XulbuX/PythonLibraryXulbuX
32
11
  Project-URL: License, https://github.com/XulbuX/PythonLibraryXulbuX/blob/main/LICENSE
33
12
  Project-URL: Source Code, https://github.com/XulbuX/PythonLibraryXulbuX/tree/main/src
34
- Keywords: xulbux,python,library,utility,helper,functions,tools,classes,types,methods,cmd,console,constants,code,color,data,structures,env,environment,file,format,json,path,regex,string,system,operations,presets
13
+ Keywords: args,arguments,attributes,classes,cmd,client,code,codes,color,commands,console,consts,constants,convert,conversion,data,debug,easier,env,environment,error,file,format,formatting,functions,helper,hex,hexa,hsl,hsla,info,input,json,library,log,logging,methods,nice,operations,path,presets,pretty,printing,properties,python,re,regex,rgb,rgba,string,structures,system,tools,types,utility,warn,warning,xulbux
35
14
  Classifier: Intended Audience :: Developers
36
15
  Classifier: Programming Language :: Python :: 3
37
16
  Classifier: Programming Language :: Python :: 3.10
38
17
  Classifier: Programming Language :: Python :: 3.11
39
18
  Classifier: Programming Language :: Python :: 3.12
40
- Classifier: License :: OSI Approved :: MIT License
41
19
  Classifier: Operating System :: OS Independent
42
20
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
43
21
  Requires-Python: >=3.10.0
@@ -54,6 +32,7 @@ Requires-Dist: black>=23.7.0; extra == "dev"
54
32
  Requires-Dist: isort>=5.12.0; extra == "dev"
55
33
  Requires-Dist: flake8>=6.1.0; extra == "dev"
56
34
  Requires-Dist: flake8-pyproject>=1.2.3; extra == "dev"
35
+ Dynamic: license-file
57
36
 
58
37
  # **$\color{#8085FF}\Huge\textsf{XulbuX}$**
59
38
 
@@ -102,20 +81,20 @@ from xulbux import rgba, hsla, hexa
102
81
 
103
82
  ## Modules
104
83
 
105
- | | |
106
- | :--------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------- |
107
- | <h3>[`xx_code`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_code)</h3> | advanced code-string operations (*changing the indent, finding function calls, ...*) |
108
- | <h3>[`xx_color`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_color)</h3> | everything around colors (*converting, blending, searching colors in strings, ...*) |
109
- | <h3>[`xx_console`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_console)</h3> | advanced actions related to the console (*pretty logging, advanced inputs, ...*) |
110
- | <h3>[`xx_data`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_data)</h3> | advanced operations with data structures (*compare, generate path ID's, pretty print/format, ...*) |
111
- | <h3>[`xx_env_path`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_env_path)</h3> | getting and editing the PATH variable (*get paths, check for paths, add paths, ...*) |
112
- | <h3>[`xx_file`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_file)</h3> | advanced working with files (*create files, rename file-extensions, ...*) |
113
- | <h3>[`xx_format_codes`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_format_codes)</h3> | easy pretty printing with custom format codes (*print, inputs, custom format codes to ANSI, ...*) |
114
- | <h3>`xx_json`</h3> | advanced working with json files (*read, create, update, ...*) |
115
- | <h3>`xx_path`</h3> | advanced path operations (*get paths, smart-extend relative paths, delete paths, ...*) |
116
- | <h3>`xx_regex`</h3> | generated regex pattern-templates (*match bracket- and quote pairs, match colors, ...*) |
117
- | <h3>[`xx_string`](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_string)</h3> | helpful actions when working with strings. (*normalize, escape, decompose, ...*) |
118
- | <h3>`xx_system`</h3> | advanced system actions (*restart with message, check installed Python libs, ...*) |
84
+ | Module | Short Description |
85
+ | :---------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------- |
86
+ | [![xx_code](https://img.shields.io/badge/xx__code-6065FF?style=flat)](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_code) | advanced code-string operations (*changing the indent, finding function calls, ...*) |
87
+ | [![xx_color](https://img.shields.io/badge/xx__color-6065FF?style=flat)](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_color) | everything around colors (*converting, blending, searching colors in strings, ...*) |
88
+ | [![xx_console](https://img.shields.io/badge/xx__console-6065FF?style=flat)](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_console) | advanced actions related to the console (*pretty logging, advanced inputs, ...*) |
89
+ | [![xx_data](https://img.shields.io/badge/xx__data-6065FF?style=flat)](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_data) | advanced operations with data structures (*compare, generate path ID's, pretty print/format, ...*) |
90
+ | [![xx_env_path](https://img.shields.io/badge/xx__env__path-6065FF?style=flat)](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_env_path) | getting and editing the PATH variable (*get paths, check for paths, add paths, ...*) |
91
+ | [![xx_file](https://img.shields.io/badge/xx__file-6065FF?style=flat)](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_file) | advanced working with files (*create files, rename file-extensions, ...*) |
92
+ | [![xx_format_codes](https://img.shields.io/badge/xx__format__codes-6065FF?style=flat)](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_format_codes) | easy pretty printing with custom format codes (*print, inputs, custom format codes to ANSI, ...*) |
93
+ | [![xx_json](https://img.shields.io/badge/xx__json-6065FF?style=flat)](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_json) | advanced working with json files (*read, create, update, ...*) |
94
+ | [![xx_path](https://img.shields.io/badge/xx__path-6065FF?style=flat)](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_path) | advanced path operations (*get paths, smart-extend relative paths, delete paths, ...*) |
95
+ | ![xx_regex](https://img.shields.io/badge/xx__regex-6065FF?style=flat) | generated regex pattern-templates (*match bracket- and quote pairs, match colors, ...*) |
96
+ | [![xx_string](https://img.shields.io/badge/xx__string-6065FF?style=flat)](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_string) | helpful actions when working with strings. (*normalize, escape, decompose, ...*) |
97
+ | ![xx_system](https://img.shields.io/badge/xx__system-6065FF?style=flat) | advanced system actions (*restart with message, check installed Python libs, ...*) |
119
98
 
120
99
  <br>
121
100
 
xulbux-1.6.9/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # **$\color{#8085FF}\Huge\textsf{XulbuX}$**
2
+
3
+ **$\color{#8085FF}\textsf{XulbuX}$** is library that contains many useful classes, types, and functions,
4
+ ranging from console logging and working with colors to file management and system operations.
5
+ The library is designed to simplify common programming tasks and improve code readability through its collection of tools.
6
+
7
+ For precise information about the library, see the library's [wiki page](https://github.com/XulbuX/PythonLibraryXulbuX/wiki).<br>
8
+ For the libraries latest changes and updates, see the [change log](https://github.com/XulbuX/PythonLibraryXulbuX/blob/main/CHANGELOG.md).
9
+
10
+ <br>
11
+
12
+ ## Installation
13
+
14
+ Run the following commands in a console with administrator privileges, so the actions take effect for all users.
15
+
16
+ Install the library and all its dependencies with the command:
17
+ ```console
18
+ pip install xulbux
19
+ ```
20
+
21
+ Upgrade the library and all its dependencies to their latest available version with the command:
22
+ ```console
23
+ pip install --upgrade xulbux
24
+ ```
25
+
26
+ <br>
27
+
28
+ ## Usage
29
+
30
+ Import the full library under the alias `xx`, so its constants, classes, methods and types are accessible with `xx.CONSTANT.value`, `xx.Class.method()`, `xx.type()`:
31
+ ```python
32
+ import xulbux as xx
33
+ ```
34
+ So you don't have to import the full library under an alias, you can also import only certain parts of the library's contents:
35
+ ```python
36
+ # CONSTANTS
37
+ from xulbux import COLOR, CHARS, ANSI
38
+ # Classes
39
+ from xulbux import Code, Color, Console, ...
40
+ # types
41
+ from xulbux import rgba, hsla, hexa
42
+ ```
43
+
44
+ <br>
45
+
46
+ ## Modules
47
+
48
+ | Module | Short Description |
49
+ | :---------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------- |
50
+ | [![xx_code](https://img.shields.io/badge/xx__code-6065FF?style=flat)](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_code) | advanced code-string operations (*changing the indent, finding function calls, ...*) |
51
+ | [![xx_color](https://img.shields.io/badge/xx__color-6065FF?style=flat)](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_color) | everything around colors (*converting, blending, searching colors in strings, ...*) |
52
+ | [![xx_console](https://img.shields.io/badge/xx__console-6065FF?style=flat)](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_console) | advanced actions related to the console (*pretty logging, advanced inputs, ...*) |
53
+ | [![xx_data](https://img.shields.io/badge/xx__data-6065FF?style=flat)](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_data) | advanced operations with data structures (*compare, generate path ID's, pretty print/format, ...*) |
54
+ | [![xx_env_path](https://img.shields.io/badge/xx__env__path-6065FF?style=flat)](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_env_path) | getting and editing the PATH variable (*get paths, check for paths, add paths, ...*) |
55
+ | [![xx_file](https://img.shields.io/badge/xx__file-6065FF?style=flat)](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_file) | advanced working with files (*create files, rename file-extensions, ...*) |
56
+ | [![xx_format_codes](https://img.shields.io/badge/xx__format__codes-6065FF?style=flat)](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_format_codes) | easy pretty printing with custom format codes (*print, inputs, custom format codes to ANSI, ...*) |
57
+ | [![xx_json](https://img.shields.io/badge/xx__json-6065FF?style=flat)](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_json) | advanced working with json files (*read, create, update, ...*) |
58
+ | [![xx_path](https://img.shields.io/badge/xx__path-6065FF?style=flat)](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_path) | advanced path operations (*get paths, smart-extend relative paths, delete paths, ...*) |
59
+ | ![xx_regex](https://img.shields.io/badge/xx__regex-6065FF?style=flat) | generated regex pattern-templates (*match bracket- and quote pairs, match colors, ...*) |
60
+ | [![xx_string](https://img.shields.io/badge/xx__string-6065FF?style=flat)](https://github.com/XulbuX/PythonLibraryXulbuX/wiki/xx_string) | helpful actions when working with strings. (*normalize, escape, decompose, ...*) |
61
+ | ![xx_system](https://img.shields.io/badge/xx__system-6065FF?style=flat) | advanced system actions (*restart with message, check installed Python libs, ...*) |
62
+
63
+ <br>
64
+
65
+ ## Example Usage
66
+
67
+ This is what it could look like using this library for a simple but very nice looking color converter:
68
+ ```python
69
+ from xulbux import COLOR # CONSTANTS
70
+ from xulbux import FormatCodes, Console # Classes
71
+ from xulbux import hexa # types
72
+
73
+
74
+ def main() -> None:
75
+
76
+ # LET THE USER ENTER A HEXA COLOR IN ANY HEXA FORMAT
77
+ input_clr = FormatCodes.input(
78
+ "\n[b](Enter a HEXA color in any format) [dim](>) "
79
+ )
80
+
81
+ # ANNOUNCE INDEXING THE INPUT COLOR
82
+ Console.log(
83
+ "INDEX",
84
+ "Indexing the input HEXA color...",
85
+ start="\n",
86
+ title_bg_color=COLOR.blue,
87
+ )
88
+
89
+ try:
90
+ # TRY TO CONVERT THE INPUT COLOR INTO A hexa() COLOR
91
+ hexa_color = hexa(input_clr)
92
+
93
+ except ValueError:
94
+ # ANNOUNCE THE ERROR AND EXIT THE PROGRAM
95
+ Console.fail(
96
+ "The input HEXA color is invalid.",
97
+ end="\n\n",
98
+ exit=True,
99
+ )
100
+
101
+ # ANNOUNCE STARTING THE CONVERSION
102
+ Console.log(
103
+ "CONVERT",
104
+ "Converting the HEXA color into different types...",
105
+ title_bg_color=COLOR.tangerine,
106
+ )
107
+
108
+ # CONVERT THE HEXA COLOR INTO THE TWO OTHER COLOR TYPES
109
+ rgba_color = hexa_color.to_rgba()
110
+ hsla_color = hexa_color.to_hsla()
111
+
112
+ # ANNOUNCE THE SUCCESSFUL CONVERSION
113
+ Console.done(
114
+ "Successfully converted color into different types.",
115
+ end="\n\n",
116
+ )
117
+
118
+ # PRETTY PRINT THE COLOR IN DIFFERENT TYPES
119
+ FormatCodes.print(f"[b](HEXA:) [i|white]({hexa_color})")
120
+ FormatCodes.print(f"[b](RGBA:) [i|white]({rgba_color})")
121
+ FormatCodes.print(f"[b](HSLA:) [i|white]({hsla_color})\n")
122
+
123
+
124
+ if __name__ == "__main__":
125
+ main()
126
+ ```
127
+
128
+ <br>
129
+ <br>
130
+
131
+ --------------------------------------------------------------
132
+ [View this library on PyPI](https://pypi.org/project/XulbuX/)
@@ -4,11 +4,12 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "xulbux"
7
- version = "1.6.7"
7
+ version = "1.6.9"
8
8
  authors = [{ name = "XulbuX", email = "xulbux.real@gmail.com" }]
9
9
  description = "A Python library which includes lots of helpful classes, types and functions aiming to make common programming tasks simpler."
10
10
  readme = "README.md"
11
- license = { file = "LICENSE" }
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
12
13
  requires-python = ">=3.10.0"
13
14
  dependencies = [
14
15
  "keyboard>=0.13.5",
@@ -30,39 +31,68 @@ classifiers = [
30
31
  "Programming Language :: Python :: 3.10",
31
32
  "Programming Language :: Python :: 3.11",
32
33
  "Programming Language :: Python :: 3.12",
33
- "License :: OSI Approved :: MIT License",
34
34
  "Operating System :: OS Independent",
35
35
  "Topic :: Software Development :: Libraries :: Python Modules",
36
36
  ]
37
37
  keywords = [
38
- "xulbux",
39
- "python",
40
- "library",
41
- "utility",
42
- "helper",
43
- "functions",
44
- "tools",
38
+ "args",
39
+ "arguments",
40
+ "attributes",
45
41
  "classes",
46
- "types",
47
- "methods",
48
42
  "cmd",
49
- "console",
50
- "constants",
43
+ "client",
51
44
  "code",
45
+ "codes",
52
46
  "color",
47
+ "commands",
48
+ "console",
49
+ "consts",
50
+ "constants",
51
+ "convert",
52
+ "conversion",
53
53
  "data",
54
- "structures",
54
+ "debug",
55
+ "easier",
55
56
  "env",
56
57
  "environment",
58
+ "error",
57
59
  "file",
58
60
  "format",
61
+ "formatting",
62
+ "functions",
63
+ "helper",
64
+ "hex",
65
+ "hexa",
66
+ "hsl",
67
+ "hsla",
68
+ "info",
69
+ "input",
59
70
  "json",
71
+ "library",
72
+ "log",
73
+ "logging",
74
+ "methods",
75
+ "nice",
76
+ "operations",
60
77
  "path",
78
+ "presets",
79
+ "pretty",
80
+ "printing",
81
+ "properties",
82
+ "python",
83
+ "re",
61
84
  "regex",
85
+ "rgb",
86
+ "rgba",
62
87
  "string",
88
+ "structures",
63
89
  "system",
64
- "operations",
65
- "presets",
90
+ "tools",
91
+ "types",
92
+ "utility",
93
+ "warn",
94
+ "warning",
95
+ "xulbux",
66
96
  ]
67
97
 
68
98
  [project.urls]
@@ -121,10 +151,15 @@ minversion = "7.0"
121
151
  addopts = "-ra -q"
122
152
  pythonpath = ["src"]
123
153
  testpaths = [
124
- "tests/test_console_info.py",
125
- "tests/test_color_types.py",
154
+ "tests/test_code.py",
126
155
  "tests/test_color.py",
156
+ "tests/test_color_types.py",
157
+ "tests/test_console.py",
127
158
  "tests/test_data.py",
128
- "tests/test_env_vars.py",
159
+ "tests/test_env_path.py",
160
+ "tests/test_file.py",
129
161
  "tests/test_format_codes.py",
162
+ "tests/test_json.py",
163
+ "tests/test_path.py",
164
+ "tests/test_string.py",
130
165
  ]
@@ -0,0 +1,25 @@
1
+ __version__ = "1.6.9"
2
+ __author__ = "XulbuX"
3
+ __email__ = "xulbux.real@gmail.com"
4
+ __license__ = "MIT"
5
+ __copyright__ = "Copyright (c) 2025 XulbuX"
6
+ __url__ = "https://github.com/XulbuX/PythonLibraryXulbuX"
7
+ __description__ = "A library which includes a lot of really helpful functions."
8
+ __all__ = [
9
+ "_consts_", "xx_code", "xx_color", "xx_console", "xx_data", "xx_env_path", "xx_file", "xx_format_codes", "xx_json",
10
+ "xx_path", "xx_regex", "xx_string", "xx_system"
11
+ ]
12
+
13
+ from ._consts_ import *
14
+ from .xx_code import *
15
+ from .xx_color import *
16
+ from .xx_console import *
17
+ from .xx_data import *
18
+ from .xx_env_path import *
19
+ from .xx_file import *
20
+ from .xx_format_codes import *
21
+ from .xx_json import *
22
+ from .xx_path import *
23
+ from .xx_regex import *
24
+ from .xx_string import *
25
+ from .xx_system import *
@@ -1,5 +1,5 @@
1
- from . import __version__
2
1
  from ._consts_ import COLOR
2
+ from . import __version__
3
3
  from .xx_format_codes import FormatCodes
4
4
  from .xx_console import Console
5
5
 
@@ -33,17 +33,17 @@ def help_command():
33
33
  [dim](•) [{color['class']}]rgba[{color['punctuators']}]/([i|{color['types']}]int[_|{color['punctuators']}],[i|{color['types']}]int[_|{color['punctuators']}],[i|{color['types']}]int[_|{color['punctuators']}],[i|{color['types']}]float[_|{color['punctuators']}])[*]
34
34
  [dim](•) [{color['class']}]hsla[{color['punctuators']}]/([i|{color['types']}]int[_|{color['punctuators']}],[i|{color['types']}]int[_|{color['punctuators']}],[i|{color['types']}]int[_|{color['punctuators']}],[i|{color['types']}]float[_|{color['punctuators']}])[*]
35
35
  [dim](•) [{color['class']}]hexa[{color['punctuators']}]/([i|{color['types']}]str[_|{color['punctuators']}]|[i|{color['types']}]int[_|{color['punctuators']}])[*]
36
+ [dim](•) CODE STRING OPERATIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Code[*]
37
+ [dim](•) WORKING WITH COLORS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Color[*]
38
+ [dim](•) CONSOLE LOG AND ACTIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Console[*]
36
39
  [dim](•) PATH OPERATIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Path[*]
37
40
  [dim](•) FILE OPERATIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]File[*]
38
41
  [dim](•) JSON FILE OPERATIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Json[*]
39
42
  [dim](•) SYSTEM ACTIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]System[*]
40
43
  [dim](•) MANAGE THE ENV PATH VAR [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]EnvPath[*]
41
- [dim](•) CONSOLE LOG AND ACTIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Console[*]
42
44
  [dim](•) EASY PRETTY PRINTING [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]FormatCodes[*]
43
- [dim](•) WORKING WITH COLORS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Color[*]
44
45
  [dim](•) DATA OPERATIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Data[*]
45
46
  [dim](•) STRING OPERATIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]String[*]
46
- [dim](•) CODE STRING OPERATIONS [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Code[*]
47
47
  [dim](•) REGEX PATTERN TEMPLATES [{color['lib']}]xx[{color['punctuators']}].[{color['class']}]Regex[*]
48
48
  [_]
49
49
  [dim](Press any key to exit...)
@@ -0,0 +1,115 @@
1
+ from .xx_string import String
2
+ from .xx_regex import Regex
3
+ from .xx_data import Data
4
+
5
+ import regex as _rx
6
+
7
+
8
+ class Code:
9
+
10
+ @staticmethod
11
+ def add_indent(code: str, indent: int) -> str:
12
+ """Adds `indent` spaces at the beginning of each line."""
13
+ indented_lines = [" " * indent + line for line in code.splitlines()]
14
+ return "\n".join(indented_lines)
15
+
16
+ @staticmethod
17
+ def get_tab_spaces(code: str) -> int:
18
+ """Will try to get the amount of spaces used for indentation."""
19
+ code_lines = String.get_lines(code, remove_empty_lines=True)
20
+ indents = [len(line) - len(line.lstrip()) for line in code_lines]
21
+ non_zero_indents = [i for i in indents if i > 0]
22
+ return min(non_zero_indents) if non_zero_indents else 0
23
+
24
+ @staticmethod
25
+ def change_tab_size(code: str, new_tab_size: int, remove_empty_lines: bool = False) -> str:
26
+ """Replaces all tabs with `new_tab_size` spaces.\n
27
+ ----------------------------------------------------------------------------------
28
+ If `remove_empty_lines` is `True`, empty lines will be removed in the process."""
29
+ code_lines = String.get_lines(code, remove_empty_lines=True)
30
+ lines = code_lines if remove_empty_lines else String.get_lines(code)
31
+ tab_spaces = Code.get_tab_spaces(code)
32
+ if (tab_spaces == new_tab_size) or tab_spaces == 0:
33
+ if remove_empty_lines:
34
+ return "\n".join(code_lines)
35
+ return code
36
+ result = []
37
+ for line in lines:
38
+ stripped = line.lstrip()
39
+ indent_level = (len(line) - len(stripped)) // tab_spaces
40
+ new_indent = " " * (indent_level * new_tab_size)
41
+ result.append(new_indent + stripped)
42
+ return "\n".join(result)
43
+
44
+ @staticmethod
45
+ def get_func_calls(code: str) -> list:
46
+ """Will try to get all function calls and return them as a list."""
47
+ funcs = _rx.findall(r"(?i)" + Regex.func_call(), code)
48
+ nested_func_calls = []
49
+ for _, func_attrs in funcs:
50
+ nested_calls = _rx.findall(r"(?i)" + Regex.func_call(), func_attrs)
51
+ if nested_calls:
52
+ nested_func_calls.extend(nested_calls)
53
+ return Data.remove_duplicates(funcs + nested_func_calls)
54
+
55
+ @staticmethod
56
+ def is_js(code: str, funcs: list = ["__", "$t", "$lang"]) -> bool:
57
+ """Will check if the code is very likely to be JavaScript."""
58
+ if not code or len(code.strip()) < 3:
59
+ return False
60
+ for func in funcs:
61
+ if _rx.match(r"^[\s\n]*" + _rx.escape(func) + r"\([^\)]*\)[\s\n]*$", code):
62
+ return True
63
+ direct_js_patterns = [
64
+ r"^[\s\n]*\$\(['\"][^'\"]+['\"]\)\.[\w]+\([^\)]*\);?[\s\n]*$", # jQuery calls
65
+ r"^[\s\n]*\$\.[a-zA-Z]\w*\([^\)]*\);?[\s\n]*$", # $.ajax(), etc.
66
+ r"^[\s\n]*\(\s*function\s*\(\)\s*\{.*\}\s*\)\(\);?[\s\n]*$", # IIFE
67
+ r"^[\s\n]*document\.[a-zA-Z]\w*\([^\)]*\);?[\s\n]*$", # document.getElementById()
68
+ r"^[\s\n]*window\.[a-zA-Z]\w*\([^\)]*\);?[\s\n]*$", # window.alert()
69
+ r"^[\s\n]*console\.[a-zA-Z]\w*\([^\)]*\);?[\s\n]*$", # console.log()
70
+ ]
71
+ for pattern in direct_js_patterns:
72
+ if _rx.match(pattern, code):
73
+ return True
74
+ arrow_function_patterns = [
75
+ r"^[\s\n]*\b[\w_]+\s*=\s*\([^\)]*\)\s*=>\s*[^;{]*[;]?[\s\n]*$", # const x = (y) => y*2;
76
+ r"^[\s\n]*\b[\w_]+\s*=\s*[\w_]+\s*=>\s*[^;{]*[;]?[\s\n]*$", # const x = y => y*2;
77
+ r"^[\s\n]*\(\s*[\w_,\s]+\s*\)\s*=>\s*[^;{]*[;]?[\s\n]*$", # (x) => x*2
78
+ r"^[\s\n]*[\w_]+\s*=>\s*[^;{]*[;]?[\s\n]*$", # x => x*2
79
+ ]
80
+ for pattern in arrow_function_patterns:
81
+ if _rx.match(pattern, code):
82
+ return True
83
+ funcs_pattern = r"(" + "|".join(_rx.escape(f) for f in funcs) + r")" + Regex.brackets("()")
84
+ js_indicators = [(r"\b(var|let|const)\s+[\w_$]+", 2), # JS variable declarations
85
+ (r"\$[\w_$]+\s*=", 2), # jQuery-style variables
86
+ (r"\$[\w_$]+\s*\(", 2), # jQuery function calls
87
+ (r"\bfunction\s*[\w_$]*\s*\(", 2), # Function declarations
88
+ (r"[\w_$]+\s*=\s*function\s*\(", 2), # Function assignments
89
+ (r"\b[\w_$]+\s*=>\s*[\{\(]", 2), # Arrow functions
90
+ (r"\(function\s*\(\)\s*\{", 2), # IIFE pattern
91
+ (funcs_pattern, 2), # Custom predefined functions
92
+ (r"\b(true|false|null|undefined)\b", 1), # JS literals
93
+ (r"===|!==|\+\+|--|\|\||&&", 1.5), # JS-specific operators
94
+ (r"\bnew\s+[\w_$]+\s*\(", 1.5), # Object instantiation with new
95
+ (r"\b(document|window|console|Math|Array|Object|String|Number)\.", 2), # JS objects
96
+ (r"\basync\s+function|\bawait\b", 2), # Async/await
97
+ (r"\b(if|for|while|switch)\s*\([^)]*\)\s*\{", 1), # Control structures with braces
98
+ (r"\btry\s*\{[^}]*\}\s*catch\s*\(", 1.5), # Try-catch
99
+ (r";[\s\n]*$", 0.5), # Semicolon line endings
100
+ ]
101
+ js_score = 0
102
+ line_endings = [line.strip() for line in code.splitlines() if line.strip()]
103
+ semicolon_endings = sum(1 for line in line_endings if line.endswith(';'))
104
+ if semicolon_endings >= 1:
105
+ js_score += min(semicolon_endings, 2)
106
+ opening_braces = code.count('{')
107
+ closing_braces = code.count('}')
108
+ if opening_braces > 0 and opening_braces == closing_braces:
109
+ js_score += 1
110
+ for pattern, score in js_indicators:
111
+ regex = _rx.compile(pattern, _rx.IGNORECASE)
112
+ matches = regex.findall(code)
113
+ if matches:
114
+ js_score += len(matches) * score
115
+ return js_score >= 2