lsst-resources 29.2025.1400__py3-none-any.whl → 29.2025.1500__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.
@@ -23,8 +23,6 @@ import multiprocessing
23
23
  import os
24
24
  import posixpath
25
25
  import re
26
- import shutil
27
- import tempfile
28
26
  import urllib.parse
29
27
  from functools import cache
30
28
  from pathlib import Path, PurePath, PurePosixPath
@@ -41,7 +39,7 @@ from collections.abc import Iterable, Iterator
41
39
  from typing import TYPE_CHECKING, Any, Literal, NamedTuple, overload
42
40
 
43
41
  from ._resourceHandles._baseResourceHandle import ResourceHandleProtocol
44
- from .utils import ensure_directory_is_writeable
42
+ from .utils import get_tempdir
45
43
 
46
44
  if TYPE_CHECKING:
47
45
  from .utils import TransactionProtocol
@@ -1140,35 +1138,23 @@ class ResourcePath: # numpydoc ignore=PR02
1140
1138
  prefix : `ResourcePath`, optional
1141
1139
  Temporary directory to use (can be any scheme). Without this the
1142
1140
  path will be formed as a local file URI in a temporary directory
1143
- created by `tempfile.mkdtemp`. Ensuring that the prefix
1144
- location exists is the responsibility of the caller.
1141
+ obtained from `lsst.resources.utils.get_tempdir`. Ensuring that the
1142
+ prefix location exists is the responsibility of the caller.
1145
1143
  suffix : `str`, optional
1146
1144
  A file suffix to be used. The ``.`` should be included in this
1147
1145
  suffix.
1148
1146
  delete : `bool`, optional
1149
1147
  By default the resource will be deleted when the context manager
1150
1148
  is exited. Setting this flag to `False` will leave the resource
1151
- alone. `False` will also retain any directories that may have
1152
- been created.
1149
+ alone.
1153
1150
 
1154
1151
  Yields
1155
1152
  ------
1156
1153
  uri : `ResourcePath`
1157
1154
  The temporary URI. Will be removed when the context is completed.
1158
1155
  """
1159
- use_tempdir = False
1160
1156
  if prefix is None:
1161
- directory = tempfile.mkdtemp()
1162
- # If the user has set a umask that restricts the owner-write bit,
1163
- # the directory returned from mkdtemp may not initially be
1164
- # writeable by us
1165
- ensure_directory_is_writeable(directory)
1166
-
1167
- prefix = ResourcePath(directory, forceDirectory=True, isTemporary=True)
1168
- # Record that we need to delete this directory. Can not rely
1169
- # on isTemporary flag since an external prefix may have that
1170
- # set as well.
1171
- use_tempdir = True
1157
+ prefix = ResourcePath(get_tempdir(), forceDirectory=True)
1172
1158
 
1173
1159
  # Need to create a randomized file name. For consistency do not
1174
1160
  # use mkstemp for local and something else for remote. Additionally
@@ -1187,13 +1173,10 @@ class ResourcePath: # numpydoc ignore=PR02
1187
1173
  yield temporary_uri
1188
1174
  finally:
1189
1175
  if delete:
1190
- if use_tempdir:
1191
- shutil.rmtree(prefix.ospath, ignore_errors=True)
1192
- else:
1193
- with contextlib.suppress(FileNotFoundError):
1194
- # It's okay if this does not work because the user
1195
- # removed the file.
1196
- temporary_uri.remove()
1176
+ with contextlib.suppress(FileNotFoundError):
1177
+ # It's okay if this does not work because the user
1178
+ # removed the file.
1179
+ temporary_uri.remove()
1197
1180
 
1198
1181
  def read(self, size: int = -1) -> bytes:
1199
1182
  """Open the resource and return the contents in bytes.
lsst/resources/http.py CHANGED
@@ -26,7 +26,6 @@ import random
26
26
  import re
27
27
  import ssl
28
28
  import stat
29
- import tempfile
30
29
  from collections.abc import Iterator
31
30
  from typing import TYPE_CHECKING, Any, BinaryIO, cast
32
31
 
@@ -60,6 +59,7 @@ from lsst.utils.timer import time_this
60
59
  from ._resourceHandles import ResourceHandleProtocol
61
60
  from ._resourceHandles._httpResourceHandle import HttpReadResourceHandle, parse_content_range_header
62
61
  from ._resourcePath import ResourcePath
62
+ from .utils import get_tempdir
63
63
 
64
64
  if TYPE_CHECKING:
65
65
  from .utils import TransactionProtocol
@@ -384,18 +384,7 @@ class HttpResourcePathConfig:
384
384
  if self._tmpdir_buffersize is not None:
385
385
  return self._tmpdir_buffersize
386
386
 
387
- # Use the value of environment variables 'LSST_RESOURCES_TMPDIR' or
388
- # 'TMPDIR', if defined. Otherwise use the system temporary directory,
389
- # with a last-resort fallback to the current working directory if
390
- # nothing else is available.
391
- tmpdir = None
392
- for dir in (os.getenv(v) for v in ("LSST_RESOURCES_TMPDIR", "TMPDIR")):
393
- if dir and os.path.isdir(dir):
394
- tmpdir = dir
395
- break
396
-
397
- if tmpdir is None:
398
- tmpdir = tempfile.gettempdir()
387
+ tmpdir = get_tempdir()
399
388
 
400
389
  # Compute the block size as 256 blocks of typical size
401
390
  # (i.e. 4096 bytes) or 10 times the file system block size,
lsst/resources/utils.py CHANGED
@@ -11,7 +11,7 @@
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
@@ -21,6 +21,7 @@ import shutil
21
21
  import stat
22
22
  import tempfile
23
23
  from collections.abc import Callable, Iterator
24
+ from functools import cache
24
25
  from pathlib import Path, PurePath, PurePosixPath
25
26
  from typing import Any, Protocol
26
27
 
@@ -93,6 +94,35 @@ def posix2os(posix: PurePath | str) -> str:
93
94
  return os.path.join(*paths)
94
95
 
95
96
 
97
+ @cache
98
+ def get_tempdir() -> str:
99
+ """Get POSIX path to temporary directory.
100
+
101
+ Returns
102
+ -------
103
+ tmpdir : `str`
104
+ Path to the default temporary directory location.
105
+
106
+ Notes
107
+ -----
108
+ Uses the value of environment variables ``LSST_RESOURCES_TMPDIR`` or
109
+ ``TMPDIR``, if defined. Otherwise use the system temporary directory,
110
+ with a last-resort fallback to the current working directory if
111
+ nothing else is available.
112
+ """
113
+ tmpdir = None
114
+ # $TMPDIR is also checked with getttempdir() below.
115
+ for dir in (os.getenv(v) for v in ("LSST_RESOURCES_TMPDIR", "TMPDIR")):
116
+ if dir and os.path.isdir(dir):
117
+ tmpdir = dir
118
+ break
119
+
120
+ if tmpdir is None:
121
+ tmpdir = tempfile.gettempdir()
122
+
123
+ return tmpdir
124
+
125
+
96
126
  class NoTransaction:
97
127
  """A simple emulation of the
98
128
  `~lsst.daf.butler.core.datastore.DatastoreTransaction` class.
lsst/resources/version.py CHANGED
@@ -1,2 +1,2 @@
1
1
  __all__ = ["__version__"]
2
- __version__ = "29.2025.1400"
2
+ __version__ = "29.2025.1500"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lsst-resources
3
- Version: 29.2025.1400
3
+ Version: 29.2025.1500
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
6
  License: BSD 3-Clause License
@@ -1,9 +1,9 @@
1
1
  lsst/__init__.py,sha256=9I6UQ9gj-ZcPlvsa0OPBo76UujxXVehVzw9yMAOQvyM,466
2
2
  lsst/resources/__init__.py,sha256=BDj6uokvd0ZQNGl-Xgz5gZd83Z0L2gFqGSk0KJpylP8,778
3
- lsst/resources/_resourcePath.py,sha256=xjXtlr8KVkW74V9lnS4WT-mTYy8nhdlXLR8GRcWflxE,65697
3
+ lsst/resources/_resourcePath.py,sha256=xTVyDHD-UHlF5FeDvSXXnsmOuoSFnORZD_wMksxiFfA,64926
4
4
  lsst/resources/file.py,sha256=-jPuoHvTEtx5tnDyNkfwhWAyX0cTwkuMd-JvJn9EGdE,23226
5
5
  lsst/resources/gs.py,sha256=Lpo5GAzH7R7HG8E5RMGOdP4j4hjWJn-k6M3OXj0nHQM,12783
6
- lsst/resources/http.py,sha256=4Z6nZujpG8cKXv5UrKSxm6GnbJt3up81_TeNJo6yAKY,88713
6
+ lsst/resources/http.py,sha256=JW3cBe4MERyjopFKkELui1BRr4b4Mkgp0Iqt9YFIxuc,88227
7
7
  lsst/resources/location.py,sha256=x3Tq0x5o1OXYmZDxYBenUG1N71wtDhnjVAr3s2ZEiu8,7937
8
8
  lsst/resources/mem.py,sha256=VOWh7XxJPfqKcFdLZSjKEAfORQ2AHZHpxmjT8LniV60,1008
9
9
  lsst/resources/packageresource.py,sha256=vnfeRlpVwpC5cDQZE6Lnh8EH6oZy1sH2vLz9ONYjJ4k,6817
@@ -12,17 +12,17 @@ lsst/resources/s3.py,sha256=wrOMdFWltxpGEWeL--kPCbk5Le_viCIsEn4lOPZbXhM,24124
12
12
  lsst/resources/s3utils.py,sha256=cKJ9GWHETHhn1djezyikWwAaw4k1B3hFvfif96THHDQ,14355
13
13
  lsst/resources/schemeless.py,sha256=GfJcKzZ0XIeepfQdW4HPZWiZlSp_ej0SEtSiJTrDUQs,10666
14
14
  lsst/resources/tests.py,sha256=MLB8hERKuNredzzg3Qq9M_U7IesV3xrbcjFwKuMp3Ok,43513
15
- lsst/resources/utils.py,sha256=D2J0d0n5-jotQ3AWFotXTi2PFN0S9C6HK41G1uO-Y3Q,5891
16
- lsst/resources/version.py,sha256=tG0U8v8pqFE3UYsFMTK1so9Djnk6SthXSsn8LMVzAoQ,55
15
+ lsst/resources/utils.py,sha256=IHVrOdj0szNWxiXk-jbZu1RhTR8WXks1vI9JCpBxeBA,6706
16
+ lsst/resources/version.py,sha256=altncYankWkwG1F2OVHhPl0np72lUhdVRAOSqBtd-kc,55
17
17
  lsst/resources/_resourceHandles/__init__.py,sha256=zOcZ8gVEBdAWcHJaZabA8Vdq-wAVcxjbmA_1b1IWM6M,76
18
18
  lsst/resources/_resourceHandles/_baseResourceHandle.py,sha256=lQwxDOmFUNJndTxsjpz-HxrQBL0L-z4aXQocHdOEI7c,4676
19
19
  lsst/resources/_resourceHandles/_fileResourceHandle.py,sha256=A7_WQPzD0ZlOzNmaI_TPdZybrNxrXPkNHWVla3UFxfs,3676
20
20
  lsst/resources/_resourceHandles/_httpResourceHandle.py,sha256=JRjpE-ZQfgKX5OyVLulIbzW38FdhovcoOd1D4rhb5vk,10900
21
21
  lsst/resources/_resourceHandles/_s3ResourceHandle.py,sha256=NkDmPb9bm_zMvr6mMnb-tBmqJDt0yUJrt2gZXR8l7ok,12923
22
- lsst_resources-29.2025.1400.dist-info/licenses/COPYRIGHT,sha256=yazVsoMmFwhiw5itGrdT4YPmXbpsQyUFjlpOyZIa77M,148
23
- lsst_resources-29.2025.1400.dist-info/licenses/LICENSE,sha256=7wrtgl8meQ0_RIuv2TjIKpAnNrl-ODH-QLwyHe9citI,1516
24
- lsst_resources-29.2025.1400.dist-info/METADATA,sha256=Z-uQEgBnNqKRf9_wkbTe-cJcyIWo7u5ihdMqAtBj8dM,2237
25
- lsst_resources-29.2025.1400.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
26
- lsst_resources-29.2025.1400.dist-info/top_level.txt,sha256=eUWiOuVVm9wwTrnAgiJT6tp6HQHXxIhj2QSZ7NYZH80,5
27
- lsst_resources-29.2025.1400.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
28
- lsst_resources-29.2025.1400.dist-info/RECORD,,
22
+ lsst_resources-29.2025.1500.dist-info/licenses/COPYRIGHT,sha256=yazVsoMmFwhiw5itGrdT4YPmXbpsQyUFjlpOyZIa77M,148
23
+ lsst_resources-29.2025.1500.dist-info/licenses/LICENSE,sha256=7wrtgl8meQ0_RIuv2TjIKpAnNrl-ODH-QLwyHe9citI,1516
24
+ lsst_resources-29.2025.1500.dist-info/METADATA,sha256=8tmxas_i8S1F0lwXkFr7MwlERU1h1TArUW-xUqp4FwE,2237
25
+ lsst_resources-29.2025.1500.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
26
+ lsst_resources-29.2025.1500.dist-info/top_level.txt,sha256=eUWiOuVVm9wwTrnAgiJT6tp6HQHXxIhj2QSZ7NYZH80,5
27
+ lsst_resources-29.2025.1500.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
28
+ lsst_resources-29.2025.1500.dist-info/RECORD,,