Skip to content

Commit 24f307f

Browse files
committed
apply Arnatious cleanup for entry points dist cache
1 parent 6c9ec8b commit 24f307f

File tree

1 file changed

+10
-14
lines changed
  • opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation

1 file changed

+10
-14
lines changed

opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/_load.py

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

15+
from functools import cached_property
1516
from logging import getLogger
1617
from os import environ
1718

@@ -35,26 +36,21 @@
3536

3637

3738
class _EntryPointDistFinder:
38-
def __int__(self):
39-
self._mapping = None
39+
@cached_property
40+
def _mapping(self):
41+
return {
42+
self._key_for(ep): dist
43+
for dist in distributions()
44+
for ep in dist.entry_points
45+
}
4046

4147
def dist_for(self, entry_point: EntryPoint):
4248
dist = getattr(entry_point, "dist", None)
4349
if dist:
4450
return dist
4551

46-
if self._mapping is None:
47-
self._mapping = {
48-
self._key_for(ep): dist
49-
for ep in dist.entry_points
50-
for dist in distributions()
51-
}
52-
53-
return self._mapping.get(self._key_for(entry_point))
54-
55-
@staticmethod
56-
def _key_for(entry_point: EntryPoint):
57-
return f"{entry_point.group}:{entry_point.name}:{entry_point.value}"
52+
key = f"{entry_point.group}:{entry_point.name}:{entry_point.value}"
53+
return self._mapping.get(key)
5854

5955

6056
def _load_distro() -> BaseDistro:

0 commit comments

Comments
 (0)