Commit b01dcaf3 authored by Jason Madden's avatar Jason Madden Committed by GitHub

Merge pull request #1642 from gevent/issue1641

Make selectors2 truly optional on Py2 with dnspython
parents bf4e5d87 95b03f11
...@@ -13,7 +13,10 @@ os: ...@@ -13,7 +13,10 @@ os:
- linux - linux
- osx - osx
osx_image: xcode11.4 osx_image: xcode11.4
addons:
homebrew:
packages:
- ccache
env: env:
global: global:
...@@ -95,7 +98,6 @@ before_install: ...@@ -95,7 +98,6 @@ before_install:
- echo Running in stage $TRAVIS_BUILD_STAGE_NAME - echo Running in stage $TRAVIS_BUILD_STAGE_NAME
- | - |
if [[ "$TRAVIS_OS_NAME" == "osx" && "$TRAVIS_BUILD_STAGE_NAME" != "test" ]]; then if [[ "$TRAVIS_OS_NAME" == "osx" && "$TRAVIS_BUILD_STAGE_NAME" != "test" ]]; then
brew install ccache
export PATH="/usr/local/opt/ccache/libexec:$PATH" export PATH="/usr/local/opt/ccache/libexec:$PATH"
export CFLAGS="$CFLAGS -Wno-parentheses-equality" export CFLAGS="$CFLAGS -Wno-parentheses-equality"
fi fi
...@@ -313,7 +315,8 @@ jobs: ...@@ -313,7 +315,8 @@ jobs:
# Run dnspython with coverage enabled, it's implemented in python whereas ares is C. # Run dnspython with coverage enabled, it's implemented in python whereas ares is C.
# PyPy is supported. # PyPy is supported.
- &test-dnspython-jobs - &test-dnspython-jobs
script: GEVENT_RESOLVER=dnspython python -mgevent.tests --coverage --ignore tests_that_dont_use_resolver.txt script:
- GEVENT_RESOLVER=dnspython python -mgevent.tests --coverage --ignore tests_that_dont_use_resolver.txt
name: dnspython resolver (Python 2.7) name: dnspython resolver (Python 2.7)
# Now test the alternate backends, starting with libuv-cffi, which should be present everywhere # Now test the alternate backends, starting with libuv-cffi, which should be present everywhere
- &test-libuv-jobs - &test-libuv-jobs
......
On Python 2, the dnspython resolver can be used without having
selectors2 installed. Previously, an ImportError would be raised.
...@@ -40,9 +40,15 @@ if [ -d /gevent -a -d /opt/python ]; then ...@@ -40,9 +40,15 @@ if [ -d /gevent -a -d /opt/python ]; then
# Running inside docker # Running inside docker
# Set a cache directory for pip. This was # Set a cache directory for pip. This was
# mounted to be the same as it is outside docker # mounted to be the same as it is outside docker so it
# can be persisted.
# XXX: This works for macOS, where everything bind-mounted
# is seen as owned by root in the container. But when the host is Linux
# the actual UIDs come through to the container, triggering
# pip to disable the cache when it detects that the owner doesn't match.
export XDG_CACHE_HOME="/cache" export XDG_CACHE_HOME="/cache"
ls -ld /cache ls -ld /cache
ls -ld /cache/pip
yum -y install libffi-devel ccache yum -y install libffi-devel ccache
# On Fedora Rawhide (F33) # On Fedora Rawhide (F33)
# yum install python39 python3-devel gcc kernel-devel kernel-headers make diffutils file # yum install python39 python3-devel gcc kernel-devel kernel-headers make diffutils file
......
...@@ -38,8 +38,31 @@ MAPPING = { ...@@ -38,8 +38,31 @@ MAPPING = {
'gevent.contextvars': 'contextvars', 'gevent.contextvars': 'contextvars',
} }
OPTIONAL_STDLIB_MODULES = frozenset() if PY3 else frozenset([
'selectors2',
])
_PATCH_PREFIX = '__g_patched_module_' _PATCH_PREFIX = '__g_patched_module_'
def _collect_stdlib_gevent_modules():
"""
Return a map from standard library name to
imported gevent module that provides the same API.
Optional modules are skipped if they cannot be imported.
"""
result = {}
for gevent_name, stdlib_name in iteritems(MAPPING):
try:
result[stdlib_name] = importlib.import_module(gevent_name)
except ImportError:
if stdlib_name in OPTIONAL_STDLIB_MODULES:
continue
raise
return result
class _SysModulesPatcher(object): class _SysModulesPatcher(object):
def __init__(self, importing, extra_all=lambda mod_name: ()): def __init__(self, importing, extra_all=lambda mod_name: ()):
...@@ -49,11 +72,7 @@ class _SysModulesPatcher(object): ...@@ -49,11 +72,7 @@ class _SysModulesPatcher(object):
# green modules, replacing regularly imported modules. # green modules, replacing regularly imported modules.
# This begins as the gevent list of modules, and # This begins as the gevent list of modules, and
# then gets extended with green things from the tree we import. # then gets extended with green things from the tree we import.
self._green_modules = { self._green_modules = _collect_stdlib_gevent_modules()
stdlib_name: importlib.import_module(gevent_name)
for gevent_name, stdlib_name
in iteritems(MAPPING)
}
## Transient, reset each time we're called. ## Transient, reset each time we're called.
# The set of things imported before we began. # The set of things imported before we began.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment