memorymanagement 1.1.0__tar.gz → 1.1.2__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.
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: memorymanagement
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Summary: Adds support for memory management
5
- Home-page: https://github.com/Ricardo-Werner-Rivas/python-memory-management/tree/PyPI
5
+ Home-page: https://github.com/Ricardo-Werner-Rivas/memorymanagement/tree/PyPI
6
6
  Author: Ricardo Werner Rivas
7
7
  Author-email: ricardowernerrivas@gmail.com
8
8
  License: MIT
9
- Project-URL: Bug Tracker, https://github.com/Ricardo-Werner-Rivas/python-memory-management/issues
10
- Project-URL: Repository, https://github.com/Ricardo-Werner-Rivas/python-memory-management
9
+ Project-URL: Bug Tracker, https://github.com/Ricardo-Werner-Rivas/memorymanagement/issues
10
+ Project-URL: Repository, https://github.com/Ricardo-Werner-Rivas/memorymanagement
11
11
  Classifier: Programming Language :: Python
12
12
  Classifier: Operating System :: Microsoft :: Windows
13
13
  Description-Content-Type: text/markdown
@@ -26,12 +26,12 @@ It is also possible to modify the list of flagged references through its methods
26
26
  ### `pointers`
27
27
  Provides a safe implementation of pointers for Python.
28
28
  #### Class `Pointer`
29
- The pointer itself. Imitates the behaviour of C pointers. This pointer points to a reference, not to an object stored in memory.
29
+ The pointer itself. Imitates the behaviour of C pointers. `Pointer` points to a **reference**, not to an object stored in memory.
30
30
  #### Decorator `pointerize`
31
31
  Allows functions to receive pointers instead of values.
32
32
  ## Installation
33
- You can install the `memorymanagement` package from PyPI as follows:
34
- ```ps
33
+ You can install the `memorymanagement` package from **PyPI** as follows:
34
+ ```powershell
35
35
  pip install memorymanagement
36
36
  ```
37
37
  ## How to use
@@ -159,10 +159,22 @@ Value: 20
159
159
 
160
160
  ```
161
161
  ## Contribution
162
- To contribute to this project, clone or fork this repository.
162
+ To contribute to this project fork this repository and clone your fork. Pull requests will be revised by the owner before being accepted or rejected.
163
163
 
164
- There are to branches:
165
- * PyPI: the main branch, for releases.
166
- * TestPyPI: for pre-releases or development versions.
164
+ There are two branches:
165
+ * **PyPI**: the main branch, for releases.
166
+ * **TestPyPI**: for pre-releases or development versions.
167
167
 
168
- Pull requests from TestPyPI to PyPI will be accepted when a new release is finished.
168
+ Pull requests from TestPyPI to PyPI will only be done by the owner when a new release is ready.
169
+
170
+ To merge branches properly with PyPI branch in your cloned repository, you will need to have the `.gitattributes` file in the PyPI branch and execute the following commands, while in repo directory, in your PowerShell:
171
+ ```powershell
172
+ git config merge.keepPyPIFiles.name "Keep README.md and setup.cfg from PyPI branch on merge"
173
+ git config merge.keepPyPIFiles.driver "bash -c 'cp $(git rev-parse --show-toplevel)/$3 $2'"
174
+ ```
175
+ Or in your git bash terminal:
176
+ ```bash
177
+ git config merge.keepPyPIFiles.name "Keep README.md and setup.cfg from PyPI branch on merge"
178
+ git config merge.keepPyPIFiles.driver "bash -c 'cp $(git rev-parse --show-toplevel)/$3 $2'"
179
+ ```
180
+ This way, READMEs and setup files will not be overwritten in the PyPI branch.
@@ -10,12 +10,12 @@ It is also possible to modify the list of flagged references through its methods
10
10
  ### `pointers`
11
11
  Provides a safe implementation of pointers for Python.
12
12
  #### Class `Pointer`
13
- The pointer itself. Imitates the behaviour of C pointers. This pointer points to a reference, not to an object stored in memory.
13
+ The pointer itself. Imitates the behaviour of C pointers. `Pointer` points to a **reference**, not to an object stored in memory.
14
14
  #### Decorator `pointerize`
15
15
  Allows functions to receive pointers instead of values.
16
16
  ## Installation
17
- You can install the `memorymanagement` package from PyPI as follows:
18
- ```ps
17
+ You can install the `memorymanagement` package from **PyPI** as follows:
18
+ ```powershell
19
19
  pip install memorymanagement
20
20
  ```
21
21
  ## How to use
@@ -143,10 +143,22 @@ Value: 20
143
143
 
144
144
  ```
145
145
  ## Contribution
146
- To contribute to this project, clone or fork this repository.
146
+ To contribute to this project fork this repository and clone your fork. Pull requests will be revised by the owner before being accepted or rejected.
147
147
 
148
- There are to branches:
149
- * PyPI: the main branch, for releases.
150
- * TestPyPI: for pre-releases or development versions.
148
+ There are two branches:
149
+ * **PyPI**: the main branch, for releases.
150
+ * **TestPyPI**: for pre-releases or development versions.
151
151
 
152
- Pull requests from TestPyPI to PyPI will be accepted when a new release is finished.
152
+ Pull requests from TestPyPI to PyPI will only be done by the owner when a new release is ready.
153
+
154
+ To merge branches properly with PyPI branch in your cloned repository, you will need to have the `.gitattributes` file in the PyPI branch and execute the following commands, while in repo directory, in your PowerShell:
155
+ ```powershell
156
+ git config merge.keepPyPIFiles.name "Keep README.md and setup.cfg from PyPI branch on merge"
157
+ git config merge.keepPyPIFiles.driver "bash -c 'cp $(git rev-parse --show-toplevel)/$3 $2'"
158
+ ```
159
+ Or in your git bash terminal:
160
+ ```bash
161
+ git config merge.keepPyPIFiles.name "Keep README.md and setup.cfg from PyPI branch on merge"
162
+ git config merge.keepPyPIFiles.driver "bash -c 'cp $(git rev-parse --show-toplevel)/$3 $2'"
163
+ ```
164
+ This way, READMEs and setup files will not be overwritten in the PyPI branch.
@@ -42,7 +42,7 @@ class Cleaner:
42
42
  Returns the list of variables to be erased from memory.
43
43
  None of this properties has setter or deleter. Those lists can only be manipulated through the class methods.
44
44
  """
45
- def __init__(self,not_delete:list[str]=list(vars(modules["__main__"])),excluded:list[str]=[],flagged:list[str]=[]):
45
+ def __init__(self,not_delete:list[str]|None=None,excluded:list[str]=[],flagged:list[str]=[]):
46
46
  """
47
47
  Initializes the class instance.\n
48
48
  It is recommended to initialize the instance right after all global imports at the beggining of the program so no argument is needed.
@@ -53,13 +53,14 @@ class Cleaner:
53
53
  excluded (`list[str]`, Optional): List of variables to be excluded from the memory cleaning process. Empty list by default.
54
54
  flagged (`list[str]`, Optional): List of variables to be erased from memory. Empty list by default.
55
55
  """
56
+ if not not_delete:
57
+ not_delete=list(vars(modules["__main__"]))
56
58
  for key,value in vars(modules["__main__"]).copy().items():
57
59
  if isinstance(value,Cleaner) and key in vars(modules["__main__"]).keys():
58
60
  del vars(modules["__main__"])[key]
59
61
  self._not_delete=not_delete.copy()
60
62
  self._excluded=excluded.copy()
61
63
  self._flagged=flagged.copy()
62
- return
63
64
  def update(self,exclude:str|list[str]|tuple[str]|None=None,include:str|list[str]|tuple[str]|None=None):
64
65
  """
65
66
  Flags all the new global variables' references that were not manually excluded here or before. You can also include previously excluded references.
@@ -82,7 +83,10 @@ class Cleaner:
82
83
  while var in self._excluded:
83
84
  self._excluded.remove(var)
84
85
  self._flagged=[var for var in list(vars(modules["__main__"])) if var not in self._not_delete and var not in self._excluded]
85
- return
86
+ for var in self._flagged.copy():
87
+ if isinstance(vars(modules["__main__"])[var],Cleaner):
88
+ self._flagged.remove(var)
89
+ self._not_delete.append(var)
86
90
  @property
87
91
  def not_delete(self):
88
92
  return self._not_delete
@@ -105,7 +109,6 @@ class Cleaner:
105
109
  self._flagged.remove(var)
106
110
  if var not in self._excluded:
107
111
  self._excluded.append(var)
108
- return
109
112
  def include(self,*include:str):
110
113
  """
111
114
  Allows to include the desired references (previously excluded) in the cleaning process.
@@ -119,7 +122,6 @@ class Cleaner:
119
122
  self._flagged.append(var)
120
123
  while var in self._excluded:
121
124
  self._excluded.remove(var)
122
- return
123
125
  def clean(self):
124
126
  """
125
127
  Culminates the cleaning process. Erases all the flagged references.
