-
Notifications
You must be signed in to change notification settings - Fork 728
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vendor importlib_metadata separately
- Loading branch information
Showing
31 changed files
with
1,577 additions
and
574 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Oops, something went wrong.