imio.pyutils 1.1.2__tar.gz → 1.1.4__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 (25) hide show
  1. {imio_pyutils-1.1.2 → imio.pyutils-1.1.4}/CHANGES.rst +12 -0
  2. imio.pyutils-1.1.4/PKG-INFO +391 -0
  3. {imio_pyutils-1.1.2 → imio.pyutils-1.1.4}/imio/pyutils/system.py +2 -2
  4. {imio_pyutils-1.1.2 → imio.pyutils-1.1.4}/imio/pyutils/tests.py +4 -0
  5. {imio_pyutils-1.1.2 → imio.pyutils-1.1.4}/imio/pyutils/utils.py +9 -8
  6. imio.pyutils-1.1.4/imio.pyutils.egg-info/PKG-INFO +391 -0
  7. {imio_pyutils-1.1.2 → imio.pyutils-1.1.4}/imio.pyutils.egg-info/SOURCES.txt +1 -0
  8. imio.pyutils-1.1.4/imio.pyutils.egg-info/entry_points.txt +3 -0
  9. {imio_pyutils-1.1.2 → imio.pyutils-1.1.4}/setup.py +1 -1
  10. imio_pyutils-1.1.2/PKG-INFO +0 -382
  11. imio_pyutils-1.1.2/imio.pyutils.egg-info/PKG-INFO +0 -382
  12. {imio_pyutils-1.1.2 → imio.pyutils-1.1.4}/MANIFEST.in +0 -0
  13. {imio_pyutils-1.1.2 → imio.pyutils-1.1.4}/Makefile +0 -0
  14. {imio_pyutils-1.1.2 → imio.pyutils-1.1.4}/README.rst +0 -0
  15. {imio_pyutils-1.1.2 → imio.pyutils-1.1.4}/imio/__init__.py +0 -0
  16. {imio_pyutils-1.1.2 → imio.pyutils-1.1.4}/imio/pyutils/__init__.py +0 -0
  17. {imio_pyutils-1.1.2 → imio.pyutils-1.1.4}/imio/pyutils/batching.py +0 -0
  18. {imio_pyutils-1.1.2 → imio.pyutils-1.1.4}/imio/pyutils/bs.py +0 -0
  19. {imio_pyutils-1.1.2 → imio.pyutils-1.1.4}/imio/pyutils/postgres.py +0 -0
  20. {imio_pyutils-1.1.2 → imio.pyutils-1.1.4}/imio.pyutils.egg-info/dependency_links.txt +0 -0
  21. {imio_pyutils-1.1.2 → imio.pyutils-1.1.4}/imio.pyutils.egg-info/namespace_packages.txt +0 -0
  22. {imio_pyutils-1.1.2 → imio.pyutils-1.1.4}/imio.pyutils.egg-info/not-zip-safe +0 -0
  23. {imio_pyutils-1.1.2 → imio.pyutils-1.1.4}/imio.pyutils.egg-info/requires.txt +0 -0
  24. {imio_pyutils-1.1.2 → imio.pyutils-1.1.4}/imio.pyutils.egg-info/top_level.txt +0 -0
  25. {imio_pyutils-1.1.2 → imio.pyutils-1.1.4}/setup.cfg +0 -0
@@ -1,6 +1,18 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ 1.1.4 (2025-06-06)
5
+ ------------------
6
+
7
+ - Fixed `IndexError` in `utils.get_ordinal_clusters` when `numbers=[]`.
8
+ [gbastien]
9
+
10
+ 1.1.3 (2025-02-05)
11
+ ------------------
12
+
13
+ - Improved datetime import in system to correct load_var evaluation.
14
+ [sgeulette]
15
+
4
16
  1.1.2 (2024-12-19)
5
17
  ------------------
6
18
 
