Skip to content

Commit

Permalink
vendor importlib_metadata separately
Browse files Browse the repository at this point in the history
  • Loading branch information
madhur-ob committed May 15, 2024
1 parent 2f87ca0 commit 0d01b8d
Show file tree
Hide file tree
Showing 31 changed files with 1,577 additions and 574 deletions.
2 changes: 1 addition & 1 deletion metaflow/_vendor/typeguard/_checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
from importlib.metadata import entry_points
from typing import ParamSpec
else:
from metaflow._vendor.importlib_metadata import entry_points
from importlib_metadata import entry_points
from metaflow._vendor.typing_extensions import ParamSpec

TypeCheckerCallable: TypeAlias = Callable[
Expand Down
2 changes: 1 addition & 1 deletion metaflow/_vendor/typeguard/_importhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
if sys.version_info >= (3, 10):
from importlib.metadata import PackageNotFoundError, version
else:
from metaflow._vendor.importlib_metadata import PackageNotFoundError, version
from importlib_metadata import PackageNotFoundError, version

try:
OPTIMIZATION = "typeguard" + "".join(version("typeguard").split(".")[:3])
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import abc
import csv
import sys
from metaflow._vendor import zipp
from metaflow._vendor.v3_6 import zipp
import email
import pathlib
import operator
Expand Down
71 changes: 71 additions & 0 deletions metaflow/_vendor/v3_6/importlib_metadata/_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import sys
import platform


__all__ = ['install', 'NullFinder', 'Protocol']


try:
from typing import Protocol
except ImportError: # pragma: no cover
from metaflow._vendor.v3_6.typing_extensions import Protocol # type: ignore


def install(cls):
"""
Class decorator for installation on sys.meta_path.
Adds the backport DistributionFinder to sys.meta_path and
attempts to disable the finder functionality of the stdlib
DistributionFinder.
"""
sys.meta_path.append(cls())
disable_stdlib_finder()
return cls


def disable_stdlib_finder():
"""
Give the backport primacy for discovering path-based distributions
by monkey-patching the stdlib O_O.
See #91 for more background for rationale on this sketchy
behavior.
"""

def matches(finder):
return getattr(
finder, '__module__', None
) == '_frozen_importlib_external' and hasattr(finder, 'find_distributions')

for finder in filter(matches, sys.meta_path): # pragma: nocover
del finder.find_distributions


class NullFinder:
"""
A "Finder" (aka "MetaClassFinder") that never finds any modules,
but may find distributions.
"""

@staticmethod
def find_spec(*args, **kwargs):
return None

# In Python 2, the import system requires finders
# to have a find_module() method, but this usage
# is deprecated in Python 3 in favor of find_spec().
# For the purposes of this finder (i.e. being present
# on sys.meta_path but having no other import
# system functionality), the two methods are identical.
find_module = find_spec


def pypy_partial(val):
"""
Adjust for variable stacklevel on partial under PyPy.
Workaround for #327.
"""
is_pypy = platform.python_implementation() == 'PyPy'
return val + is_pypy
13 changes: 13 additions & 0 deletions metaflow/_vendor/v3_7/importlib_metadata.LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2017-2019 Jason R. Coombs, Barry Warsaw

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

0 comments on commit 0d01b8d

Please sign in to comment.