hygeos-core 1.3.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.
Files changed (62) hide show
  1. hygeos_core-1.3.2/LICENSE +202 -0
  2. hygeos_core-1.3.2/NOTICE +13 -0
  3. hygeos_core-1.3.2/PKG-INFO +23 -0
  4. hygeos_core-1.3.2/core/__init__.py +8 -0
  5. hygeos_core-1.3.2/core/ascii_table.py +268 -0
  6. hygeos_core-1.3.2/core/auth.py +4 -0
  7. hygeos_core-1.3.2/core/cache.py +10 -0
  8. hygeos_core-1.3.2/core/condor.py +9 -0
  9. hygeos_core-1.3.2/core/config.py +131 -0
  10. hygeos_core-1.3.2/core/conftest.py +4 -0
  11. hygeos_core-1.3.2/core/dates.py +71 -0
  12. hygeos_core-1.3.2/core/deptree.py +4 -0
  13. hygeos_core-1.3.2/core/deptree_prefect.py +4 -0
  14. hygeos_core-1.3.2/core/download.py +4 -0
  15. hygeos_core-1.3.2/core/env.py +194 -0
  16. hygeos_core-1.3.2/core/files/__init__.py +5 -0
  17. hygeos_core-1.3.2/core/files/cache.py +334 -0
  18. hygeos_core-1.3.2/core/files/fileutils.py +392 -0
  19. hygeos_core-1.3.2/core/files/lock.py +50 -0
  20. hygeos_core-1.3.2/core/files/save.py +100 -0
  21. hygeos_core-1.3.2/core/files/uncompress.py +268 -0
  22. hygeos_core-1.3.2/core/fileutils.py +11 -0
  23. hygeos_core-1.3.2/core/ftp.py +12 -0
  24. hygeos_core-1.3.2/core/fuzzy.py +61 -0
  25. hygeos_core-1.3.2/core/geo/__init__.py +3 -0
  26. hygeos_core-1.3.2/core/geo/convert.py +36 -0
  27. hygeos_core-1.3.2/core/geo/naming.py +56 -0
  28. hygeos_core-1.3.2/core/geo/patterns.csv +30 -0
  29. hygeos_core-1.3.2/core/geo/product_name.py +132 -0
  30. hygeos_core-1.3.2/core/import_utils.py +21 -0
  31. hygeos_core-1.3.2/core/interpolate.py +1058 -0
  32. hygeos_core-1.3.2/core/lock.py +4 -0
  33. hygeos_core-1.3.2/core/log.py +279 -0
  34. hygeos_core-1.3.2/core/masks.py +42 -0
  35. hygeos_core-1.3.2/core/monitor.py +370 -0
  36. hygeos_core-1.3.2/core/network/auth.py +32 -0
  37. hygeos_core-1.3.2/core/network/download.py +63 -0
  38. hygeos_core-1.3.2/core/network/ftp.py +182 -0
  39. hygeos_core-1.3.2/core/process/blockwise.py +918 -0
  40. hygeos_core-1.3.2/core/process/condor.py +73 -0
  41. hygeos_core-1.3.2/core/process/deptree.py +604 -0
  42. hygeos_core-1.3.2/core/process/deptree_prefect.py +134 -0
  43. hygeos_core-1.3.2/core/progressbar.py +387 -0
  44. hygeos_core-1.3.2/core/pseudoinverse.py +40 -0
  45. hygeos_core-1.3.2/core/pytest_utils.py +5 -0
  46. hygeos_core-1.3.2/core/save.py +4 -0
  47. hygeos_core-1.3.2/core/static/Exceptions.py +11 -0
  48. hygeos_core-1.3.2/core/static/__init__.py +6 -0
  49. hygeos_core-1.3.2/core/static/abstract.py +74 -0
  50. hygeos_core-1.3.2/core/static/constraint.py +146 -0
  51. hygeos_core-1.3.2/core/static/interface.py +183 -0
  52. hygeos_core-1.3.2/core/static/parametrized.py +9 -0
  53. hygeos_core-1.3.2/core/static/singleton.py +42 -0
  54. hygeos_core-1.3.2/core/static/virtual.py +6 -0
  55. hygeos_core-1.3.2/core/table.py +129 -0
  56. hygeos_core-1.3.2/core/tests/conftest.py +355 -0
  57. hygeos_core-1.3.2/core/tests/graphics.py +194 -0
  58. hygeos_core-1.3.2/core/tests/pytest_utils.py +16 -0
  59. hygeos_core-1.3.2/core/tools.py +1274 -0
  60. hygeos_core-1.3.2/core/uncompress.py +4 -0
  61. hygeos_core-1.3.2/core/xrtags.py +62 -0
  62. hygeos_core-1.3.2/pyproject.toml +53 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,13 @@
1
+ Copyright 2024 Hygeos
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,23 @@
1
+ Metadata-Version: 2.4
2
+ Name: hygeos-core
3
+ Version: 1.3.2
4
+ Summary: Common Operations for Robust Engineering
5
+ License-File: LICENSE
6
+ License-File: NOTICE
7
+ Author: François Steinmetz
8
+ Author-email: fs@hygeos.com
9
+ Requires-Python: >=3.10
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Requires-Dist: dask
17
+ Requires-Dist: h5netcdf
18
+ Requires-Dist: lxml
19
+ Requires-Dist: python-dotenv
20
+ Requires-Dist: scipy
21
+ Requires-Dist: toml
22
+ Requires-Dist: tqdm
23
+ Requires-Dist: xarray
@@ -0,0 +1,8 @@
1
+ """
2
+ Common Operations for Robust Engineering
3
+
4
+ A collection of common procedures for generic programming purposes
5
+ """
6
+ from core.files.fileutils import filegen, mdir
7
+ from core.files.save import to_netcdf
8
+ from core.log import rgb
@@ -0,0 +1,268 @@
1
+ import time
2
+ from typing import Literal
3
+
4
+
5
+ class ascii_table:
6
+
7
+ """
8
+ A class to represent a table for displaying data in a formatted way.
9
+ """
10
+
11
+ class style:
12
+ """
13
+ A class to define the style of a table using specific characters.
14
+ """
15
+ def __init__(self,
16
+ inner_vbar = True,
17
+ inner_hbar = False,
18
+ h_padding = 1,
19
+ v_padding = 0,
20
+ style: Literal["squared", "rounded", "simple", "double"] = "squared",
21
+ ):
22
+
23
+ styles = dict(
24
+ squared = "─│┌┐└┘├┤┬┴┼",
25
+ rounded = "─│╭╮╰╯├┤┬┴┼",
26
+ simple = "-|+++++++++",
27
+ double = "═║╔╗╚╝╠╣╦╩╬",
28
+ )
29
+
30
+ self.style = styles[style]
31
+
32
+ self.inner_vbar = inner_vbar
33
+ self.inner_hbar = inner_hbar
34
+ self.h_padding = h_padding
35
+ self.v_padding = v_padding
36
+
37
+ # internal config
38
+ self.h = self.style[0] # horizontal char
39
+ self.v = self.style[1] # vertical char
40
+ self.tl = self.style[2] # corner top left
41
+ self.tr = self.style[3] # corner top right
42
+ self.bl = self.style[4] # corner bot left
43
+ self.br = self.style[5] # corner bot right
44
+ self.ml = self.style[6] # mid left
45
+ self.mr = self.style[7] # mid right
46
+ self.mt = self.style[8] # mid top
47
+ self.mb = self.style[9] # mid bot
48
+ self.cr = self.style[10] # cross
49
+
50
+ self.live_print_target_time = 0.100 # s
51
+
52
+ def __init__(self, df, style=style(), colors={}, sides={}, max_width: int|None=35):
53
+ """
54
+ Ascii table constructor
55
+ df: source table, pd.DataFrame
56
+ style: allows to override the styling of the table
57
+ colors: is a dictionnary of core.log.rgb colors like {column: rgb.green}
58
+
59
+ Basic usage:
60
+ ascii_table(res).print()
61
+ """
62
+ self.df = df
63
+ self._style = style
64
+
65
+ df_str = df.astype(str)
66
+ self.columns: list[str] = df_str.columns
67
+ self.spaces: list[int] = df_str[self.columns].apply(
68
+ lambda col: max(len(col.name), col.str.len().max())
69
+ ).tolist()
70
+
71
+ # NOTE: could use interactive / dynamic ranges, more complex tough
72
+ # self.terminal = shutil.get_terminal_size()
73
+
74
+ # lowercase the columns keys
75
+ colors = {k.lower(): v for k, v in colors.items()}
76
+ sides = {k.lower(): v for k, v in sides.items()}
77
+
78
+
79
+ for c in self.columns:
80
+ if c.lower() not in colors: # no colors by default
81
+ colors[c.lower()] = None
82
+
83
+ if c.lower() not in sides: # left side by default
84
+ sides[c.lower()] = "left"
85
+
86
+ self.colors = [colors[i.lower()] for i in self.columns]
87
+ self.sides = [sides[i.lower()] for i in self.columns]
88
+
89
+ # limiting column max width
90
+ self.max_width = max_width
91
+ if max_width is not None:
92
+ for i, v in enumerate(self.spaces):
93
+ if v > max_width:
94
+ self.spaces[i] = max_width
95
+
96
+
97
+
98
+ def print(self, live_print=False, no_color=False):
99
+ s = self.to_string(live_print, no_color)
100
+ print(s)
101
+
102
+
103
+ def to_string(self, live_print=False, no_color=True):
104
+ """
105
+ Generates an ascii representation of the dataset provided in the constructor.
106
+ """
107
+
108
+ # NOTE: does not (yet) handle line reduction with ellipsis
109
+ # ellipsis_char = "‥" # "…" # two dots variants seems more readable
110
+ # width_footprint = sum(self.widths) + 3*len(self.widths) + 1
111
+ # width_overshoot = width_footprint - self.terminal.columns
112
+
113
+ # config
114
+ ivb = self._style.inner_vbar
115
+ ihb = self._style.inner_hbar
116
+ hp = self._style.h_padding
117
+ vp = self._style.v_padding
118
+
119
+ # style characters
120
+ h = self._style.h # horizontal
121
+ v = self._style.v # vertical
122
+ tl = self._style.tl # top left corner
123
+ tr = self._style.tr # top right corner
124
+ bl = self._style.bl # bottom left
125
+ br = self._style.br # bottom right
126
+ mr = self._style.mr # mid right
127
+ mt = self._style.mt # mid top
128
+ ml = self._style.ml # mid left
129
+ mb = self._style.mb # mid bottom
130
+ cr = self._style.cr # cross
131
+
132
+ max_width = self.max_width
133
+
134
+ spaces = self.spaces.copy()
135
+ colors = self.colors.copy()
136
+ sides = self.sides.copy()
137
+
138
+ # Precompute common strings
139
+ hhp = h * hp
140
+ shp = ' ' * hp
141
+ h_line = h * (hp * 2 + 1) # For cases without inner bars
142
+
143
+ def _line_separator(pos):
144
+ """
145
+ Generates an ascii separator line for the table based on position.
146
+ """
147
+
148
+ if pos == "mid":
149
+
150
+ ivbc = cr if ivb else h # cross if inner vertical bars, line otherwise
151
+ sep = hhp + ivbc + hhp # construct mid separator (not on the outer side)
152
+ if not ivb: sep = hhp # if no vertical bar, reduce padding
153
+
154
+ mids = [h*w for w in spaces]
155
+ line = ml + hhp + sep.join(mids) + hhp + mr
156
+ return line
157
+
158
+ if pos == "top":
159
+
160
+ ivbc = mt if ivb else h
161
+ sep = hhp + ivbc + hhp
162
+ if not ivb: sep = hhp
163
+
164
+ mids = [h*w for w in spaces]
165
+ line = tl + hhp + sep.join(mids) + hhp + tr
166
+ return line
167
+
168
+ if pos == "bot":
169
+
170
+ ivbc = mb if ivb else h
171
+ sep = hhp + ivbc + hhp
172
+ if not ivb: sep = hhp
173
+
174
+ mids = [h*w for w in spaces]
175
+ line = bl + hhp + sep.join(mids) + hhp + br
176
+ return line
177
+
178
+
179
+ def _line_padding():
180
+ """
181
+ Generates an ascii padding line for the table.
182
+ """
183
+
184
+ ivbc = v if ivb else h
185
+ sep = shp + ivbc + shp
186
+ if not ihb: sep = shp
187
+
188
+ mids = [" "*w for w in spaces]
189
+ line = ml + shp + sep.join(mids) + shp + mr
190
+ return line
191
+
192
+
193
+ def _color_str(s, i):
194
+ c = colors[i]
195
+
196
+ if c is not None:
197
+ return c(s)
198
+ return s
199
+
200
+ def _format_str(s):
201
+
202
+ l = max_width
203
+ if len(s) > l:
204
+ s = s[:l-1] + "‥"
205
+ return s
206
+
207
+
208
+ # disable for performance reason
209
+ if not max_width:
210
+ _format_str = lambda x: x
211
+
212
+ # disable colors
213
+ if no_color:
214
+ _color_str = lambda x, y: x
215
+
216
+ def _line_content(line):
217
+ """
218
+ Generates an ascii content line for the table.
219
+ """
220
+
221
+ ivbc = v if ivb else h
222
+ sep = shp + ivbc + shp
223
+ if not ivb: sep = shp
224
+
225
+ def align_text(text, width, side):
226
+ return text.ljust(width) if side == "left" else text.rjust(width)
227
+
228
+ mids = [
229
+ _color_str(align_text(_format_str(str(w)), spaces[i], sides[i]), i)
230
+ for i, w in enumerate(line)
231
+ ]
232
+ line = v + shp + sep.join(mids) + shp + v
233
+ return line
234
+
235
+
236
+ """
237
+ Main routine using the previous subroutines
238
+ Iterates over each lines of the dataframe and builds the ascii representation
239
+ """
240
+
241
+ entries = self.df[self.columns].values
242
+ lines = []
243
+
244
+ headers = [s.capitalize() for s in self.columns]
245
+
246
+
247
+ itr = self._style.live_print_target_time / len(self.df)
248
+ itr = min(itr, 0.015)
249
+ fn = lines.append if not live_print else lambda x: (time.sleep(itr), print(x, flush=True))
250
+
251
+ fn("")
252
+ fn(_line_separator("top" ))
253
+ fn(_line_content(headers))
254
+ fn(_line_separator("mid" ))
255
+ for j, e in enumerate(entries):
256
+
257
+ for i in range(vp): fn(_line_padding("mid"))
258
+ fn(_line_content(e))
259
+ for i in range(vp): fn(_line_padding("mid"))
260
+ if ihb:
261
+ fn(_line_separator("mid"))
262
+
263
+ fn(_line_separator("bot"))
264
+ fn("")
265
+
266
+ if not live_print:
267
+ message = "\n".join(lines)
268
+ return message
@@ -0,0 +1,4 @@
1
+ import warnings
2
+ from core.network.auth import get_auth, get_auth_dhus
3
+
4
+ warnings.warn("Please import from core.network.auth", DeprecationWarning)
@@ -0,0 +1,10 @@
1
+ import warnings
2
+ from core.files.cache import (
3
+ cache_dataframe,
4
+ cache_json,
5
+ cache_pickle,
6
+ cache_dataset,
7
+ cachefunc,
8
+ )
9
+
10
+ warnings.warn("Please import from core.files.cache", DeprecationWarning)
@@ -0,0 +1,9 @@
1
+ import warnings
2
+ from core.process.condor import (
3
+ get_htcondor_logdir,
4
+ get_htcondor_params,
5
+ get_htcondor_runner,
6
+ get_htcondor_client,
7
+ )
8
+
9
+ warnings.warn("Please import from core.process.condor", DeprecationWarning)
@@ -0,0 +1,131 @@
1
+ from pathlib import Path
2
+ from typing import Optional, Any
3
+ from copy import deepcopy
4
+ import toml
5
+
6
+ from core.static import constraint
7
+ from core.static import interface
8
+ from core import log
9
+
10
+ from warnings import warn
11
+
12
+ warn('core.config will be deprecated.', DeprecationWarning)
13
+
14
+ """
15
+ Generic project configuration module.
16
+ Simpler version of core.config module, more generic
17
+ Config path need to be passed as argument
18
+ """
19
+
20
+ class Config:
21
+
22
+ @interface
23
+ def new_from_toml(config_path: Path, allow_empty_if_no_file: bool = False):
24
+
25
+ file_found = config_path.is_file() and config_path.name.endswith(".toml")
26
+
27
+ if not file_found and not allow_empty_if_no_file:
28
+ raise RuntimeError(f"Invalid config file path {config_path}")
29
+
30
+ configuration = {} if not file_found else toml.load(config_path)
31
+
32
+ return Config(configuration)
33
+
34
+ @interface
35
+ def new_from_dict(config_dict: dict):
36
+ return Config(config_dict)
37
+
38
+ @interface
39
+ def copy(self):
40
+ return Config(deepcopy(self.config_dict))
41
+
42
+ @interface
43
+ def __init__(self, config_dict: dict):
44
+ self.config_dict: dict = config_dict
45
+
46
+ @interface
47
+ def get_subsection(self, subsection: str=None, default:dict=None) -> dict:
48
+ """
49
+ Returns the specified toml subsection
50
+ returns the root if None provided
51
+ """
52
+ config_ptr = self.config_dict # get config content
53
+
54
+ # Section or nested subsection
55
+ if subsection is not None:
56
+ sections = subsection.split('.')
57
+
58
+ # find subsection
59
+ for sub in sections:
60
+ if sub in config_ptr:
61
+ config_ptr = config_ptr[sub]
62
+ else:
63
+ if default is not None:
64
+ return default
65
+ raise KeyError(f"Missing section [{subsection}] in config file")
66
+ return config_ptr
67
+
68
+
69
+ @interface
70
+ def ingest(self, config_dict, override=True):
71
+ """
72
+ Ingest a configuration, if override is true then doubled keys are overriden by new config
73
+ otherwise only add missing keys from new config
74
+ keeping the keys defined in configuration and not overriden by itself.
75
+ """
76
+
77
+ if isinstance(config_dict, dict): # already a dict
78
+ pass
79
+ elif isinstance(config_dict, Config):
80
+ config_dict = config_dict.config_dict
81
+ else:
82
+ log.error(f"Unexpected argument type \'{type(config_dict)}\', expected dict or Config object", e=ValueError)
83
+
84
+ for k, v in config_dict.items(): # iterate provided defaults keys, vals
85
+ if k in self.config_dict: # if the key is not already defined
86
+ if not override:
87
+ continue
88
+ self.config_dict[k] = v
89
+
90
+
91
+ @interface
92
+ def get(
93
+ self,
94
+ key: str,
95
+ subsection: str = None,
96
+ *,
97
+ default=None,
98
+ ) -> Any:
99
+ """
100
+ Returns the key if present in the config file.
101
+ If not present and no default provided: raises an error
102
+ if default is provided (different than None): return default instead
103
+
104
+ auto cast values to Path objects if its key starts with 'dir_' and its type is str
105
+ """
106
+
107
+ config_dict_ptr = self.get_subsection(subsection=subsection)
108
+
109
+ # key managing
110
+ if key not in config_dict_ptr:
111
+ if default is not None:
112
+ return default
113
+ else:
114
+ mess = "root section" if subsection is None else f"section [{subsection}]"
115
+ raise KeyError( f"Missing key \'{key}\' in {mess} of in config file")
116
+
117
+ # get value
118
+ value = config_dict_ptr[key]
119
+
120
+ # auto convert value to path if its key starts with 'dir_'
121
+ if type(value) is str and key.startswith("dir_"):
122
+ value = Path(value)
123
+
124
+ return value
125
+
126
+ def __str__(self):
127
+ return str(self.config_dict)
128
+
129
+ @interface
130
+ def __getitem__(self, key: str, subsection=None):
131
+ return self.get(key=key, subsection=subsection)
@@ -0,0 +1,4 @@
1
+ import warnings
2
+ from core.tests.conftest import *
3
+
4
+ warnings.warn("Please import from core.tests.conftest", DeprecationWarning)