lsst-resources 29.0.0rc7__py3-none-any.whl → 29.2025.4600__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.
lsst/resources/utils.py CHANGED
@@ -11,16 +11,18 @@
11
11
 
12
12
  from __future__ import annotations
13
13
 
14
- __all__ = ("NoTransaction", "TransactionProtocol", "os2posix", "posix2os")
14
+ __all__ = ("NoTransaction", "TransactionProtocol", "get_tempdir", "os2posix", "posix2os")
15
15
 
16
16
  import contextlib
17
17
  import logging
18
+ import multiprocessing
18
19
  import os
19
20
  import posixpath
20
21
  import shutil
21
22
  import stat
22
23
  import tempfile
23
24
  from collections.abc import Callable, Iterator
25
+ from functools import cache
24
26
  from pathlib import Path, PurePath, PurePosixPath
25
27
  from typing import Any, Protocol
26
28
 
@@ -32,6 +34,11 @@ IS_POSIX = os.sep == posixpath.sep
32
34
  # posix means posix and only determine explicitly in the non-posix case.
33
35
  OS_ROOT_PATH = posixpath.sep if IS_POSIX else Path().resolve().root
34
36
 
37
+ # Maximum number of worker threads for parallelized operations.
38
+ # If greater than 10, be aware that this number has to be consistent
39
+ # with connection pool sizing (for example in urllib3).
40
+ MAX_WORKERS = 10
41
+
35
42
  log = logging.getLogger(__name__)
36
43
 
37
44
 
@@ -93,6 +100,35 @@ def posix2os(posix: PurePath | str) -> str:
93
100
  return os.path.join(*paths)
94
101
 
95
102
 
103
+ @cache
104
+ def get_tempdir() -> str:
105
+ """Get POSIX path to temporary directory.
106
+
107
+ Returns
108
+ -------
109
+ tmpdir : `str`
110
+ Path to the default temporary directory location.
111
+
112
+ Notes
113
+ -----
114
+ Uses the value of environment variables ``LSST_RESOURCES_TMPDIR`` or
115
+ ``TMPDIR``, if defined. Otherwise use the system temporary directory,
116
+ with a last-resort fallback to the current working directory if
117
+ nothing else is available.
118
+ """
119
+ tmpdir = None
120
+ # $TMPDIR is also checked with getttempdir() below.
121
+ for dir in (os.getenv(v) for v in ("LSST_RESOURCES_TMPDIR", "TMPDIR")):
122
+ if dir and os.path.isdir(dir):
123
+ tmpdir = dir
124
+ break
125
+
126
+ if tmpdir is None:
127
+ tmpdir = tempfile.gettempdir()
128
+
129
+ return tmpdir
130
+
131
+
96
132
  class NoTransaction:
