Skip to content

Commit c25a6b8

Browse files
committed
Format with ruff.
1 parent 587e61e commit c25a6b8

File tree

15 files changed

+161
-156
lines changed

15 files changed

+161
-156
lines changed

opentelemetry-instrumentation/src/opentelemetry/instrumentation/_blobupload/api/blob.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414

1515
import base64
1616
import json
17-
1817
from types import MappingProxyType as _frozendict
19-
from typing import Mapping, Dict, Optional
18+
from typing import Mapping, Optional
2019

2120

2221
class Blob:
@@ -119,8 +118,8 @@ def __eq__(self, o):
119118
def __repr__(self):
120119
params = [repr(self._raw_bytes)]
121120
if self._content_type is not None:
122-
params.append('content_type={}'.format(repr(self._content_type)))
121+
params.append("content_type={}".format(repr(self._content_type)))
123122
if self._labels:
124-
params.append('labels={}'.format(json.dumps(self._labels, sort_keys=True)))
125-
params_string = ', '.join(params)
126-
return 'Blob({})'.format(params_string)
123+
params.append("labels={}".format(json.dumps(self._labels, sort_keys=True)))
124+
params_string = ", ".join(params)
125+
return "Blob({})".format(params_string)

opentelemetry-instrumentation/src/opentelemetry/instrumentation/_blobupload/api/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
"""Defines constants that are used by the '_blobupload' package."""
1616

1717
# Special constant used to indicate that a BlobUploader did not upload.
18-
NOT_UPLOADED = '/dev/null'
18+
NOT_UPLOADED = "/dev/null"

opentelemetry-instrumentation/src/opentelemetry/instrumentation/_blobupload/api/content_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ def from_buffer(self, raw_bytes, mime=True):
3939
def detect_content_type(raw_bytes: bytes) -> str:
4040
"""Attempts to infer the content type of the specified data."""
4141
if not raw_bytes:
42-
return 'application/octet-stream'
42+
return "application/octet-stream"
4343
return _module.from_buffer(raw_bytes, mime=True)

opentelemetry-instrumentation/src/opentelemetry/instrumentation/_blobupload/api/provider.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
from opentelemetry.instrumentation._blobupload.api.blob_uploader import (
2121
BlobUploader,
2222
)
23-
from opentelemetry.instrumentation._blobupload.api.constants import NOT_UPLOADED
24-
23+
from opentelemetry.instrumentation._blobupload.api.constants import (
24+
NOT_UPLOADED,
25+
)
2526

2627
_logger = logging.getLogger(__name__)
2728

opentelemetry-instrumentation/src/opentelemetry/instrumentation/_blobupload/backend/google/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
# distributed under the License is distributed on an "AS IS" BASIS,
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
13-
# limitations under the License.
13+
# limitations under the License.

opentelemetry-instrumentation/src/opentelemetry/instrumentation/_blobupload/backend/google/gcs/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from opentelemetry.instrumentation._blobupload.backend.google.gcs._gcs_impl import GcsBlobUploader
16-
15+
from opentelemetry.instrumentation._blobupload.backend.google.gcs._gcs_impl import (
16+
GcsBlobUploader,
17+
)
1718

