Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer import of json and platform #503

Merged
merged 6 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import email
import functools
import itertools
import json
import operator
import os
import pathlib
Expand All @@ -29,8 +28,6 @@
from itertools import starmap
from typing import Any, Iterable, List, Mapping, Match, Optional, Set, cast

from zipp.compat.overlay import zipfile

from . import _meta
from ._collections import FreezableDefaultDict, Pair
from ._compat import (
Expand Down Expand Up @@ -675,6 +672,8 @@ def origin(self):
return self._load_json('direct_url.json')

def _load_json(self, filename):
import json

return pass_none(json.loads)(
self.read_text(filename),
object_hook=lambda data: types.SimpleNamespace(**data),
Expand Down Expand Up @@ -777,6 +776,8 @@ def children(self):
return []

def zip_children(self):
from zipp.compat.overlay import zipfile

zip_path = zipfile.Path(self.root)
names = zip_path.root.namelist()
self.joinpath = zip_path.joinpath
Expand Down
3 changes: 2 additions & 1 deletion importlib_metadata/_compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import platform
import sys

__all__ = ['install', 'NullFinder']
Expand Down Expand Up @@ -52,5 +51,7 @@ def pypy_partial(val):

Workaround for #327.
"""
import platform

jaraco marked this conversation as resolved.
Show resolved Hide resolved
jaraco marked this conversation as resolved.
Show resolved Hide resolved
is_pypy = platform.python_implementation() == 'PyPy'
return val + is_pypy
Loading