@@ -128,7 +130,6 @@ class Cleaner:
128
130
  if var in list(vars(modules["__main__"])):
129
131
  del vars(modules["__main__"])[var]
130
132
  self._flagged.clear()
131
- return
132
133
  def __str__(self):
133
134
  string=f"""
134
135
  Flagged: {self.flagged}
@@ -1,3 +1,17 @@
1
+ #*===============================================================================================================================
2
+ #* LEGEND
3
+ #*-------------------------------------------------------------------------------------------------------------------------------
4
+ #! Missing
5
+ #? Question
6
+ #* Section
7
+ #^ Important
8
+ # Normal comment
9
+ #// Alternative or deprecated code
10
+ #*===============================================================================================================================
11
+
12
+ #^ The different types of comments require the "Colorful Comments Refreshed" extension for VSCode to be properly distinguished
13
+
14
+ #* IMPORTS
1
15
  # Import "TypeVar" and "Generic"
2
16
  from typing import TypeVar,Generic
3
17
  # Import "modules" from "sys" package
@@ -5,10 +19,9 @@ from sys import modules
5
19
  # Import "currentframe" from "inspect" package
6
20
  from inspect import currentframe
7
21
 
8
- # Create new generic type
9
- object_type=TypeVar("object_type")
10
- # Define the class "Pointer"
11
- class Pointer(Generic[object_type]):
22
+ #* MAIN CLASS
23
+ # Define the class "Pointer" with generic type
24
+ class Pointer(Generic[TypeVar("Any")]):
12
25
  """
13
26
  Implements pointers in Python for both mutable (though unneded) and non-mutable objects.
14
27
  These pointers are completely safe and do not work internally as C's pointers, they are just an imitation of their behaviour.
@@ -66,7 +79,6 @@ class Pointer(Generic[object_type]):
66
79
  self._value=value
67
80
  self._vars_dict=vars_dict
68
81
  self._attr=attr
69
- name=None
70
82
  name=[]
71
83
  for key,v in vars_dict.items():
72
84
  try:
@@ -90,7 +102,11 @@ class Pointer(Generic[object_type]):
90
102
  name=None
91
103
  self._name=name
92
104
  return
105
+
106
+ #* PROPERTIES
107
+ # Value
93
108
  @property
109
+ # Getter
94
110
  def value(self):
95
111
  if self._attr:
96
112
  if self._name and self._name not in list(self._vars_dict):
@@ -107,6 +123,7 @@ class Pointer(Generic[object_type]):
107
123
  if self._value is not self._vars_dict[self._name]:
108
124
  self._value=self._vars_dict[self._name]
109
125
  return self._value
126
+ # Setter
110
127
  @value.setter
111
128
  def value(self,value):
112
129
  if self._attr:
@@ -116,6 +133,7 @@ class Pointer(Generic[object_type]):
116
133
  if self._name and value is not self._vars_dict[self._name]:
117
134
  self._vars_dict[self._name]=value
118
135
  return
136
+ # Deleter
119
137
  @value.deleter
120
138
  def value(self):
121
139
  if self._attr:
@@ -125,15 +143,186 @@ class Pointer(Generic[object_type]):
125
143
  if self._name:
126
144
  del self._vars_dict[self._name]
127
145
  return
146
+
147
+ #* INDEXATION
148
+ # Getter
128
149
  def __getitem__(self,index):
129
150
  return self.value[index]
151
+ # Setter
130
152
  def __setitem__(self,index,value):
131
153
  self.value[index]=value
132
154
  return
155
+ # Deleter
133
156
  def __delitem__(self,index):
134
157
  del self.value[index]
135
158
  return