1819
__all__ = [
1920
GcsBlobUploader

opentelemetry-instrumentation/src/opentelemetry/instrumentation/_blobupload/backend/google/gcs/_gcs_client_wrapper.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
"""Isolates calls to 'google-cloud-storage' dependency, simplifying mocking."""
1717

1818

19-
from typing import Any, TypeAlias
20-
2119
import logging
20+
from typing import Any, TypeAlias
2221

2322
_logger = logging.getLogger(__name__)
2423

@@ -38,7 +37,7 @@
3837
# to 'Any' to allow for mocks of the Google Cloud Storage client. It
3938
# is updated at runtime in 'set_gcs_client_factory', though this
4039
# means it is not particularly useful for automatic static type
41-
# checking (it is, however, useful for documenting intended type).
40+
# checking (it is, however, useful for documenting intended type).
4241
GcsClientType: TypeAlias = Any
4342

4443

@@ -47,7 +46,7 @@ def set_gcs_client_factory(gcs_client_type, client_factory):
4746
global _gcs_client_factory
4847
global GcsClientType
4948
if _gcs_initialized:
50-
_logger.warning('Replacing default GCS client factory')
49+
_logger.warning("Replacing default GCS client factory")
5150
GcsClientType = gcs_client_type
5251
_gcs_client_factory = client_factory
5352
if _gcs_client_factory and _gcs_blob_from_uri:
@@ -58,7 +57,7 @@ def set_gcs_blob_from_uri(blob_from_uri):
5857
global _gcs_initialized
5958
global _gcs_blob_from_uri
6059
if _gcs_initialized:
61-
_logger.warning('Replacing default GCS blob_from_uri method')
60+
_logger.warning("Replacing default GCS blob_from_uri method")
6261
_gcs_blob_from_uri = blob_from_uri
6362
if _gcs_client_factory and _gcs_blob_from_uri:
6463
_gcs_initialized = True
@@ -84,7 +83,7 @@ def blob_from_uri(uri, client):
8483
from google.cloud.storage import Client as _GcsClient
8584
from google.cloud.storage.blob import Blob as _GcsBlob
8685
set_gcs_client_factory(_GcsClient, _GcsClient)
87-
set_gcs_blob_from_uri(getattr(_GcsBlob, 'from_uri', getattr(_GcsBlob, 'from_string')))
86+
set_gcs_blob_from_uri(getattr(_GcsBlob, "from_uri", getattr(_GcsBlob, "from_string")))
8887
_logger.debug('Found "google-cloud-storage" optional dependency and successfully registered it.')
8988
except ImportError:
9089
_logger.warning('Missing optional "google-cloud-storage" dependency.')

opentelemetry-instrumentation/src/opentelemetry/instrumentation/_blobupload/backend/google/gcs/_gcs_impl.py

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@
1515
"""Provides the 'GcsBlobUploader' class."""
1616

1717
import io
18-
import uuid
1918
import logging
20-
19+
import uuid
2120
from typing import Optional, TypeAlias
2221

23-
from opentelemetry.instrumentation._blobupload.api import Blob
24-
from opentelemetry.instrumentation._blobupload.api import BlobUploader
25-
from opentelemetry.instrumentation._blobupload.utils import SimpleBlobUploader
26-
from opentelemetry.instrumentation._blobupload.utils import blob_uploader_from_simple_blob_uploader
27-
from opentelemetry.instrumentation._blobupload.backend.google.gcs import _gcs_client_wrapper
22+
from opentelemetry.instrumentation._blobupload.api import Blob, BlobUploader
23+
from opentelemetry.instrumentation._blobupload.backend.google.gcs import (
24+
_gcs_client_wrapper,
25+
)
26+
from opentelemetry.instrumentation._blobupload.utils import (
27+
SimpleBlobUploader,
28+
blob_uploader_from_simple_blob_uploader,
29+
)
2830

2931
_logger = logging.getLogger(__name__)
3032

@@ -33,26 +35,26 @@
3335

3436
def _path_for_span(trace_id, span_id):
3537
if not trace_id or not span_id:
36-
return ''
37-
return 'traces/{}/spans/{}'.format(trace_id, span_id)
38+
return ""
39+
return "traces/{}/spans/{}".format(trace_id, span_id)
3840

3941

4042
def _path_for_event(trace_id, span_id, event_name):
4143
if not event_name:
42-
return ''
44+
return ""
4345
span_path = _path_for_span(trace_id, span_id)
4446
if not span_path:
45-
return ''
46-
return '{}/events/{}'.format(span_path, event_name)
47+
return ""
48+
return "{}/events/{}".format(span_path, event_name)
4749

4850

4951
def _path_for_span_event(trace_id, span_id, event_index):
5052
if event_index is None:
51-
return ''
53+
return ""
5254
span_path = _path_for_span(trace_id, span_id)
5355
if not span_path:
54-
return ''
55-
return '{}/events/{}'.format(span_path, event_index)
56+
return ""
57+
return "{}/events/{}".format(span_path, event_index)
5658

5759

5860
def _path_segment_from_labels(labels):
@@ -67,39 +69,39 @@ def _path_segment_from_labels(labels):
6769
...depending on the particular type of signal source.
6870
6971
"""
70-
signal_type = labels.get('otel_type')
71-
if not signal_type or signal_type not in ['span', 'event', 'span_event']:
72-
return ''
73-
trace_id = labels.get('trace_id')
74-
span_id = labels.get('span_id')
75-
event_name = labels.get('event_name')
76-
event_index = labels.get('event_index')
77-
if signal_type == 'span':
72+
signal_type = labels.get("otel_type")
73+
if not signal_type or signal_type not in ["span", "event", "span_event"]:
74+
return ""
75+
trace_id = labels.get("trace_id")
76+
span_id = labels.get("span_id")
77+
event_name = labels.get("event_name")
78+
event_index = labels.get("event_index")
79+
if signal_type == "span":
7880
return _path_for_span(trace_id, span_id)
79-
elif signal_type == 'event':
81+
elif signal_type == "event":
8082
return _path_for_event(trace_id, span_id, event_name)
81-
elif signal_type == 'span_event':
83+
elif signal_type == "span_event":
8284
return _path_for_span_event(trace_id, span_id, event_index)
8385

8486

8587
class _SimpleGcsBlobUploader(SimpleBlobUploader):
8688

8789
def __init__(self, prefix: str, client:Optional[GcsClient]=None):
8890
if not prefix:
89-
raise ValueError('Must supply a non-empty prefix.')
90-
if not prefix.startswith('gs://'):
91+
raise ValueError("Must supply a non-empty prefix.")
92+
if not prefix.startswith("gs://"):
9193
raise ValueError('Invalid prefix; must start with "gs://"; found: "{}".'.format(prefix))
92-
if not prefix.endswith('/'):
93-
prefix = '{}/'.format(prefix)
94+
if not prefix.endswith("/"):
95+
prefix = "{}/".format(prefix)
9496
self._prefix = prefix
9597
self._client = client or _gcs_client_wrapper.create_gcs_client()
9698

9799
def generate_destination_uri(self, blob: Blob) -> str:
98100
origin_path = _path_segment_from_labels(blob.labels)
99-
if origin_path and not origin_path.endswith('/'):
100-
origin_path = '{}/'.format(origin_path)
101+
if origin_path and not origin_path.endswith("/"):
102+
origin_path = "{}/".format(origin_path)
101103
upload_id = uuid.uuid4().hex
102-
return '{}{}uploads/{}'.format(self._prefix, origin_path, upload_id)
104+
return "{}{}uploads/{}".format(self._prefix, origin_path, upload_id)
103105

104106
def upload_sync(self, uri: str, blob: Blob):
105107
_logger.debug('Uploading blob: size: {} -> "{}"'.format(len(blob.raw_bytes), uri))

opentelemetry-instrumentation/src/opentelemetry/instrumentation/_blobupload/utils/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414

1515
"""Exposes API methods to callers from the package name."""
1616

17-
from opentelemetry.instrumentation._blobupload.utils.simple_blob_uploader_adaptor import blob_uploader_from_simple_blob_uploader
18-
from opentelemetry.instrumentation._blobupload.utils.simple_blob_uploader import SimpleBlobUploader
17+
from opentelemetry.instrumentation._blobupload.utils.simple_blob_uploader import (
18+
SimpleBlobUploader,
19+
)
20+
from opentelemetry.instrumentation._blobupload.utils.simple_blob_uploader_adaptor import (
21+
blob_uploader_from_simple_blob_uploader,
22+
)
1923

2024
__all__ = [
2125
blob_uploader_from_simple_blob_uploader,

opentelemetry-instrumentation/src/opentelemetry/instrumentation/_blobupload/utils/simple_blob_uploader.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from opentelemetry.instrumentation._blobupload.api import Blob
2020

21+
2122
class SimpleBlobUploader(abc.ABC):
2223
"""Pure abstract base class of a backend implementation that is synchronous."""
2324

@@ -31,7 +32,7 @@ def generate_destination_uri(self, blob: Blob) -> str:
3132
Returns:
3233
A new, unique URI that represents the target destination of the data.
3334
"""
34-
raise NotImplementedError('SimpleBlobUploader.generate_destination_uri')
35+
raise NotImplementedError("SimpleBlobUploader.generate_destination_uri")
3536

3637
@abc.abstractmethod
3738
def upload_sync(self, uri: str, blob: Blob):
@@ -45,4 +46,4 @@ def upload_sync(self, uri: str, blob: Blob):
4546
Effects:
4647
Attempts to upload/write the Blob to the specified destination URI.
4748
"""
48-
raise NotImplementedError('SimpleBlobUploader.upload_sync')
49+
raise NotImplementedError("SimpleBlobUploader.upload_sync")

0 commit comments

Comments
 (0)