anemoi-utils 0.4.26__py3-none-any.whl → 0.4.27__py3-none-any.whl

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

Potentially problematic release.


This version of anemoi-utils might be problematic. Click here for more details.

anemoi/utils/_version.py CHANGED
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '0.4.26'
21
- __version_tuple__ = version_tuple = (0, 4, 26)
20
+ __version__ = version = '0.4.27'
21
+ __version_tuple__ = version_tuple = (0, 4, 27)
anemoi/utils/remote/s3.py CHANGED
@@ -47,8 +47,8 @@ SECRETS = ["aws_access_key_id", "aws_secret_access_key"]
47
47
  thread_local = threading.local()
48
48
 
49
49
 
50
- def s3_client(bucket: str, *, region: str = None, service: str = "s3") -> Any:
51
- """Get an S3 client for the specified bucket and region.
50
+ def _s3_config(bucket: str, *, region: str = None) -> Any:
51
+ """Get an S3 client config for the specified bucket and region.
52
52
 
53
53
  Parameters
54
54
  ----------
@@ -56,31 +56,15 @@ def s3_client(bucket: str, *, region: str = None, service: str = "s3") -> Any:
56
56
  The name of the S3 bucket.
57
57
  region : str, optional
58
58
  The AWS region of the S3 bucket.
59
- service : str, optional
60
- The AWS service to use, default is "s3".
61
59
 
62
60
  Returns
63
61
  -------
64
62
  Any
65
63
  The S3 client.