@@ -0,0 +1,391 @@
1
+ Metadata-Version: 1.2
2
+ Name: imio.pyutils
3
+ Version: 1.1.4
4
+ Summary: Some python useful methods
5
+ Home-page: https://github.com/imio/imio.pyutils/
6
+ Author: IMIO
7
+ Author-email: support@imio.be
8
+ License: GPL
9
+ Project-URL: Source, https://github.com/imio/imio.pyutils
10
+ Project-URL: PyPI, https://pypi.python.org/pypi/imio.pyutils
11
+ Description: .. image:: https://github.com/IMIO/imio.pyutils/actions/workflows/main.yml/badge.svg?branch=master
12
+ :target: https://github.com/IMIO/imio.pyutils/actions/workflows/main.yml
13
+
14
+ .. image:: https://coveralls.io/repos/github/IMIO/imio.pyutils/badge.svg
15
+ :target: https://coveralls.io/github/IMIO/imio.pyutils
16
+
17
+ .. image:: http://img.shields.io/pypi/v/imio.pyutils.svg
18
+ :alt: PyPI badge
19
+ :target: https://pypi.org/project/imio.pyutils
20
+
21
+ .. contents::
22
+
23
+ Introduction
24
+ ============
25
+
26
+ This package provides python useful methods.
27
+
28
+ It relates to following kinds of operations:
29
+
30
+ 1) System level operations (system.py)
31
+
32
+ It provides helper methods to:
33
+
34
+ * read and write files,
35
+ * read directories,
36
+ * execute commands,
37
+ * store and load list and dict,
38
+ * trace printing,
39
+ * creating temporary files,
40
+ * etc.
41
+
42
+ 2) Various python helpers (utils.py)
43
+
44
+ About:
45
+
46
+ * ordereddict and dict manipulations
47
+ * list manipulations
48
+ * duration recording
49
+
50
+ 3) BeautifulSoup methods (bs.py)
51
+
52
+ * remove elements
53
+ * remove attributes
54
+ * remove comments
55
+ * replace entire strings
56
+ * unwrap tags
57
+
58
+ 4) Postgres level operations (postgres.py). It requires psycopg2 egg !
59
+
60
+ It provides helper methods to:
61
+
62
+ * single or multiple select,
63
+ * insert, update, delete rows,
64
+ * etc.
65
+
66
+ Tests
67
+ =====
68
+
69
+ Can be run with: `bin/python -m unittest discover`
70
+
71
+ Changelog
72
+ =========
73
+
74
+ 1.1.4 (2025-06-06)
75
+ ------------------
76
+
77
+ - Fixed `IndexError` in `utils.get_ordinal_clusters` when `numbers=[]`.
78
+ [gbastien]
79
+
80
+ 1.1.3 (2025-02-05)
81
+ ------------------
82
+
83
+ - Improved datetime import in system to correct load_var evaluation.
84
+ [sgeulette]
85
+
86
+ 1.1.2 (2024-12-19)
87
+ ------------------
88
+
89
+ - Improved `batching.batch_delete_files`.
90
+ [sgeulette]
91
+
92
+ 1.1.1 (2024-09-18)
93
+ ------------------
94
+
95
+ - Generated universal wheel version.
96
+ [sgeulette]
97
+
98
+ 1.1.0 (2024-09-17)
99
+ ------------------
100
+
101
+ - Added `utils.add_key_if_value` to add a key in a dic only if value or is not None.
102
+ [sgeulette]
103
+ - Moved `batching.batch_delete_files` from imio.helpers to be used commonly.
104
+ [sgeulette]
105
+
106
+ 1.0.4 (2024-06-11)
107
+ ------------------
108
+
109
+ - Blacked files.
110
+ [sgeulette]
111
+ - Added `system.post_request` to send a POST request.
112
+ [sgeulette]
113
+
114
+ 1.0.3 (2024-05-24)
115
+ ------------------
116
+
117
+ - Fix bad release for python2.
118
+ [aduchene]
119
+
120
+ 1.0.2 (2024-05-15)
121
+ ------------------
122
+
123
+ - Added a new helper `utils.get_ordinal_clusters` to cluster ordinal numbers based on an offset.
124
+ [aduchene]
125
+
126
+ 1.0.1 (2024-04-08)
127
+ ------------------
128
+
129
+ - Added patterns parameter in `system.read_dir_filter`.
130
+ [sgeulette]
131
+ - Returned original filename in `system.hashed_filename` if string to hash is empty.
132
+ [sgeulette]
133
+
134
+ 1.0.0 (2024-03-05)
135
+ ------------------
136
+
137
+ - Require `six>=1.16.0`.
138
+ [sgeulette]
139
+ - Added `system.hashed_filename` to get a new filename differentiated by a hashed string.
140
+ [sgeulette]
141
+
142
+ 1.0.0a1 (2024-02-08)
143
+ --------------------
144
+
145
+ - Handled set in `load_var`.
146
+ [sgeulette]
147
+ - Added `load_pickle` and `dump_pickle`
148
+ [sgeulette]
149
+ - Improved `bs.is_empty`
150
+ [sgeulette]
151
+
152
+ 1.0.0a (2023-11-28)
153
+ -------------------
154
+
155
+ - Made py2 and py3 compliant
156
+ [sgeulette]
157
+ - Improved `utils_safe_encode`
158
+ [sgeulette]
159
+ - Added `bs.is_empty` function.
160
+ [sgeulette]
161
+ - Added `bs.remove_some_childrens` function.
162
+ [sgeulette]
163
+ - Added `bs.replace_strings_by_pattern` function
164
+ [sgeulette]
165
+ - Added `exclude_patterns` parameter in `system.read_recursive_dir`
166
+ [sgeulette]
167
+
168
+ 0.31 (2023-09-26)
169
+ -----------------
170
+
171
+ - Added `utils.listify` that will make sure a given value
172
+ is always returned as list-like iterable.
173
+ [gbastien]
174
+ - Improved `system.get_git_tag` with new parameter to get last tag from all branches
175
+ [sgeulette]
176
+ - Added `utils.radix_like_starting_1` to get list of positional numbers following a given base but starting with 1
177
+ [sgeulette]
178
+ - Added `utils.letters_sequence` to get a letters string corresponding to nth position
179
+ [sgeulette]
180
+
181
+ 0.30 (2023-07-24)
182
+ -----------------
183
+
184
+ - Added `system.read_recursive_dir` to get files recursively (with relative or full name).
185
+ [sgeulette]
186
+
187
+ 0.29 (2023-05-12)
188
+ -----------------
189
+
190
+ - Improved `utils.all_of_dict_values` to include optionally a label.
191
+ [sgeulette]
192
+ - Added `setup_logger` to modify a given logger independently
193
+ [sgeulette]
194
+ - Added `full_path` to prefix filename with path if necessary
195
+ [sgeulette]
196
+
197
+ 0.28 (2023-03-29)
198
+ -----------------
199
+
200
+ - Added `utils.one_of_dict_values` that gives the first non empty value of a list of keys.
201
+ [sgeulette]
202
+ - Added `utils.all_of_dict_values` that returns a not empty values list from a dict following a keys list
203
+ [sgeulette]
204
+
205
+ 0.27 (2023-02-27)
206
+ -----------------
207
+
208
+ - Added `utils.sort_by_indexes` that will sort a list of values
209
+ depending on a list of indexes.
210
+ [gbastien]
211
+
212
+ 0.26 (2022-12-12)
213
+ -----------------
214
+
215
+ - Added `stop` to print error and exit.
216
+ [sgeulette]
217
+
218
+ 0.25 (2022-09-16)
219
+ -----------------
220
+
221
+ - Added `get_git_tag`.
222
+ [sgeulette]
223
+
224
+ 0.24 (2022-08-19)
225
+ -----------------
226
+
227
+ - Added `utils.time_start` and `utils.time_elapsed` to print elapsed time from start.
228
+ Intended to be easily used when debugging...
229
+ [sgeulette]
230
+
231
+ 0.23 (2022-07-01)
232
+ -----------------
233
+
234
+ - Added `utils.append` to append a value and return it.
235
+ [sgeulette]
236
+
237
+ 0.22 (2022-04-28)
238
+ -----------------
239
+
240
+ - Added `utils.get_clusters` to display a list of number grouped by clusters.
241
+ [gbastien]
242
+
243
+ 0.21 (2022-04-26)
244
+ -----------------
245
+
246
+ - Added `utils.merge_dicts` to be able to merge several dicts for which values
247
+ are list, list are extended in final result.
248
+ [gbastien]
249
+
250
+ 0.20 (2022-02-10)
251
+ -----------------
252
+
253
+ - Modified `memory` to return more useful information.
254
+ [sgeulette]
255
+
256
+ 0.19 (2022-01-21)
257
+ -----------------
258
+
259
+ - Added `process_memory` to return current process memory.
260
+ [sgeulette]
261
+ - Added `memory` to return RAM information.
262
+ [sgeulette]
263
+
264
+ 0.18 (2022-01-12)
265
+ -----------------
266
+
267
+ - Made `insert_in_ordereddict` python3 compatible.
268
+ [sgeulette]
269
+ - Added `odict_pos_key` to get key at position in ordereddict.
270
+ [sgeulette]
271
+
272
+ 0.17 (2022-01-04)
273
+ -----------------
274
+
275
+ - Added `timed` and `ftimed` functions.
276
+ [sgeulette]
277
+ - Added OrderedDict for load_var function
278
+ [sgeulette]
279
+
280
+ 0.16 (2021-10-27)
281
+ -----------------
282
+
283
+ - Added `iterable_as_list_of_list` function.
284
+ [sgeulette]
285
+ - Added date in runCommand output
286
+ [sgeulette]
287
+
288
+ 0.15 (2021-04-27)
289
+ -----------------
290
+
291
+ - Added `ln_key` parameter in `read_dictcsv` method.
292
+ [sgeulette]
293
+
294
+ 0.14 (2021-04-21)
295
+ -----------------
296
+
297
+ - Added `read_dictcsv` function.
298
+ [sgeulette]
299
+ - Added `utils.replace_in_list` function to ease replacement of values in a list.
300
+ [gbastien]
301
+ - Added `safe_encode` function.
302
+ [sgeulette]
303
+
304
+ 0.13 (2020-10-07)
305
+ -----------------
306
+
307
+ - Added `insert_in_ordereddict` function to easier insert a new key at needed position.
308
+ [sgeulette]
309
+
310
+ 0.12 (2020-05-19)
311
+ -----------------
312
+
313
+ - Update syntax for py 3.
314
+ [odelaere]
315
+
316
+ 0.11 (2018-10-12)
317
+ -----------------
318
+
319
+ - Added warning log level function
320
+ [odelaere]
321
+
322
+ 0.10 (2018-07-23)
323
+ -----------------
324
+
325
+ - Added to_skip parameter in read_dir functions.
326
+ [sgeulette]
327
+
328
+ 0.9 (2017-07-28)
329
+ ----------------
330
+
331
+ - Added read_csv function.
332
+ [sgeulette]
333
+
334
+ 0.8 (2017-07-19)
335
+ ----------------
336
+
337
+ - runCommand can append to file.
338
+ [sgeulette]
339
+
340
+ 0.7 (2017-06-26)
341
+ ----------------
342
+
343
+ - Just release on pypi for collective.documentgenerator.
344
+ [sgeulette]
345
+
346
+ 0.6 (2017-02-08)
347
+ ----------------
348
+
349
+ - runCommand: return as third value the return code of the command.
350
+ [sgeulette]
351
+
352
+ 0.5 (2017-02-08)
353
+ ----------------
354
+
355
+ - Added outfile parameter to runCommand.
356
+ [sgeulette]
357
+
358
+ 0.4 (2016-12-07)
359
+ ----------------
360
+
361
+ - Added param to get only files in dir.
362
+ [sgeulette]
363
+ - Added methods for bs4 (beautifulsoup)
364
+ [sgeulette]
365
+
366
+ 0.3 (2016-09-21)
367
+ ----------------
368
+
369
+ - Return empty list when file doesn't exist.
370
+ [sgeulette]
371
+
372
+ 0.2 (2016-04-15)
373
+ ----------------
374
+
375
+ - Added options on read_file.
376
+ [sgeulette]
377
+
378
+ 0.1 (2015-06-03)
379
+ ----------------
380
+
381
+ - Initial release.
382
+ [sgeulette]
383
+
384
+ Keywords: Python IMIO
385
+ Platform: UNKNOWN
386
+ Classifier: Development Status :: 5 - Production/Stable
387
+ Classifier: License :: OSI Approved :: GNU General Public License (GPL)
388
+ Classifier: Operating System :: OS Independent
389
+ Classifier: Programming Language :: Python
390
+ Classifier: Programming Language :: Python :: 2.7
391
+ Classifier: Programming Language :: Python :: 3.10
@@ -6,11 +6,11 @@
6
6
  #
