danielutils 0.9.61__tar.gz → 0.9.63__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.
Files changed (121) hide show
  1. {danielutils-0.9.61 → danielutils-0.9.63}/PKG-INFO +2 -2
  2. {danielutils-0.9.61 → danielutils-0.9.63}/README.md +1 -1
  3. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/__init__.py +1 -1
  4. danielutils-0.9.63/danielutils/classes/__init__.py +6 -0
  5. danielutils-0.9.61/danielutils/classes/Shell.py → danielutils-0.9.63/danielutils/classes/repl.py +2 -2
  6. danielutils-0.9.63/danielutils/conversions/__init__.py +2 -0
  7. {danielutils-0.9.61/danielutils/conversions/SpecializedConversions → danielutils-0.9.63/danielutils/conversions/specialized_conversions}/to_hex.py +1 -1
  8. {danielutils-0.9.61/danielutils/conversions/SpecializedConversions → danielutils-0.9.63/danielutils/conversions/specialized_conversions}/to_int.py +1 -1
  9. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/data_structures/Graph.py +2 -2
  10. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/data_structures/Heap.py +1 -1
  11. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/data_structures/Queue.py +2 -2
  12. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/data_structures/Stack.py +1 -1
  13. danielutils-0.9.63/danielutils/data_structures/__init__.py +7 -0
  14. danielutils-0.9.63/danielutils/data_structures/default_dict.py +16 -0
  15. danielutils-0.9.63/danielutils/files_and_folders.py +435 -0
  16. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/metaclasses/InstanceCacheMeta.py +1 -1
  17. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/my_tqdm.py +7 -2
  18. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/reflection/Class.py +6 -1
  19. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/threads/worker.py +6 -1
  20. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/threads/worker_pool.py +9 -4
  21. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils.egg-info/PKG-INFO +2 -2
  22. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils.egg-info/SOURCES.txt +23 -13
  23. {danielutils-0.9.61 → danielutils-0.9.63}/pyproject.toml +3 -3
  24. {danielutils-0.9.61 → danielutils-0.9.63}/setup.py +4 -4
  25. danielutils-0.9.61/danielutils/classes/__init__.py +0 -6
  26. danielutils-0.9.61/danielutils/conversions/__init__.py +0 -2
  27. danielutils-0.9.61/danielutils/data_structures/__init__.py +0 -6
  28. {danielutils-0.9.61 → danielutils-0.9.63}/LISENCE +0 -0
  29. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/aliases.py +0 -0
  30. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/classes/Convenience.py +0 -0
  31. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/classes/Counter.py +0 -0
  32. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/classes/Tree.py +0 -0
  33. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/classes/frange.py +0 -0
  34. {danielutils-0.9.61/danielutils/classes/SortedBuiltins → danielutils-0.9.63/danielutils/classes/sorted_builtins}/__init__.py +0 -0
  35. {danielutils-0.9.61/danielutils/classes/SortedBuiltins → danielutils-0.9.63/danielutils/classes/sorted_builtins}/sset.py +0 -0
  36. {danielutils-0.9.61/danielutils/classes/TypedBuiltins → danielutils-0.9.63/danielutils/classes/typed_builtins}/__init__.py +0 -0
  37. {danielutils-0.9.61/danielutils/classes/TypedBuiltins → danielutils-0.9.63/danielutils/classes/typed_builtins}/factory.py +0 -0
  38. {danielutils-0.9.61/danielutils/classes/TypedBuiltins → danielutils-0.9.63/danielutils/classes/typed_builtins}/tdict.py +0 -0
  39. {danielutils-0.9.61/danielutils/classes/TypedBuiltins → danielutils-0.9.63/danielutils/classes/typed_builtins}/tlist.py +0 -0
  40. {danielutils-0.9.61/danielutils/classes/TypedBuiltins → danielutils-0.9.63/danielutils/classes/typed_builtins}/tset.py +0 -0
  41. {danielutils-0.9.61/danielutils/classes/TypedBuiltins → danielutils-0.9.63/danielutils/classes/typed_builtins}/ttuple.py +0 -0
  42. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/colors.py +0 -0
  43. /danielutils-0.9.61/danielutils/conversions/MainConversions.py → /danielutils-0.9.63/danielutils/conversions/main_conversions.py +0 -0
  44. {danielutils-0.9.61/danielutils/conversions/SpecializedConversions → danielutils-0.9.63/danielutils/conversions/specialized_conversions}/__init__.py +0 -0
  45. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/data_structures/Comparer.py +0 -0
  46. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/data_structures/Node.py +0 -0
  47. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/data_structures/functions.py +0 -0
  48. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/date.py +0 -0
  49. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/date_time.py +0 -0
  50. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/decorators/PartiallyImplemented.py +0 -0
  51. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/decorators/__init__.py +0 -0
  52. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/decorators/atomic.py +0 -0
  53. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/decorators/attach.py +0 -0
  54. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/decorators/chain_decorators.py +0 -0
  55. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/decorators/decorate_conditionally.py +0 -0
  56. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/decorators/delay_call.py +0 -0
  57. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/decorators/deprecate.py +0 -0
  58. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/decorators/limit_recursion.py +0 -0
  59. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/decorators/memo.py +0 -0
  60. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/decorators/overload.py +0 -0
  61. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/decorators/processify.py +0 -0
  62. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/decorators/property.py +0 -0
  63. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/decorators/threadify.py +0 -0
  64. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/decorators/timeout.py +0 -0
  65. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/decorators/validate.py +0 -0
  66. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/exceptions.py +0 -0
  67. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/functions/__init__.py +0 -0
  68. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/functions/areoneof.py +0 -0
  69. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/functions/check_foreach.py +0 -0
  70. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/functions/isoftype.py +0 -0
  71. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/functions/isoneof.py +0 -0
  72. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/functions/powerset.py +0 -0
  73. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/functions/types_subseteq.py +0 -0
  74. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/generators/__init__.py +0 -0
  75. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/generators/conditional_generator.py +0 -0
  76. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/generators/generator_from_stream.py +0 -0
  77. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/generators/join_generators.py +0 -0
  78. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/internet.py +0 -0
  79. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/io.py +0 -0
  80. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/loops.py +0 -0
  81. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/math/__init__.py +0 -0
  82. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/math/constants.py +0 -0
  83. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/math/functions.py +0 -0
  84. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/math/math_print.py +0 -0
  85. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/math/math_symbols.py +0 -0
  86. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/metaclasses/AtomicClassMeta.py +0 -0
  87. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/metaclasses/ImplicitDataDeleterMeta.py +0 -0
  88. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/metaclasses/Interface.py +0 -0
  89. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/metaclasses/OverloadMeta.py +0 -0
  90. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/metaclasses/__init__.py +0 -0
  91. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/multi_x.py +0 -0
  92. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/path.py +0 -0
  93. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/print.py +0 -0
  94. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/reflection/File.py +0 -0
  95. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/reflection/Function.py +0 -0
  96. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/reflection/Module.py +0 -0
  97. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/reflection/System.py +0 -0
  98. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/reflection/__init__.py +0 -0
  99. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/reflection/get_prev_frame.py +0 -0
  100. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/reflection/get_traceback.py +0 -0
  101. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/relations.py +0 -0
  102. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/signals.py +0 -0
  103. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/snippets/__init__.py +0 -0
  104. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/snippets/try_get.py +0 -0
  105. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/system/__init__.py +0 -0
  106. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/system/independent.py +0 -0
  107. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/system/windows/__init__.py +0 -0
  108. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/system/windows/utils/__init__.py +0 -0
  109. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/system/windows/utils/filetime.py +0 -0
  110. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/system/windows/win32_ctime.py +0 -0
  111. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/system/windows/windows.py +0 -0
  112. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/text.py +0 -0
  113. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/threads/__init__.py +0 -0
  114. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/time.py +0 -0
  115. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/university/__init__.py +0 -0
  116. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/university/databases/__init__.py +0 -0
  117. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils/university/databases/all.py +0 -0
  118. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils.egg-info/dependency_links.txt +0 -0
  119. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils.egg-info/requires.txt +0 -0
  120. {danielutils-0.9.61 → danielutils-0.9.63}/danielutils.egg-info/top_level.txt +0 -0
  121. {danielutils-0.9.61 → danielutils-0.9.63}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: danielutils
