Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Commit

Permalink
Python 3.7 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
vxgmichel committed Jul 24, 2018
1 parent 444c1a1 commit 1a29786
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ env:
- PYTHON_VERSION=3.7

cache:
timeout: 300
directories:
- ./miniconda # Conda environment
- ./.eggs # pytest eggs
Expand Down Expand Up @@ -44,6 +45,7 @@ install:
- conda install --yes boost gxx_linux-64
- conda install --yes -c tango-controls tango=$TANGO_VERSION
- conda install --yes numpy # Not a strong requirement yet
- conda install --yes gevent # Temporary fix for gevent issue #1260
# Use conda prefix as root for the dependencies
- export BOOST_ROOT=$CONDA_PREFIX TANGO_ROOT=$CONDA_PREFIX ZMQ_ROOT=$CONDA_PREFIX OMNI_ROOT=$CONDA_PREFIX

Expand Down
30 changes: 18 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
# See LICENSE.txt for more info.
# ------------------------------------------------------------------------------

# pylint: disable=deprecated-method

import os
import imp
import sys
import runpy
import struct
import platform
import subprocess

from setuptools import setup, Extension
Expand All @@ -25,6 +26,12 @@
from distutils.unixccompiler import UnixCCompiler
from distutils.version import LooseVersion as V

# Distro import
try:
from pip._vendor import distro
except ImportError:
import platform as distro

# Sphinx imports
try:
import sphinx
Expand All @@ -44,12 +51,12 @@
POSIX = 'posix' in os.name
WINDOWS = 'nt' in os.name
IS64 = 8 * struct.calcsize("P") == 64
PYTHON_VERSION = platform.python_version_tuple()
PYTHON2 = ('2',) <= PYTHON_VERSION < ('3',)
PYTHON3 = ('3',) <= PYTHON_VERSION < ('4',)
PYTHON_VERSION = sys.version_info
PYTHON2 = (2,) <= PYTHON_VERSION < (3,)
PYTHON3 = (3,) <= PYTHON_VERSION < (4,)

# Linux distribution
distribution = platform.linux_distribution()[0].lower() if POSIX else ""
distribution = distro.linux_distribution()[0].lower() if POSIX else ""
distribution_match = lambda names: any(x in distribution for x in names)
DEBIAN = distribution_match(['debian', 'ubuntu', 'mint'])
REDHAT = distribution_match(['redhat', 'fedora', 'centos', 'opensuse'])
Expand Down Expand Up @@ -94,11 +101,10 @@ def abspath(*path):


def get_release_info():
name = "release"
release_dir = abspath('tango')
data = imp.find_module(name, [release_dir])
release = imp.load_module(name, *data)
return release.Release
namespace = runpy.run_path(
abspath('tango/release.py'),
run_name='tango.release')
return namespace['Release']


def uniquify(seq):
Expand Down Expand Up @@ -465,9 +471,9 @@ def setup_args():
'Programming Language :: C',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Topic :: Scientific/Engineering',
'Topic :: Software Development :: Libraries',
]
Expand Down
5 changes: 1 addition & 4 deletions tango/asyncio_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@

__all__ = ("AsyncioExecutor", "get_global_executor", "set_global_executor")

# Asyncio compatibility

ensure_future = getattr(asyncio, 'ensure_future', getattr(asyncio, 'async'))

# Global executor

Expand Down Expand Up @@ -74,7 +71,7 @@ def delegate(self, fn, *args, **kwargs):
"""Return the given operation as an asyncio future."""
callback = functools.partial(fn, *args, **kwargs)
coro = self.loop.run_in_executor(self.subexecutor, callback)
return ensure_future(coro)
return asyncio.ensure_future(coro)

def access(self, accessor, timeout=None):
"""Return a result from an asyncio future."""
Expand Down
2 changes: 1 addition & 1 deletion tango/asyncio_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def run_coroutine_threadsafe(coro, loop):

def callback():
try:
_chain_future(asyncio.async(coro, loop=loop), future)
_chain_future(asyncio.ensure_future(coro, loop=loop), future)
except Exception as exc:
if future.set_running_or_notify_cancel():
future.set_exception(exc)
Expand Down
8 changes: 7 additions & 1 deletion tango/gevent_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,15 @@ def access(self, accessor, timeout=None):
"""Return a result from an gevent future."""
return accessor.get(timeout=timeout)

def create_watcher(self):
try:
return self.loop.async_()
except AttributeError:
return getattr(self.loop, 'async')()

def submit(self, fn, *args, **kwargs):
task = GeventTask(fn, *args, **kwargs)
watcher = self.loop.async()
watcher = self.create_watcher()
watcher.start(task.spawn)
watcher.send()
task.started.wait()
Expand Down

0 comments on commit 1a29786

Please sign in to comment.