Skip to content

Commit cc6cc24

Browse files
authored
Merge pull request #96 from lsst/tickets/DM-42091
DM-42091: Remove long deprecated s3 utilities
2 parents 754fa0f + 0cf3e5c commit cc6cc24

File tree

4 files changed

+2
-95
lines changed

4 files changed

+2
-95
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ repos:
2222
name: isort (python)
2323
- repo: https://github.com/astral-sh/ruff-pre-commit
2424
# Ruff version.
25-
rev: v0.5.7
25+
rev: v0.6.8
2626
hooks:
2727
- id: ruff
2828
- repo: https://github.com/numpy/numpydoc

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ classifiers = [
2121
keywords = ["lsst"]
2222
dependencies = [
2323
"lsst-utils",
24-
"deprecated"
2524
]
2625
dynamic = ["version"]
2726
requires-python = ">=3.11.0"

python/lsst/resources/s3utils.py

+1-92
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@
1212
from __future__ import annotations
1313

1414
__all__ = (
15-
"clean_test_environment",
1615
"getS3Client",
1716
"s3CheckFileExists",
1817
"bucketExists",
19-
"setAwsEnvCredentials",
20-
"unsetAwsEnvCredentials",
2118
"backoff",
2219
"all_retryable_errors",
2320
"max_retry_time",
@@ -35,19 +32,14 @@
3532
from contextlib import contextmanager
3633
from http.client import HTTPException, ImproperConnectionState
3734
from types import ModuleType
38-
from typing import TYPE_CHECKING, Any, NamedTuple, cast
35+
from typing import Any, NamedTuple, cast
3936
from unittest.mock import patch
4037

4138
from botocore.exceptions import ClientError
4239
from botocore.handlers import validate_bucket_name
43-
from deprecated.sphinx import deprecated
4440
from urllib3.exceptions import HTTPError, RequestError
4541
from urllib3.util import Url, parse_url
4642

47-
if TYPE_CHECKING:
48-
from unittest import TestCase
49-
50-
5143
try:
5244
import boto3
5345
except ImportError:
@@ -124,33 +116,6 @@ class _TooManyRequestsError(Exception):
124116
max_retry_time = 60
125117

126118

127-
@deprecated(
128-
reason="This has been replaced by a new function, clean_test_environment_for_s3()."
129-
" Will be removed after v26.2023.5000",
130-
version="26.2023.5000",
131-
category=FutureWarning,
132-
)
133-
def clean_test_environment(testcase: TestCase) -> None:
134-
"""Clear S3_ENDPOINT_URL then restore it at the end of a test.
135-
136-
Parameters
137-
----------
138-
testcase : `unittest.TestCase`
139-
Reference to the test being run; used to add a cleanup function.
140-
"""
141-
endpoint = os.environ.get("S3_ENDPOINT_URL")
142-
143-
if not endpoint:
144-
return
145-
os.environ["S3_ENDPOINT_URL"] = ""
146-
147-
def cleanup() -> None:
148-
if endpoint is not None:
149-
os.environ["S3_ENDPOINT_URL"] = endpoint
150-
151-
testcase.addCleanup(cleanup)
152-
153-
154119
@contextmanager
155120
def clean_test_environment_for_s3() -> Iterator[None]:
156121
"""Reset S3 environment to ensure that unit tests with a mock S3 can't
@@ -446,62 +411,6 @@ def bucketExists(bucketName: str, client: boto3.client | None = None) -> bool:
446411
return False
447412

448413

449-
@deprecated(
450-
reason="This function could accidentally leave real credentials in the environment during testing."
451-
" A new function, clean_test_environment_for_s3(), can be used to set up mock credentials."
452-
" Will be removed after v26.2023.5000",
453-
version="26.2023.5000",
454-
category=FutureWarning,
455-
)
456-
def setAwsEnvCredentials(
457-
accessKeyId: str = "dummyAccessKeyId", secretAccessKey: str = "dummySecretAccessKey"
458-
) -> bool:
459-
"""Set AWS credentials environmental variables.
460-
461-
Parameters
462-
----------
463-
accessKeyId : `str`
464-
Value given to AWS_ACCESS_KEY_ID environmental variable. Defaults to
465-
`dummyAccessKeyId`.
466-
secretAccessKey : `str`
467-
Value given to AWS_SECRET_ACCESS_KEY environmental variable. Defaults
468-
to `dummySecretAccessKey`.
469-
470-
Returns
471-
-------
472-
setEnvCredentials : `bool`
473-
True when environmental variables were set, False otherwise.
474-
475-
Notes
476-
-----
477-
If either AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY are not set, both
478-
values are overwritten to ensure that the values are consistent.
479-
"""
480-
if "AWS_ACCESS_KEY_ID" not in os.environ or "AWS_SECRET_ACCESS_KEY" not in os.environ:
481-
os.environ["AWS_ACCESS_KEY_ID"] = accessKeyId
482-
os.environ["AWS_SECRET_ACCESS_KEY"] = secretAccessKey
483-
return True
484-
return False
485-
486-
487-
@deprecated(
488-
reason="This has been replaced by a new function, clean_test_environment_for_s3()."
489-
" Will be removed after v26.2023.5000",
490-
version="26.2023.5000",
491-
category=FutureWarning,
492-
)
493-
def unsetAwsEnvCredentials() -> None:
494-
"""Unset AWS credential environment variables.
495-
496-
Unsets the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environmental
497-
variables.
498-
"""
499-
if "AWS_ACCESS_KEY_ID" in os.environ:
500-
del os.environ["AWS_ACCESS_KEY_ID"]
501-
if "AWS_SECRET_ACCESS_KEY" in os.environ:
502-
del os.environ["AWS_SECRET_ACCESS_KEY"]
503-
504-
505414
def translate_client_error(err: ClientError, uri: ResourcePath) -> None:
506415
"""Translate a ClientError into a specialist error if relevant.
507416

requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ responses >= 0.12.0
99
urllib3 >= 1.25.10
1010
requests >= 2.26.0
1111
defusedxml
12-
deprecated

0 commit comments

Comments
 (0)