3
- Version: 0.9.61
3
+ Version: 0.9.63
4
4
  Summary: A python utils library for things I find useful
5
5
  Home-page: https://github.com/danielnachumdev/danielutils
6
6
  Author: danielnachumdev
@@ -44,7 +44,7 @@ Requires-Dist: tqdm
44
44
  [![Python 3.10.11](https://img.shields.io/badge/python-3.10.11-blue.svg)](https://www.python.org/downloads/release/python-31011/)
45
45
  [![gitleaks](https://github.com/danielnachumdev/danielutils/actions/workflows/gitleaks.yml/badge.svg)](https://github.com/danielnachumdev/danielutils/actions/workflows/gitleaks.yml)
46
46
  [![CodeQL](https://github.com/danielnachumdev/danielutils/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/danielnachumdev/danielutils/actions/workflows/github-code-scanning/codeql)
47
- # danielutils v=0.9.61
47
+ # danielutils v=0.9.63
48
48
  A utils library for things that I find useful for my coding workflow.\
49
49
  Feel free to use and / or contribute / improve my code :)
50
50
 
@@ -4,7 +4,7 @@
4
4
  [![Python 3.10.11](https://img.shields.io/badge/python-3.10.11-blue.svg)](https://www.python.org/downloads/release/python-31011/)
5
5
  [![gitleaks](https://github.com/danielnachumdev/danielutils/actions/workflows/gitleaks.yml/badge.svg)](https://github.com/danielnachumdev/danielutils/actions/workflows/gitleaks.yml)
6
6
  [![CodeQL](https://github.com/danielnachumdev/danielutils/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/danielnachumdev/danielutils/actions/workflows/github-code-scanning/codeql)
7
- # danielutils v=0.9.61
7
+ # danielutils v=0.9.63
8
8
  A utils library for things that I find useful for my coding workflow.\
9
9
  Feel free to use and / or contribute / improve my code :)
10
10
 
@@ -3,7 +3,7 @@
3
3
  """
4
4
  from .functions import *
5
5
  from .decorators import *
6
- from .io import *
6
+ from .files_and_folders import *
7
7
  from .system import *
8
8
  from .text import *
9
9
  from .conversions import *
@@ -0,0 +1,6 @@
1
+ from .sorted_builtins import *
2
+ from .typed_builtins import *
3
+ from .convenience import *
4
+ from .frange import *
5
+ from .counter import *
6
+ from .repl import *
@@ -35,7 +35,7 @@ class Command:
35
35
  return self.callback(*args, **kwargs)
36
36
 
37
37
 
38
- class Shell:
38
+ class REPL:
39
39
  """a class to easily create a shell application and get functionality for free
40
40
  """
41
41
 
@@ -82,7 +82,7 @@ class Shell:
82
82
 
83
83
 
84
84
  __all__ = [
85
- "Shell",
85
+ "REPL",
86
86
  "Command",
87
87
  "Argument"
88
88
  ]
@@ -0,0 +1,2 @@
1
+ from .main_conversions import *
2
+ from .specialized_conversions import *
@@ -1,5 +1,5 @@
1
1
  from ...metaclasses.OverloadMeta import OverloadMeta
2
- from ..MainConversions import int_to_hex, char_to_hex
2
+ from ..main_conversions import int_to_hex, char_to_hex
3
3
 
4
4
 
5
5
  @OverloadMeta.overload
@@ -1,6 +1,6 @@
1
1
  """functions that convert values to int"""
2
2
  from typing import Union, List as t_list
3
- from ..MainConversions import char_to_int
3
+ from ..main_conversions import char_to_int
4
4
  from ...reflection import get_python_version
5
5
  if get_python_version() >= (3, 9):
6
6
  from builtins import list as t_list
@@ -1,6 +1,6 @@
1
1
  from typing import Optional, Generator, List as t_list, Set as t_set
2
- from .Queue import Queue
3
- from .Node import MultiNode
2
+ from .queue import Queue
3
+ from .node import MultiNode
4
4
  from ..reflection import get_python_version
5
5
  if get_python_version() >= (3, 9):
6
6
  from builtins import list as t_list, set as t_set
@@ -1,5 +1,5 @@
1
1
  from typing import Any, Union
2
- from .Comparer import Comparer, CompareGreater, CompareSmaller
2
+ from .comparer import Comparer, CompareGreater, CompareSmaller
3
3
 
4
4
 
5
5
  class Heap:
@@ -1,6 +1,6 @@
1
1
  from typing import Callable, Any, Union
2
- from .Heap import Heap
3
- from .Comparer import Comparer, CompareGreater
2
+ from .heap import Heap
3
+ from .comparer import Comparer, CompareGreater
4
4
  from .functions import default_weight_function
5
5
  from ..metaclasses import AtomicClassMeta
6
6
 
@@ -1,5 +1,5 @@
1
1
  from typing import Optional, Generator, Any, cast
2
- from .Node import Node
2
+ from .node import Node
3
3
 
4
4
 
5
5
  class Stack:
@@ -0,0 +1,7 @@
1
+ from .queue import *
2
+ from .heap import *
3
+ from .comparer import *
4
+ from .node import *
5
+ from .graph import *
6
+ from .stack import *
7
+ from .default_dict import *
@@ -0,0 +1,16 @@
1
+ """
2
+ My implementation to collections.defaultdict
3
+ """
4
+
5
+
6
+ class DefaultDict(dict):
7
+ def __init__(self, cls):
8
+ self._cls = cls
9
+
10
+ def __getitem__(self, key):
11
+ return super().get(key, self._cls())
12
+
13
+
14
+ __all__ = [
15
+ "DefaultDict"
16
+ ]
@@ -0,0 +1,435 @@
1
+ # -*- coding: utf-8 -*-
2
+ import subprocess
3
+ from typing import IO, Iterator, Generator, Optional, cast, Union, List as t_list
4
+ # import shutil
5
+ from pathlib import Path
6
+ import os
7
+ from .decorators import validate
8
+ from .reflection import get_python_version
9
+ if get_python_version() >= (3, 9):
10
+ from builtins import list as t_list
11
+
12
+ @validate
13
+ def path_exists(path: str) -> bool:
14
+ """checks whether a path exists
15
+
16
+ Args:
17
+ path (str): path to check
18
+
19
+ Returns:
20
+ bool: result of check
21
+ """
22
+ return os.path.exists(path)
23
+
24
+
25
+ @validate
26
+ def file_exists(path: str) -> bool:
27
+ """checks whether a file exists at specified path
28
+
29
+ Args:
30
+ path (str): path to check
31
+
32
+ Returns:
33
+ bool: will return true iff the path exists and it is a path to a file
34
+ """
35
+ return path_exists(path) and is_file(path)
36
+
37
+
38
+ @validate
39
+ def directory_exists(path: str) -> bool:
40
+ """checks whether a directory exists at specified path
41
+
42
+ Args:
43
+ path (str): path to check
44
+
45
+ Returns:
46
+ bool: will return true iff the path exists and it is a path to a directory
47
+ """
48
+ return path_exists(path) and is_directory(path)
49
+
50
+
51
+ @validate
52
+ def delete_file(path: str) -> None:
53
+ """deletes a file if it exists
54
+
55
+ Args:
56
+ path (str): path of file
57
+ """
58
+ if file_exists(path):
59
+ os.remove(path)
60
+
61
+
62
+ @validate
63
+ # type:ignore
64
+ def read_file(path: str, read_bytes: bool = False) -> Union[t_list[str], t_list[bytes]]:
65
+ """read all lines from a file
66
+
67
+ Args:
68
+ path (str): the path to the file
69
+
70
+ Returns:
71
+ list[str]: a list of all the lines in the file
72
+ """
73
+ try:
74
+ if read_bytes:
75
+ with open(path, "rb") as f:
76
+ return f.readlines()
77
+ else:
78
+ with open(path, "r", encoding="mbcs") as f:
79
+ return f.readlines()
80
+ except Exception as e:
81
+ if isinstance(e, UnicodeDecodeError):
82
+ raise UnicodeDecodeError(e.encoding, e.object, e.start, e.end,
83
+ "Can't read byte in file.\nTo use with bytes use: read_bytes = True ") from e
84
+ raise e
85
+
86
+
87
+ @validate
88
+ def is_file(path: str) -> bool:
89
+ """return whether a path represents a file
90
+
91
+ Args:
92
+ path (str): path to check
93
+ """
94
+ return os.path.isfile(path)
95
+
96
+
97
+ @validate
98
+ def is_directory(path: str) -> bool:
99
+ """return whether a path represents a directory
100
+
101
+ Args:
102
+ path (str): path to check
103
+ """
104
+ return os.path.isdir(path)
105
+
106
+
107
+ @validate
108
+ def get_files(path: str) -> t_list[str]:
109
+ """return a list of names of all files inside specified directory
110
+
111
+ Args:
112
+ path (str): directory
113
+
114
+ Returns:
115
+ list[str]: all files
116
+ """
117
+ files_and_directories = get_files_and_directories(path)
118
+ return list(
119
+ filter(lambda name: is_file(os.path.join(path, name)), files_and_directories))
120
+
121
+
122
+ @validate
123
+ def get_files_and_directories(path: str) -> t_list[str]:
124
+ """get a list of all files and directories in specified path
125
+
126
+ Args:
127
+ path (str): path to check
128
+
129
+ Returns:
130
+ list[str]: all files and directories
131
+ """
132
+ return os.listdir(path)
133
+
134
+
135
+ @validate
136
+ def get_directories(path: str) -> t_list[str]:
137
+ """get all directories in specified path
138
+
139
+ Args:
140
+ path (str): path to check
141
+
142
+ Returns:
143
+ list[str]: all directories
144
+ """
145
+ files_and_directories = get_files_and_directories(path)
146
+ return list(
147
+ filter(lambda name: is_directory(os.path.join(path, name)), files_and_directories))
148
+
149
+
150
+ @ validate
151
+ def delete_directory(path: str) -> None:
152
+ """delete a directory and all its contents
153
+
154
+ Args:
155
+ path (str): _description_
156
+ """
157
+ if is_directory(path):
158
+ clear_directory(path)
159
+ os.rmdir(path)
160
+
161
+
162
+ @validate
163
+ def clear_directory(path: str) -> None:
164
+ """clears the content of a directory
165
+
166
+ Args:
167
+ path (str): the path of the directory to clean
168
+ """
169
+ for file in get_files(path):
170
+ delete_file(os.path.join(path, file))
171
+ for subdir in get_directories(path):
172
+ delete_directory(os.path.join(path, subdir))
173
+
174
+
175
+ @validate
176
+ def create_directory(path: str) -> None:
177
+ """create a directory at the specified path if it doesn't already exists
178
+
179
+ Args:
180
+ path (str): the path to create a directory at
181
+ """
182
+ if not directory_exists(path):
183
+ os.makedirs(path)
184
+
185
+
186
+ @validate
187
+ def create_file(path: str) -> None:
188
+ if not file_exists(path):
189
+ with open(path, "w", encoding='utf8') as f:
190
+ pass
191
+
192
+
193
+ @validate
194
+ def get_file_type_from_directory(path: str, file_type: str) -> Iterator[str]:
195
+ """returns all file with specific type from a directory
196
+
197
+ Args:
198
+ path (str): path of directory
199
+ file_type (str): the desired file type. eg: ".png"
200
+
201
+ Returns:
202
+ list[str]: result
203
+ """
204
+ return filter(
205
+ lambda name: Path(os.path.join(path, name)).suffix == file_type,
206
+ get_files(path)
207
+ )
208
+
209
+
210
+ @validate
211
+ def get_file_type_from_directory_recursively(path: str, file_type: str) -> Generator[str, None, None]:
212
+ """_summary_
213
+
214
+ Args:
215
+ path (str): _description_
216
+ file_type (str): _description_
217
+
218
+ Returns:
219
+ _type_: _description_
220
+ """
221
+ yield from filter(
222
+ lambda name: Path(os.path.join(path, name)).suffix == file_type,
223
+ get_files(path)
224
+ )
225
+ for subdir in get_directories(path):
226
+ for v in get_file_type_from_directory_recursively(os.path.join(path, subdir), file_type):
227
+ yield os.path.join(subdir, v)
228
+
229
+
230
+ @validate
231
+ def rename_file(path: str, new_name: str) -> None:
232
+ """renames a file
233
+
234
+ Args:
235
+ path (str): file to rename
236
+ new_name (str): the desired new name
237
+ """
238
+ new_path = "./" + \
239
+ "/".join(Path(path).parts[:-1])+"/"+new_name+Path(path).suffix
240
+ move_file(path, new_path)
241
+
242
+
243
+ @validate
244
+ def move_file(old_path: str, new_path: str) -> None:
245
+ """moves a file
246
+
247
+ Args:
248
+ old_path (str): old path
249
+ new_path (str): new path
250
+ """
251
+ os.rename(old_path, new_path)
252
+
253
+
254
+ @validate
255
+ async def open_file(file_path: str, application_path: str) -> int:
256
+ """open a file with the specified application
257
+
258
+ Args:
259
+ file_path (str): the file to open
260
+ application_path (str): the application to open with
261
+ Returns:
262
+ int: return code
263
+ """
264
+ with subprocess.Popen([application_path, file_path]) as p:
265
+ return p.wait()
266
+
267
+
268
+ # @validate
269
+ # def move_directory(old_path: str, new_path: str) -> None:
270
+ # """moves a directory
271
+ #
272
+ # Args:
273
+ # old_path (str): old path
274
+ # new_path (str): new path
275
+ # """
276
+ # shutil.move(old_path, new_path)
277
+ #
278
+ #
279
+ # @validate
280
+ # def copy_file(src: str, dest: str) -> None:
281
+ # """copies file from src to dest
282
+ #
283
+ # Args:
284
+ # src (str): src
285
+ # dest (str): dest
286
+ # """
287
+ # shutil.copy(src, dest)
288
+ #
289
+ #
290
+ # @validate
291
+ # def copy_directory(src: str, dest: str) -> None:
292
+ # """copies a directory from src to dest
293
+ #
294
+ # Args:
295
+ # src (str): stc
296
+ # dest (str): dest
297
+ # """
298
+ # shutil.copy(src, dest)
299
+ #
300
+
301
+ class IndentedWriter:
302
+ """every class that will inherit this class will have the following functions available
303
+ write() with the same arguments a builtin print()
304
+ indent()
305
+ undent()
306
+
307
+ also, it is expected in the __init__ function to call super().__init__()
308
+ also, the output_stream must be set whether by the first argument io super().__init__(...)
309
+ or by set_stream() explicitly somewhere else.
310
+
311
+ this class will not function properly is the output_stream is not set!
312
+
313
+ """
314
+
315
+ def __init__(self, output_stream: Optional[IO] = None, indent_value: str = "\t"):
316
+ self.indent_level = 0
317
+ self.output_stream: Optional[IO] = output_stream
318
+ self.indent_value = indent_value
319
+
320
+ def write(self, *args, sep=" ", end="\n") -> None:
321
+ """writes the supplied arguments to the output_stream
322
+
323
+ Args:
324
+ sep (str, optional): the str to use as a separator between arguments. Defaults to " ".
325
+ end (str, optional): the str to use as the final value. Defaults to "\n".
326
+
327
+ Raises:
328
+ ValueError: _description_
329
+ """
330
+ if self.output_stream is None:
331
+ raise ValueError(
332
+ "Can't write to an empty stream. the stream must not be None:"
333
+ " either by set_stream or by initialization")
334
+ self.output_stream.write(
335
+ str(self.indent_level*self.indent_value + sep.join(args)+end))
336
+
337
+ def set_stream(self, stream: IO) -> None:
338
+ """explicitly sets the stream
339
+
340
+ Args:
341
+ stream (IO): stream
342
+ """
343
+ self.output_stream = stream
344
+ self.output_stream = cast(IO, self.output_stream)
345
+
346
+ def indent(self) -> None:
347
+ """indents the preceding output with write() by one quantity more
348
+ """
349
+ self.indent_level += 1
350
+
351
+ def undent(self) -> None:
352
+ """un-dents the preceding output with write() by one quantity less
353
+ has a minimum value of 0
354
+ """
355
+ self.indent_level = max(0, self.indent_level-1)
356
+
357
+
358
+ class IndentedWriter2:
359
+ """every class that will inherit this class will have the following functions available
360
+ write() with the same arguments a builtin print()
361
+ indent()
362
+ undent()
363
+
364
+ also, it is expected in the __init__ function to call super().__init__()
365
+ also, the output_stream must be set whether by the first argument io super().__init__(...)
366
+ or by set_stream() explicitly somewhere else.
367
+
368
+ this class will not function properly is the output_stream is not set!
369
+
370
+ """
371
+
372
+ def __init__(self, indent_value: str = "\t"):
373
+ self.indent_level = 0
374
+ self.indent_value = indent_value
375
+ self.buffer: str = ""
376
+
377
+ def to_stream(self, stream: IO[str]) -> None:
378
+ """outputs the buffer to a stream
379
+
380
+ Args:
381
+ stream (IO[str]): the stream to output to
382
+ """
383
+ stream.write(self.buffer)
384
+
385
+ def write(self, *args, sep=" ", end="\n") -> None:
386
+ """writes the supplied arguments to the output_stream
387
+
388
+ Args:
389
+ sep (str, optional): the str to use as a separator between arguments. Defaults to " ".
390
+ end (str, optional): the str to use as the final value. Defaults to "\n".
391
+
392
+ Raises:
393
+ ValueError: _description_
394
+ """
395
+ self.buffer += str(self.indent_level *
396
+ self.indent_value + sep.join(args)+end)
397
+
398
+ def indent(self) -> None:
399
+ """indents the preceding output with write() by one quantity more
400
+ """
401
+ self.indent_level += 1
402
+
403
+ def undent(self) -> None:
404
+ """un-dents the preceding output with write() by one quantity less
405
+ has a minimum value of 0
406
+ """
407
+ self.indent_level = max(0, self.indent_level-1)
408
+
409
+
410
+ __all__ = [
411
+ "path_exists",
412
+ "file_exists",
413
+ "directory_exists",
414
+ "delete_file",
415
+ "read_file",
416
+ "is_file",
417
+ "is_directory",
418
+ "get_files",
419
+ "get_files_and_directories",
420
+ "get_directories",
421
+ "delete_directory",
422
+ "clear_directory",
423
+ "create_directory",
424
+ 'create_file',
425
+ "get_file_type_from_directory",
426
+ "get_file_type_from_directory_recursively",
427
+ "rename_file",
428
+ "move_file",
429
+ "open_file",
430
+ # "move_directory",
431
+ # "copy_file",
432
+ # "copy_directory",
433
+ "IndentedWriter",
434
+ "IndentedWriter2"
435
+ ]
@@ -1,4 +1,4 @@
1
- from ..classes.Counter import Counter
1
+ from ..classes.counter import Counter
2
2
 
3
3
 
4
4
  class InstanceCacheMeta(type):
@@ -1,10 +1,15 @@
1
1
  from typing import Optional
2
2
  from tqdm import tqdm
3
+ from .reflection import get_python_version
4
+ if get_python_version() >= (3, 9):
5
+ from builtins import list as t_list # type:ignore
6
+ else:
7
+ from typing import List as t_list
3
8
 
4
9
 
5
10
  class ProgressBarPool:
6
- def __init__(self, num_of_bars: int = 1, *, global_options: Optional[dict] = None, individual_options: Optional[list[Optional[dict]]] = None) -> None:
7
- self.bars: list[tqdm] = []
11
+ def __init__(self, num_of_bars: int = 1, *, global_options: Optional[dict] = None, individual_options: Optional[t_list[Optional[dict]]] = None) -> None:
12
+ self.bars: t_list[tqdm] = []
8
13
  if global_options is None:
9
14
  global_options = {}
10
15
  if individual_options is None:
@@ -1,7 +1,12 @@
1
1
  import inspect
2
+ from ..reflection import get_python_version
3
+ if get_python_version() >= (3, 9):
4
+ from builtins import list as t_list # type:ignore
5
+ else:
6
+ from typing import List as t_list
2
7
 
3
8
 
4
- def get_explicitly_declared_functions(cls: type) -> list[str]:
9
+ def get_explicitly_declared_functions(cls: type) -> t_list[str]:
5
10
  """
6
11
  Returns the names of the functions that are explicitly declared in a class.
7
12
 
@@ -3,6 +3,11 @@ from abc import ABC, abstractmethod
3
3
  from typing import Optional, Any
4
4
  from logging import error
5
5
  import danielutils
6
+ from ..reflection import get_python_version
7
+ if get_python_version() >= (3, 9):
8
+ from builtins import tuple as t_tuple # type:ignore
9
+ else:
10
+ from typing import Tuple as t_tuple
6
11
 
7
12
 
8
13
  class Worker(ABC):
@@ -56,7 +61,7 @@ class Worker(ABC):
56
61
  """
57
62
  self.pool._notify() # pylint: disable=protected-access
58
63
 
59
- def acquire(self) -> Optional[tuple[Any]]:
64
+ def acquire(self) -> Optional[t_tuple[Any]]:
60
65
  """acquire a new job object to work on from the pool
61
66
  will return a tuple of only one object (the job) or None if there are no more jobs
62
67
  Returns:
@@ -2,18 +2,23 @@ from queue import Queue
2
2
  from typing import Optional, Any
3
3
  from threading import Semaphore
4
4
  from .worker import Worker
5
+ from ..reflection import get_python_version
6
+ if get_python_version() >= (3, 9):
7
+ from builtins import type as t_type, tuple as t_tuple, list as t_list # type:ignore
8
+ else:
9
+ from typing import Type as t_type, Tuple as t_tuple, List as t_list
5
10
 
6
11
 
7
12
  class WorkerPool:
8
13
  """A worker pool class
9
14
  """
10
15
 
11
- def __init__(self, num_workers: int, worker_class: type[Worker], w_kwargs: dict, global_variables: dict) -> None:
16
+ def __init__(self, num_workers: int, worker_class: t_type[Worker], w_kwargs: dict, global_variables: dict) -> None:
12
17
  self.num_workers = num_workers
13
18
  self.global_variables: dict = global_variables
14
- self.q: Queue[tuple[Any]] = Queue()
19
+ self.q: Queue[t_tuple[Any]] = Queue()
15
20
  self.worker_class = worker_class
16
- self.workers: list[Worker] = []
21
+ self.workers: t_list[Worker] = []
17
22
  self.sem = Semaphore(0)
18
23
  self.w_kwargs = w_kwargs
19
24
 
@@ -30,7 +35,7 @@ class WorkerPool:
30
35
  self.q.put((job,))
31
36
  self.sem.release()
32
37
 
33
- def _acquire(self) -> Optional[tuple[Any]]:
38
+ def _acquire(self) -> Optional[t_tuple[Any]]:
34
39
  """acquire a new job from the pool
35
40
 
36
41
  Returns:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: danielutils
3
- Version: 0.9.61
3
+ Version: 0.9.63
4
4
  Summary: A python utils library for things I find useful
5
5
  Home-page: https://github.com/danielnachumdev/danielutils
6
6
  Author: danielnachumdev
@@ -44,7 +44,7 @@ Requires-Dist: tqdm
44
44
  [![Python 3.10.11](https://img.shields.io/badge/python-3.10.11-blue.svg)](https://www.python.org/downloads/release/python-31011/)
45
45
  [![gitleaks](https://github.com/danielnachumdev/danielutils/actions/workflows/gitleaks.yml/badge.svg)](https://github.com/danielnachumdev/danielutils/actions/workflows/gitleaks.yml)
46
46
  [![CodeQL](https://github.com/danielnachumdev/danielutils/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/danielnachumdev/danielutils/actions/workflows/github-code-scanning/codeql)
47
- # danielutils v=0.9.61
47
+ # danielutils v=0.9.63
48
48
  A utils library for things that I find useful for my coding workflow.\
49
49
  Feel free to use and / or contribute / improve my code :)
50
50
 
@@ -8,6 +8,7 @@ danielutils/colors.py
8
8
  danielutils/date.py
9
9
  danielutils/date_time.py
10
10
  danielutils/exceptions.py
11
+ danielutils/files_and_folders.py
11
12
  danielutils/internet.py
12
13
  danielutils/io.py
13
14
  danielutils/loops.py
@@ -26,23 +27,25 @@ danielutils.egg-info/requires.txt
26
27
  danielutils.egg-info/top_level.txt
27
28
  danielutils/classes/Convenience.py
28
29
  danielutils/classes/Counter.py
29
- danielutils/classes/Shell.py
30
30
  danielutils/classes/Tree.py
31
31
  danielutils/classes/__init__.py
32
+ danielutils/classes/convenience.py
33
+ danielutils/classes/counter.py
32
34
  danielutils/classes/frange.py
33
- danielutils/classes/SortedBuiltins/__init__.py
34
- danielutils/classes/SortedBuiltins/sset.py
35
- danielutils/classes/TypedBuiltins/__init__.py
36
- danielutils/classes/TypedBuiltins/factory.py
37
- danielutils/classes/TypedBuiltins/tdict.py
38
- danielutils/classes/TypedBuiltins/tlist.py
39
- danielutils/classes/TypedBuiltins/tset.py
40
- danielutils/classes/TypedBuiltins/ttuple.py
41
- danielutils/conversions/MainConversions.py
35
+ danielutils/classes/repl.py
36
+ danielutils/classes/sorted_builtins/__init__.py
37
+ danielutils/classes/sorted_builtins/sset.py
38
+ danielutils/classes/typed_builtins/__init__.py
39
+ danielutils/classes/typed_builtins/factory.py
40
+ danielutils/classes/typed_builtins/tdict.py
41
+ danielutils/classes/typed_builtins/tlist.py
42
+ danielutils/classes/typed_builtins/tset.py
43
+ danielutils/classes/typed_builtins/ttuple.py
42
44
  danielutils/conversions/__init__.py
43
- danielutils/conversions/SpecializedConversions/__init__.py
44
- danielutils/conversions/SpecializedConversions/to_hex.py
45
- danielutils/conversions/SpecializedConversions/to_int.py
45
+ danielutils/conversions/main_conversions.py
46
+ danielutils/conversions/specialized_conversions/__init__.py
47
+ danielutils/conversions/specialized_conversions/to_hex.py
48
+ danielutils/conversions/specialized_conversions/to_int.py
46
49
  danielutils/data_structures/Comparer.py
47
50
  danielutils/data_structures/Graph.py
48
51
  danielutils/data_structures/Heap.py
@@ -50,7 +53,14 @@ danielutils/data_structures/Node.py
50
53
  danielutils/data_structures/Queue.py
51
54
  danielutils/data_structures/Stack.py
52
55
  danielutils/data_structures/__init__.py
56
+ danielutils/data_structures/comparer.py
57
+ danielutils/data_structures/default_dict.py
53
58
  danielutils/data_structures/functions.py
59
+ danielutils/data_structures/graph.py
60
+ danielutils/data_structures/heap.py
61
+ danielutils/data_structures/node.py
62
+ danielutils/data_structures/queue.py
63
+ danielutils/data_structures/stack.py
54
64
  danielutils/decorators/PartiallyImplemented.py
55
65
  danielutils/decorators/__init__.py
56
66
  danielutils/decorators/atomic.py
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.0"]
3
3
  build-backend = "setuptools.build_meta"
4
4
  [project]
5
5
  name = "danielutils"
6
- version = "0.9.61"
6
+ version = "0.9.63"
7
7
  authors = [
8
8
  { name = "danielnachumdev", email = "danielnachumdev@gmail.com" },
9
9
  ]
@@ -17,8 +17,8 @@ classifiers = [
17
17
  "Development Status :: 3 - Alpha",
18
18
  "Intended Audience :: Developers",
19
19
  "Programming Language :: Python :: 3",
20
- # "Operating System :: Unix",
21
- # "Operating System :: MacOS :: MacOS X",
20
+ # "Operating system :: Unix",
21
+ # "Operating system :: MacOS :: MacOS X",
22
22
  "Operating System :: Microsoft :: Windows",
23
23
  ]
24
24
 
@@ -9,7 +9,7 @@ def read_file(path: str) -> "list[str]":
9
9
 
10
10
  README_PATH = 'README.md'
11
11
  DESCRIPTION = 'A python utils library for things I find useful'
12
- VERSION = "0.9.61"
12
+ VERSION = "0.9.63"
13
13
  LONG_DESCRIPTION = '\n'.join(read_file(README_PATH))
14
14
  setup(
15
15
  name="danielutils",
@@ -30,9 +30,9 @@ setup(
30
30
  "Development Status :: 3 - Alpha",
31
31
  "Intended Audience :: Developers",
32
32
  "Programming Language :: Python :: 3",
33
- # "Operating System :: Unix",
34
- # "Operating System :: MacOS :: MacOS X",
35
- "Operating System :: Microsoft :: Windows",
33
+ # "Operating system :: Unix",
34
+ # "Operating system :: MacOS :: MacOS X",
35
+ "Operating system :: Microsoft :: Windows",
36
36
  ]
37
37
  )
38
38
  # python .\setup.py sdist
@@ -1,6 +0,0 @@
1
- from .SortedBuiltins import *
2
- from .TypedBuiltins import *
3
- from .Convenience import *
4
- from .frange import *
5
- from .Counter import *
6
- from .Shell import *
@@ -1,2 +0,0 @@
1
- from .MainConversions import *
2
- from .SpecializedConversions import *
@@ -1,6 +0,0 @@
1
- from .Queue import *
2
- from .Heap import *
3
- from .Comparer import *
4
- from .Node import *
5
- from .Graph import *
6
- from .Stack import *
File without changes
File without changes