136
- def __str__(self):
137
- return str(self.value)
159
+
160
+ #* ARITHMETIC OPERATIONS
161
+ # Addition
162
+ def __add__(self,value):
163
+ if isinstance(value,Pointer):
164
+ return self.value+value.value
165
+ else:
166
+ return self.value+value
167
+ # Difference
168
+ def __sub__(self,value):
169
+ if isinstance(value,Pointer):
170
+ return self.value-value.value
171
+ else:
172
+ return self.value-value
173
+ # Multiplication
174
+ def __mul__(self,value):
175
+ if isinstance(value,Pointer):
176
+ return self.value*value.value
177
+ else:
178
+ return self.value*value
179
+ # Fraction
180
+ def __truediv__(self,value):
181
+ if isinstance(value,Pointer):
182
+ return self.value/value.value
183
+ else:
184
+ return self.value/value
185
+ # Integer division
186
+ def __floordiv__(self,value):
187
+ if isinstance(value,Pointer):
188
+ return self.value//value.value
189
+ else:
190
+ return self.value//value
191
+ # Module
192
+ def __mod__(self,value):
193
+ if isinstance(value,Pointer):
194
+ return self.value%value.value
195
+ else:
196
+ return self.value%value
197
+ # Power
198
+ def __pow__(self,value):
199
+ if isinstance(value,Pointer):
200
+ return self.value**value.value
201
+ else:
202
+ return self.value**value
203
+
204
+ #* REFLEXED ARITHMETIC METHODS
205
+ # Addition
206
+ def __radd__(self,value):
207
+ return value+self.value
208
+ # Difference
209
+ def __rsub__(self,value):
210
+ return value-self.value
211
+ # Multiplication
212
+ def __rmul__(self,value):
213
+ return value*self.value
214
+ # Fraction
215
+ def __rtruediv__(self,value):
216
+ return value/self.value
217
+ # Integer division
218
+ def __rfloordiv__(self,value):
219
+ return value//self.value
220
+ # Module
221
+ def __rmod__(self,value):
222
+ return value%self.value
223
+ # Power
224
+ def __rpow__(self,value):
225
+ return value**self.value
226
+
227
+ #* IN-PLACE ARITHMETIC METHODS
228
+ # Addition
229
+ def __iadd__(self,value):
230
+ self.value=self.value+value
231
+ return self
232
+ # Difference
233
+ def __isub__(self,value):
234
+ self.value=self.value-value
235
+ return self
236
+ # Multiplication
237
+ def __imul__(self,value):
238
+ self.value=self.value*value
239
+ return self
240
+ # Fraction
241
+ def __itruediv__(self,value):
242
+ self.value=self.value/value
243
+ return self
244
+ # Integer division
245
+ def __ifloordiv__(self,value):
246
+ self.value=self.value//value
247
+ return self
248
+ # Module
249
+ def __imod__(self,value):
250
+ self.value=self.value%value
251
+ return self
252
+ def __ipow__(self,value):
253
+ self.value=self.value**value
254
+ return self
255
+
256
+ #* COMPARATIVE METHODS
257
+ # Equality
258
+ def __eq__(self,value):
259
+ if isinstance(value,Pointer):
260
+ return self.value==value.value
261
+ else:
262
+ return self.value==value
263
+ # Inequality
264
+ def __ne__(self,value):
265
+ if isinstance(value,Pointer):
266
+ return self.value!=value.value
267
+ else:
268
+ return self.value!=value
269
+ # Lower than
270
+ def __lt__(self,value):
271
+ if isinstance(value,Pointer):
272
+ return self.value<value.value
273
+ else:
274
+ return self.value<value
275
+ # Lower or equal
276
+ def __le__(self,value):
277
+ if isinstance(value,Pointer):
278
+ return self.value<=value.value
279
+ else:
280
+ return self.value<=value
281
+ # Greater than
282
+ def __gt__(self,value):
283
+ if isinstance(value,Pointer):
284
+ return self.value>value.value
285
+ else:
286
+ return self.value>value
287
+ # Greater or equal
288
+ def __ge__(self,value):
289
+ if isinstance(value,Pointer):
290
+ return self.value>=value.value
291
+ else:
292
+ return self.value>=value
293
+
294
+ #* UNARY METHODS
295
+ # Negative
296
+ def __neg__(self):
297
+ return Pointer(-self.value)
298
+ # Positive
299
+ def __pos__(self):
300
+ return Pointer(+self.value)
301
+ # Absolute value
302
+ def __abs__(self):
303
+ return Pointer(abs(self.value))
304
+
305
+ #* LENGTH
306
+ # Length
307
+ def __len__(self):
308
+ return len(self.value)
309
+
310
+ #* TRANSFORMATION METHODS
311
+ # __int__
312
+ def __int__(self):
313
+ return int(self.value)
314
+ def __float__(self):
315
+ return float(self.value)
316
+ def __index__(self):
317
+ return self.value
318
+
319
+ #* SCREEN
320
+ # Representation
138
321
  def __repr__(self):
139
- return f"{self.__class__.__name__}({self.value})"
322
+ return f"{self.__class__.__name__}({self.value})"
323
+ # HTML representation
324
+ def _repr_html_(self):
325
+ return f"<p>{self.value}</p>"
326
+ # Printing
327
+ def __str__(self):
328
+ return str(self.value)
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: memorymanagement
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Summary: Adds support for memory management
5
- Home-page: https://github.com/Ricardo-Werner-Rivas/python-memory-management/tree/PyPI
5
+ Home-page: https://github.com/Ricardo-Werner-Rivas/memorymanagement/tree/PyPI
6
6
  Author: Ricardo Werner Rivas