97
133
  """A simple emulation of the
98
134
  `~lsst.daf.butler.core.datastore.DatastoreTransaction` class.
@@ -196,3 +232,40 @@ def ensure_directory_is_writeable(directory_path: str | bytes) -> None:
196
232
  desired_mode = current_mode | stat.S_IWUSR | stat.S_IXUSR
197
233
  if current_mode != desired_mode:
198
234
  os.chmod(directory_path, desired_mode)
235
+
236
+
237
+ def _get_int_env_var(env_var: str) -> int | None:
238
+ int_value = None
239
+ env_value = os.getenv(env_var)
240
+ if env_value is not None:
241
+ with contextlib.suppress(TypeError):
242
+ int_value = int(env_value)
243
+ return int_value
244
+
245
+
246
+ @cache
247
+ def _get_num_workers() -> int:
248
+ f"""Calculate the number of workers to use.
249
+
250
+ Returns
251
+ -------
252
+ num : `int`
253
+ The number of workers to use. Will use the value of the
254
+ ``LSST_RESOURCES_NUM_WORKERS`` environment variable if set. Will fall
255
+ back to using the CPU count (plus 2) but capped at {MAX_WORKERS}.
256
+ """
257
+ num_workers: int | None = None
258
+ num_workers = _get_int_env_var("LSST_RESOURCES_NUM_WORKERS")
259
+
260
+ # If someone is explicitly specifying a number, let them use that number.
261
+ if num_workers is not None:
262
+ return num_workers
263
+
264
+ if num_workers is None:
265
+ # CPU_LIMIT is used on nublado.
266
+ cpu_limit = _get_int_env_var("CPU_LIMIT") or multiprocessing.cpu_count()
267
+ if cpu_limit is not None:
268
+ num_workers = cpu_limit + 2
269
+
270
+ # But don't ever return more than the maximum allowed.
271
+ return min([num_workers, MAX_WORKERS])
lsst/resources/version.py CHANGED
@@ -1,2 +1,2 @@
1
1
  __all__ = ["__version__"]
2
- __version__ = "29.0.0rc7"
2
+ __version__ = "29.2025.4600"
@@ -1,17 +1,17 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lsst-resources
3
- Version: 29.0.0rc7
3
+ Version: 29.2025.4600
4
4
  Summary: An abstraction layer for reading and writing from URI file resources.
5
5
  Author-email: Rubin Observatory Data Management <dm-admin@lists.lsst.org>
6
- License: BSD 3-Clause License
6
+ License-Expression: BSD-3-Clause
7
7
  Project-URL: Homepage, https://github.com/lsst/resources
8
8
  Keywords: lsst
9
9
  Classifier: Intended Audience :: Developers
10
- Classifier: License :: OSI Approved :: BSD License
11
10
  Classifier: Operating System :: OS Independent
12
11
  Classifier: Programming Language :: Python :: 3
13
12
  Classifier: Programming Language :: Python :: 3.11
14
13
  Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
15
  Requires-Python: >=3.11.0
16
16
  Description-Content-Type: text/markdown
17
17
  License-File: COPYRIGHT
@@ -0,0 +1,31 @@
1
+ lsst/__init__.py,sha256=9I6UQ9gj-ZcPlvsa0OPBo76UujxXVehVzw9yMAOQvyM,466
2
+ lsst/resources/__init__.py,sha256=BDj6uokvd0ZQNGl-Xgz5gZd83Z0L2gFqGSk0KJpylP8,778
3
+ lsst/resources/_resourcePath.py,sha256=fnB8XNUfk25lV378U0kg1O6c1QnSJL7F9iqaEt08IOA,74508
4
+ lsst/resources/dav.py,sha256=ZYP7PnQzS7epm5woxnn1_t1XhsPQZm6_q1kv8baUfn4,32100
5
+ lsst/resources/davutils.py,sha256=5geEl_44lrWX-Si1VDfYJ6WP1rg22PBqlyD_v1HE4yI,100300
6
+ lsst/resources/file.py,sha256=v2XLOzflfhI6kjUGB1mE8p-1e1B2eE58PW-qsQSCqdA,24360
7
+ lsst/resources/gs.py,sha256=3qMEqO1wIK05BJmuUHtsEunuYWgR4-eB5Z3ffxEtb0o,12827
8
+ lsst/resources/http.py,sha256=WSx2VXKFd6486TytV2NMfdgLntioL6FvliZWpn9LtDE,92426
9
+ lsst/resources/location.py,sha256=x3Tq0x5o1OXYmZDxYBenUG1N71wtDhnjVAr3s2ZEiu8,7937
10
+ lsst/resources/mem.py,sha256=xCpGgvxF2gmO5gLkOikKvIet2RPvaPCiARenR9pUWCk,1115
11
+ lsst/resources/packageresource.py,sha256=vnfeRlpVwpC5cDQZE6Lnh8EH6oZy1sH2vLz9ONYjJ4k,6817
12
+ lsst/resources/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
+ lsst/resources/s3.py,sha256=NGJPM4BjtqFIPvg9vbp_blrIRt009NbOm06cr65Wqmw,29662
14
+ lsst/resources/s3utils.py,sha256=ojWf9BPrK9mhGQ8jvs4_8Nsqf9360e79U5FnPTxe24A,14576
15
+ lsst/resources/schemeless.py,sha256=9tgqf0eQI3ErGpGSscTRFk_8amF6GwpykPBaTa-KqLI,10909
16
+ lsst/resources/tests.py,sha256=UD2Pql8olpW9oCDlsA_jtl23SZtknp7ReuJHLcMPSa0,46237
17
+ lsst/resources/utils.py,sha256=6O3Mq7JbPEtqyD2lM77pRpwcPMfV5SxiNMknw-F2vNs,8097
18
+ lsst/resources/version.py,sha256=vB8XwkFrtPN40DIouI1mFlxm5jpAZvcGwleFGT1yZhI,55
19
+ lsst/resources/_resourceHandles/__init__.py,sha256=zOcZ8gVEBdAWcHJaZabA8Vdq-wAVcxjbmA_1b1IWM6M,76
20
+ lsst/resources/_resourceHandles/_baseResourceHandle.py,sha256=lQwxDOmFUNJndTxsjpz-HxrQBL0L-z4aXQocHdOEI7c,4676
21
+ lsst/resources/_resourceHandles/_davResourceHandle.py,sha256=xcJNFUj8VzlPOKlHdXXoFFyiLNiSFiT-RFNqJRzKniQ,6799
22
+ lsst/resources/_resourceHandles/_fileResourceHandle.py,sha256=2nC8tfP_ynAfjpzrtkw_1ahx1CuMEFpZ5mLmofSShUk,3676
23
+ lsst/resources/_resourceHandles/_httpResourceHandle.py,sha256=Yami8IVGeru4bLQCag-OvGG0ltz1qyEg57FY4IEB87Y,10995
24
+ lsst/resources/_resourceHandles/_s3ResourceHandle.py,sha256=Cp-eBtptskbmthy3DwLKPpYPLvU_lrqtK10X37inHt0,12406
25
+ lsst_resources-29.2025.4600.dist-info/licenses/COPYRIGHT,sha256=yazVsoMmFwhiw5itGrdT4YPmXbpsQyUFjlpOyZIa77M,148
26
+ lsst_resources-29.2025.4600.dist-info/licenses/LICENSE,sha256=7wrtgl8meQ0_RIuv2TjIKpAnNrl-ODH-QLwyHe9citI,1516
27
+ lsst_resources-29.2025.4600.dist-info/METADATA,sha256=AHUIXOjx8MQBorWKENL6Q360iyEcLVrF7IOzOEDMGIM,2240
28
+ lsst_resources-29.2025.4600.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
29
+ lsst_resources-29.2025.4600.dist-info/top_level.txt,sha256=eUWiOuVVm9wwTrnAgiJT6tp6HQHXxIhj2QSZ7NYZH80,5
30
+ lsst_resources-29.2025.4600.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
31
+ lsst_resources-29.2025.4600.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,28 +0,0 @@
1
- lsst/__init__.py,sha256=9I6UQ9gj-ZcPlvsa0OPBo76UujxXVehVzw9yMAOQvyM,466
2
- lsst/resources/__init__.py,sha256=BDj6uokvd0ZQNGl-Xgz5gZd83Z0L2gFqGSk0KJpylP8,778
3
- lsst/resources/_resourcePath.py,sha256=liiMJAZQahrt7zfeJq8iRHAlS-sFGmksR116JUfxmAA,59199
4
- lsst/resources/file.py,sha256=iri8Vri82gC2kXvj743wfiDRLrh0dgYWjSbM9Okb6N8,22624
5
- lsst/resources/gs.py,sha256=_SQC4t947JQ30aC6GHa3Ck-PAMhefhCbQhgO0MSHIRw,12592
6
- lsst/resources/http.py,sha256=m_Eb-c-vSrAJfg--KcicyIYV1PQbeRw_eEikmu-_DCc,86576
7
- lsst/resources/location.py,sha256=x3Tq0x5o1OXYmZDxYBenUG1N71wtDhnjVAr3s2ZEiu8,7937
8
- lsst/resources/mem.py,sha256=0rbjU6M1Ug7d3baCBh2TZi-3GcBUGz5uYzGiJXBGVBM,944
9
- lsst/resources/packageresource.py,sha256=myehOJgNA2k6pKH1l2pJQfOPIc7_ZhlZcrqjL-2SC7s,6462
10
- lsst/resources/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- lsst/resources/s3.py,sha256=cBnInTXbmTpkg32Y5JEDP6NPY4LJEX7dQsTeHy3rDak,22587
12
- lsst/resources/s3utils.py,sha256=cKJ9GWHETHhn1djezyikWwAaw4k1B3hFvfif96THHDQ,14355
13
- lsst/resources/schemeless.py,sha256=GfJcKzZ0XIeepfQdW4HPZWiZlSp_ej0SEtSiJTrDUQs,10666
14
- lsst/resources/tests.py,sha256=PNduvL9dgJurH2OtMsd0cPdNPKljor6K2rLh3ybID94,40132
15
- lsst/resources/utils.py,sha256=D2J0d0n5-jotQ3AWFotXTi2PFN0S9C6HK41G1uO-Y3Q,5891
16
- lsst/resources/version.py,sha256=N2xpYeAY7bVIkj93qKDpOwMTSm8nqrrJTSRFzXgYlTk,52
17
- lsst/resources/_resourceHandles/__init__.py,sha256=zOcZ8gVEBdAWcHJaZabA8Vdq-wAVcxjbmA_1b1IWM6M,76
18
- lsst/resources/_resourceHandles/_baseResourceHandle.py,sha256=lQwxDOmFUNJndTxsjpz-HxrQBL0L-z4aXQocHdOEI7c,4676
19
- lsst/resources/_resourceHandles/_fileResourceHandle.py,sha256=A7_WQPzD0ZlOzNmaI_TPdZybrNxrXPkNHWVla3UFxfs,3676
20
- lsst/resources/_resourceHandles/_httpResourceHandle.py,sha256=w14dnwez4E1Kjo2Yxr0DsUUAja9cyBfkHzqI4WdKW3o,10541
21
- lsst/resources/_resourceHandles/_s3ResourceHandle.py,sha256=NkDmPb9bm_zMvr6mMnb-tBmqJDt0yUJrt2gZXR8l7ok,12923
22
- lsst_resources-29.0.0rc7.dist-info/licenses/COPYRIGHT,sha256=yazVsoMmFwhiw5itGrdT4YPmXbpsQyUFjlpOyZIa77M,148
23
- lsst_resources-29.0.0rc7.dist-info/licenses/LICENSE,sha256=7wrtgl8meQ0_RIuv2TjIKpAnNrl-ODH-QLwyHe9citI,1516
24
- lsst_resources-29.0.0rc7.dist-info/METADATA,sha256=HD7NMX83j9A9DY8ySdSuxQhabAiZ5dbkniN_JHCHFjI,2234
25
- lsst_resources-29.0.0rc7.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
26
- lsst_resources-29.0.0rc7.dist-info/top_level.txt,sha256=eUWiOuVVm9wwTrnAgiJT6tp6HQHXxIhj2QSZ7NYZH80,5
27
- lsst_resources-29.0.0rc7.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
28
- lsst_resources-29.0.0rc7.dist-info/RECORD,,