7
7
  from __future__ import print_function
8
8
 
9
- from datetime import datetime
10
9
  from six import ensure_binary
11
10
  from six.moves import cPickle
12
11
  from six.moves import range
13
12
 
13
+ import datetime # do not import datetime datetime because load_var must eval datetime.datetime(2024, 12, 19, 11, 34)
14
14
  import hashlib
15
15
  import os
16
16
  import re
@@ -274,7 +274,7 @@ def runCommand(cmd, outfile=None, append=True):
274
274
  else:
275
275
  return int(match.group(1))
276
276
 
277
- now = datetime.now()
277
+ now = datetime.datetime.now()
278
278
  if outfile:
279
279
  fh = open(outfile, "%s" % (append and "a" or "w"))
280
280
  fh.write("==================== NEW RUN on {} ====================\n".format(now.strftime("%Y%m%d-%H%M")))
@@ -89,6 +89,10 @@ class TestUtils(unittest.TestCase):
89
89
  self.assertListEqual(
90
90
  get_ordinal_clusters([100, 200, 250, 400, 700], as_str=False), [[100, 200], [250], [400], [700]]
91
91
  )
92
+ self.assertEqual(get_ordinal_clusters([]), '')
93
+ self.assertEqual(get_ordinal_clusters([], as_str=False), [])
94
+ self.assertEqual(get_ordinal_clusters(), '')
95
+ self.assertEqual(get_ordinal_clusters(as_str=False), [])
92
96
 
93
97
  def test_insert_in_ordered_dict(self):
94
98
  dic = OrderedDict([("a", 1), ("b", 2)])
@@ -106,14 +106,15 @@ def get_ordinal_clusters(
106
106
 
107
107
  # Initialize the first group
108
108
  clusters = []
109
- current_cluster = [numbers[0]]
110
- for num in numbers[1:]:
111
- if _is_in_cluster(num, current_cluster, offset):
112
- current_cluster.append(num)
113
- else: # we'll start a new cluster
114
- clusters.append(current_cluster)
115
- current_cluster = [num]
116
- clusters.append(current_cluster) # Add the last one
109
+ if numbers:
110
+ current_cluster = [numbers[0]]
111
+ for num in numbers[1:]:
112
+ if _is_in_cluster(num, current_cluster, offset):
113
+ current_cluster.append(num)
114
+ else: # we'll start a new cluster
115
+ clusters.append(current_cluster)
116
+ current_cluster = [num]
117
+ clusters.append(current_cluster) # Add the last one
117
118
 
118
119
  if not as_str:
119
120
  return clusters