7
7
  Author-email: ricardowernerrivas@gmail.com
8
8
  License: MIT
9
- Project-URL: Bug Tracker, https://github.com/Ricardo-Werner-Rivas/python-memory-management/issues
10
- Project-URL: Repository, https://github.com/Ricardo-Werner-Rivas/python-memory-management
9
+ Project-URL: Bug Tracker, https://github.com/Ricardo-Werner-Rivas/memorymanagement/issues
10
+ Project-URL: Repository, https://github.com/Ricardo-Werner-Rivas/memorymanagement
11
11
  Classifier: Programming Language :: Python
12
12
  Classifier: Operating System :: Microsoft :: Windows
13
13
  Description-Content-Type: text/markdown
@@ -26,12 +26,12 @@ It is also possible to modify the list of flagged references through its methods
26
26
  ### `pointers`
27
27
  Provides a safe implementation of pointers for Python.
28
28
  #### Class `Pointer`
29
- The pointer itself. Imitates the behaviour of C pointers. This pointer points to a reference, not to an object stored in memory.
29
+ The pointer itself. Imitates the behaviour of C pointers. `Pointer` points to a **reference**, not to an object stored in memory.
30
30
  #### Decorator `pointerize`
31
31
  Allows functions to receive pointers instead of values.
32
32
  ## Installation
33
- You can install the `memorymanagement` package from PyPI as follows:
34
- ```ps
33
+ You can install the `memorymanagement` package from **PyPI** as follows:
34
+ ```powershell
35
35
  pip install memorymanagement
36
36
  ```
37
37
  ## How to use
@@ -159,10 +159,22 @@ Value: 20
159
159
 
160
160
  ```
161
161
  ## Contribution
162
- To contribute to this project, clone or fork this repository.
162
+ To contribute to this project fork this repository and clone your fork. Pull requests will be revised by the owner before being accepted or rejected.
163
163
 
164
- There are to branches:
165
- * PyPI: the main branch, for releases.
166
- * TestPyPI: for pre-releases or development versions.
164
+ There are two branches:
165
+ * **PyPI**: the main branch, for releases.
166
+ * **TestPyPI**: for pre-releases or development versions.
167
167
 
168
- Pull requests from TestPyPI to PyPI will be accepted when a new release is finished.
168
+ Pull requests from TestPyPI to PyPI will only be done by the owner when a new release is ready.
169
+
170
+ To merge branches properly with PyPI branch in your cloned repository, you will need to have the `.gitattributes` file in the PyPI branch and execute the following commands, while in repo directory, in your PowerShell:
171
+ ```powershell
172
+ git config merge.keepPyPIFiles.name "Keep README.md and setup.cfg from PyPI branch on merge"
173
+ git config merge.keepPyPIFiles.driver "bash -c 'cp $(git rev-parse --show-toplevel)/$3 $2'"
174
+ ```
175
+ Or in your git bash terminal:
176
+ ```bash
177
+ git config merge.keepPyPIFiles.name "Keep README.md and setup.cfg from PyPI branch on merge"
178
+ git config merge.keepPyPIFiles.driver "bash -c 'cp $(git rev-parse --show-toplevel)/$3 $2'"
179
+ ```
180
+ This way, READMEs and setup files will not be overwritten in the PyPI branch.
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = memorymanagement
3
- version = 1.1.0
3
+ version = 1.1.2
4
4
  author = Ricardo Werner Rivas
5
5
  author_email = ricardowernerrivas@gmail.com
6
6
  description = Adds support for memory management
@@ -8,10 +8,10 @@ long_description = file:README.md
8
8
  long_description_content_type = text/markdown
9
9
  license = MIT
10
10
  license_files = LICENSE
11
- url = https://github.com/Ricardo-Werner-Rivas/python-memory-management/tree/PyPI
11
+ url = https://github.com/Ricardo-Werner-Rivas/memorymanagement/tree/PyPI
12
12
  project_urls =
13
- Bug Tracker=https://github.com/Ricardo-Werner-Rivas/python-memory-management/issues
14
- Repository=https://github.com/Ricardo-Werner-Rivas/python-memory-management
13
+ Bug Tracker=https://github.com/Ricardo-Werner-Rivas/memorymanagement/issues
14
+ Repository=https://github.com/Ricardo-Werner-Rivas/memorymanagement
15
15
  classifiers =
16
16
  Programming Language :: Python
17
17
  Operating System :: Microsoft :: Windows