66
64
  """
67
- import boto3
68
65
  from botocore import UNSIGNED
69
- from botocore.client import Config
70
66
 
71
- if not hasattr(thread_local, "s3_clients"):
72
- thread_local.s3_clients = {}
73
-
74
- key = f"{bucket}-{region}-{service}"
75
-
76
- if key in thread_local.s3_clients:
77
- return thread_local.s3_clients[key]
78
-
79
- boto3_config = dict(
80
- max_pool_connections=25,
81
- request_checksum_calculation="when_required",
82
- response_checksum_validation="when_required",
83
- )
67
+ boto3_config = {}
84
68
 
85
69
  if region:
86
70
  # This is using AWS
@@ -129,6 +113,85 @@ def s3_client(bucket: str, *, region: str = None, service: str = "s3") -> Any:
129
113
  boto3_config.update(options["config"])
130
114
  del options["config"]
131
115
 
116
+ def _(options):
117
+
118
+ def __(k, v):
119
+ if k in SECRETS:
120
+ return "***"
121
+ return v
122
+
123
+ if isinstance(options, dict):
124
+ return {k: __(k, v) for k, v in options.items()}
125
+
126
+ if isinstance(options, list):
127
+ return [_(o) for o in options]
128
+
129
+ return options
130
+
131
+ LOG.debug(f"Using S3 options: {_(options)}")
132
+
133
+ return boto3_config, options
134
+
135
+
136
+ def s3_options(bucket: str, *, region: str = None, service: str = "s3") -> dict:
137
+ """Get the S3 configuration for the specified bucket and region.
138
+
139
+ Parameters
140
+ ----------
141
+ bucket : str
142
+ The name of the S3 bucket.
143
+ region : str, optional
144
+ The AWS region of the S3 bucket.
145
+ service : str, optional
146
+ The AWS service to use, default is "s3".
147
+
148
+ Returns
149
+ -------
150
+ dict
151
+ The S3 configuration.
152
+ """
153
+ _, options = _s3_config(bucket, region=region)
154
+ return options
155
+
156
+
157
+ def s3_client(bucket: str, *, region: str = None, service: str = "s3") -> Any:
158
+ """Get an S3 client for the specified bucket and region.
159
+
160
+ Parameters
161
+ ----------
162
+ bucket : str
163
+ The name of the S3 bucket.
164
+ region : str, optional
165
+ The AWS region of the S3 bucket.
166
+ service : str, optional
167
+ The AWS service to use, default is "s3".
168
+
169
+ Returns
170
+ -------
171
+ Any
172
+ The S3 client.
173
+ """
174
+ import boto3
175
+ from botocore.client import Config
176
+
177
+ if not hasattr(thread_local, "s3_clients"):
178
+ thread_local.s3_clients = {}
179
+
180
+ key = f"{bucket}-{region}-{service}"
181
+
182
+ if key in thread_local.s3_clients:
183
+ return thread_local.s3_clients[key]
184
+
185
+ boto3_config, options = _s3_config(bucket, region=region)
186
+
187
+ boto3_config.update(
188
+ dict(
189
+ max_pool_connections=25,
190
+ request_checksum_calculation="when_required",
191
+ response_checksum_validation="when_required",
192
+ )
193
+ )
194
+
132
195
  options["config"] = Config(**boto3_config)
133
196
 
134
197
  def _(options):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: anemoi-utils
3
- Version: 0.4.26
3
+ Version: 0.4.27
4
4
  Summary: A package to hold various functions to support training of ML models on ECMWF data.
5
5
  Author-email: "European Centre for Medium-Range Weather Forecasts (ECMWF)" <software.support@ecmwf.int>
6
6
  License: Apache License
@@ -1,6 +1,6 @@
1
1
  anemoi/utils/__init__.py,sha256=uVhpF-VjIl_4mMywOVtgTutgsdIsqz-xdkwxeMhzuag,730
2
2
  anemoi/utils/__main__.py,sha256=6LlE4MYrPvqqrykxXh7XMi50UZteUY59NeM8P9Zs2dU,910
3
- anemoi/utils/_version.py,sha256=ggjVlIoxYrdpYCbFUc7ixm914S2kJVBvieeqeCBnvjY,513
3
+ anemoi/utils/_version.py,sha256=l2RpdEWLXHjIi56KlS-u-66k8wBi9yvFH_NPLD7QkmQ,513
4
4
  anemoi/utils/caching.py,sha256=rXbeAmpBcMbbfN4EVblaHWKicsrtx1otER84FEBtz98,6183
5
5
  anemoi/utils/checkpoints.py,sha256=PydBqA-wI8_05zU-3yT-ZP53GnvuqB7vPXl-w6-9XX8,9541
6
6
  anemoi/utils/cli.py,sha256=Cd3ESQkNWecbGnJjkR_SKHdFPETJWFrHqg5ovtANDKs,6522
@@ -31,13 +31,13 @@ anemoi/utils/mars/__init__.py,sha256=b-Lc3L1TAQd9ODs0Z1YSJzgZCO1K_M3DSgx_yd2qXvM
31
31
  anemoi/utils/mars/mars.yaml,sha256=R0dujp75lLA4wCWhPeOQnzJ45WZAYLT8gpx509cBFlc,66
32
32
  anemoi/utils/mars/requests.py,sha256=VFMHBVAAl0_2lOcMBa1lvaKHctN0lDJsI6_U4BucGew,1142
33
33
  anemoi/utils/remote/__init__.py,sha256=7nHu-LRspYW2Fx9GNLjsxpytAUIvhIbOjb0Xmxb-33s,20988
34
- anemoi/utils/remote/s3.py,sha256=VgxNuJpJBnfxwkkV9TyrSkf7fjIuHqy1YG9vRdj9QRc,19978
34
+ anemoi/utils/remote/s3.py,sha256=DxO_TjmetX_r3ZvGaHjpz40oqvcQYP3Vd_A4ojMGlSA,21379
35
35
  anemoi/utils/remote/ssh.py,sha256=xNtsawh8okytCKRehkRCVExbHZj-CRUQNormEHglfuw,8088
36
36
  anemoi/utils/schemas/__init__.py,sha256=nkinKlsPLPXEjfTYQT1mpKC4cvs-14w_zBkDRxakwxw,698
37
37
  anemoi/utils/schemas/errors.py,sha256=lgOXzVTYzAE0qWQf3OZ42vCWixv8lilSqLLhzARBmvI,1831
38
- anemoi_utils-0.4.26.dist-info/licenses/LICENSE,sha256=8HznKF1Vi2IvfLsKNE5A2iVyiri3pRjRPvPC9kxs6qk,11354
39
- anemoi_utils-0.4.26.dist-info/METADATA,sha256=tx5q6lKfqmvh5eq9ty0Pw1e8LtzX4wysYzm_lVNeIQQ,15486
40
- anemoi_utils-0.4.26.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
41
- anemoi_utils-0.4.26.dist-info/entry_points.txt,sha256=LENOkn88xzFQo-V59AKoA_F_cfYQTJYtrNTtf37YgHY,60
42
- anemoi_utils-0.4.26.dist-info/top_level.txt,sha256=DYn8VPs-fNwr7fNH9XIBqeXIwiYYd2E2k5-dUFFqUz0,7
43
- anemoi_utils-0.4.26.dist-info/RECORD,,
38
+ anemoi_utils-0.4.27.dist-info/licenses/LICENSE,sha256=8HznKF1Vi2IvfLsKNE5A2iVyiri3pRjRPvPC9kxs6qk,11354
39
+ anemoi_utils-0.4.27.dist-info/METADATA,sha256=zqysYlsP5gsTcGN93z7KW5rSIehOpVjg85arxug6MZE,15486
40
+ anemoi_utils-0.4.27.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
41
+ anemoi_utils-0.4.27.dist-info/entry_points.txt,sha256=LENOkn88xzFQo-V59AKoA_F_cfYQTJYtrNTtf37YgHY,60
42
+ anemoi_utils-0.4.27.dist-info/top_level.txt,sha256=DYn8VPs-fNwr7fNH9XIBqeXIwiYYd2E2k5-dUFFqUz0,7
43
+ anemoi_utils-0.4.27.dist-info/RECORD,,