Skip to content

Commit

Permalink
update setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
koehlma committed Nov 30, 2015
1 parent 7767aea commit 45e2927
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 106 deletions.
36 changes: 19 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

with open(os.path.join(__dir__, 'uv', '__init__.py'), 'rb') as init_py:
init_source = init_py.read().decode('utf-8')

match = re.search(r'__version__ = \'(.+?)\'', init_source)
version = match.group(1)

Expand All @@ -73,13 +74,11 @@
with open(os.path.join(__dir__, 'cffi_declarations.c'), 'rb') as cffi_declarations:
declarations = cffi_declarations.read().decode('utf-8')

cffi_module = 'cffi_template.py'

with open(os.path.join(__dir__, cffi_module), 'rb') as cffi_template:
cffi_code = cffi_template.read().decode('utf-8').format(**locals())
with open(os.path.join(__dir__, 'cffi_template.py'), 'rb') as cffi_template:
uvcffi_code = cffi_template.read().decode('utf-8').format(**locals())

with open(os.path.join(__dir__, 'uvcffi', '__init__.py'), 'wb') as uvcffi_module:
uvcffi_module.write(cffi_code.encode('utf-8'))
uvcffi_module.write(uvcffi_code.encode('utf-8'))


ffi = cffi.FFI()
Expand Down Expand Up @@ -123,20 +122,20 @@ def build_environ():
environ = dict(os.environ)

if sys.platform == 'win32':
if os.environ.get('APPVEYOR', None) == 'True':
if os.environ.get('SET_SDK', None) == 'Y':
environ.pop('VS140COMNTOOLS', None)
environ.pop('VS120COMNTOOLS', None)
environ.pop('VS110COMNTOOLS', None)
if sys.version_info < (3, 3):
environ.pop('VS100COMNTOOLS', None)
environ['GYP_MSVS_VERSION'] = '2008'
else:
environ['GYP_MSVS_VERSION'] = '2010'
if os.environ.get('SET_SDK', None) == 'Y':
environ.pop('VS140COMNTOOLS', None)
environ.pop('VS120COMNTOOLS', None)
environ.pop('VS110COMNTOOLS', None)
if sys.version_info < (3, 3):
environ.pop('VS100COMNTOOLS', None)
environ['GYP_MSVS_VERSION'] = '2008'
else:
environ['GYP_MSVS_VERSION'] = '2010'
environ['PYTHON'] = win32_find_python27()
else:
if 'CFLAGS' not in environ: environ['CFLAGS'] = ''
environ['CFLAGS'] += ' -fPIC'

return environ


Expand Down Expand Up @@ -177,7 +176,7 @@ def clean_libuv():


def clean_build():
log.info('cleaning Build...')
log.info('cleaning build...')
shutil.rmtree(DEPS_PATH)


Expand Down Expand Up @@ -275,6 +274,9 @@ def get_inidata(self):
return bdist_wininst.get_inidata(self)


cmdclass['bdist_wininst'] = WindowsInstaller


if bdist_msi is not None:
class WindowsMSI(bdist_msi):
def run(self):
Expand All @@ -283,9 +285,9 @@ def run(self):
self.distribution.metadata.version)
self.distribution.metadata.version = cleaned.group(0)
bdist_msi.run(self)

cmdclass['bdist_msi'] = WindowsMSI

cmdclass['bdist_wininst'] = WindowsInstaller

setup(name='uv',
version=version,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def test_close(self):
self.assertRaises(uv.LoopClosedError, uv.TTY, 0, loop=self.loop)
self.assertRaises(uv.LoopClosedError, uv.UDP, loop=self.loop)

'''
def test_current_loop(self):
self.assertEqual(uv.Loop.default_loop(), uv.Loop.current_loop())
Expand Down Expand Up @@ -180,6 +181,7 @@ def main2():
thread1.join()
self.assertEqual(uv.Loop.default_loop(), uv.Loop.current_loop())
'''

def test_update_time(self):
def on_prepare(prepare):
Expand Down
4 changes: 2 additions & 2 deletions uv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
from .library import version as uv_version

from .error import UVError, HandleClosedError, LoopClosedError, StatusCode
from .handle import Handle, handles, close_all_handles
from .loop import RunMode, Loop, loops
from .handle import Handle
from .loop import RunMode, Loop
from .request import Request
from .stream import Stream, ShutdownRequest, ConnectRequest, WriteRequest

Expand Down
64 changes: 24 additions & 40 deletions uv/handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
from .error import UVError, HandleClosedError, LoopClosedError
from .loop import Loop

__all__ = ['close_all_handles', 'Handle']

handles = set()
__all__ = ['Handle']


class HandleType(enum.IntEnum):
Expand Down Expand Up @@ -56,31 +54,20 @@ def __call__(self, cls):
@ffi.callback('uv_close_cb')
def uv_close_cb(uv_handle):
handle = detach(uv_handle)
with handle.loop.callback_context:
handle.on_closed(handle)
with handle.loop.callback_context: handle.on_closed(handle)
handle.destroy()


def close_all_handles(on_closed=None):
"""
Close all handles which have not yet been closed.
:param on_closed: callback called after a handle has been closed
:type on_closed: (Handle) -> None
"""
for handle in handles: handle.close(on_closed)


@HandleType.UNKNOWN
@HandleType.HANDLE
class Handle(object):
"""
Handles represent long-lived objects capable of performing certain
operations while active. This is the base class of all handles.
:raises uv.LoopClosedError: loop has already been closed or is closing
:raises uv.LoopClosedError: loop has already been closed
:param loop: loop where the handle should run on
:param uv_handle: allocated c struct for this handle
:param uv_handle: allocated c struct for this handle (used internally)
:type loop: Loop
:type uv_handle: ffi.CData
"""
Expand All @@ -90,14 +77,13 @@ class Handle(object):
def __init__(self, uv_handle, loop=None):
self.uv_handle = ffi.cast('uv_handle_t*', uv_handle)
self.attachment = attach(self.uv_handle, self)
self.loop = loop or Loop.current_loop()
self.loop = loop or Loop.get_current()
"""
Loop where the handle is running on.
:readonly: True
:type: Loop
"""
if self.loop.closed: raise LoopClosedError()
self.on_closed = dummy_callback
"""
Callback which should be called after the handle has been closed.
Expand All @@ -107,20 +93,24 @@ def __init__(self, uv_handle, loop=None):
"""
self.closed = False
"""
Handle has been closed. This is `True` right after the
close callback has been called.
Handle has been closed. This is `True` right after the close callback
has been called. It means all internal resources are freed and this
handle is ready to be garbage collected.
:readonly: True
:type: bool
"""
self.closing = False
"""
Handle is already closed or is closing.
Handle is already closed or is closing. This is `True` right after
close has been called. Operations on a closed or closing handle will
raise :class:`uv.HandleClosedError`.
:readonly: True
:type: bool
"""
handles.add(self)
if self.loop.closed: raise LoopClosedError()
self.loop.handles.add(self)

@property
def active(self):
Expand All @@ -134,7 +124,7 @@ def active(self):
involves IO like reading, writing, connecting or listening
- :class:`uv.Check`, :class:`uv.Idle`, :class:`uv.Timer`, ...: handle
is active when it has been started
is active when it has been started and not yet stopped
:readonly: True
:type: bool
Expand All @@ -146,8 +136,8 @@ def active(self):
def referenced(self):
"""
Handle is referenced or not. If the event loop runs in default mode it
will exit when there are no more active and referenced handles left.
This has nothing to do with CPython's reference counting.
will exit when there are no more active and referenced handles left. This
has nothing to do with CPython's reference counting.
:readonly: False
:type: bool
Expand Down Expand Up @@ -178,7 +168,7 @@ def send_buffer_size(self):
and other operating systems. This means, the size set is divided by
two on Linux because Linux internally multiplies it by two.
:raises uv.UVError: error while getting the send buffer size
:raises uv.UVError: error while getting/setting the send buffer size
:raises uv.HandleClosedError: handle has already been closed or is closing
:readonly: False
:type: int
Expand All @@ -192,7 +182,7 @@ def send_buffer_size(self):
@send_buffer_size.setter
def send_buffer_size(self, size):
"""
:raises uv.UVError: error while setting the send buffer size
:raises uv.UVError: error while getting/setting the send buffer size
:raises uv.HandleClosedError: handle has already been closed or is closing
:param size: size of the send buffer
:type size: int
Expand All @@ -216,7 +206,7 @@ def receive_buffer_size(self):
and other operating systems. This means, the size set is divided by
two on Linux because Linux internally multiplies it by two.
:raises uv.UVError: error while getting the receive buffer size
:raises uv.UVError: error while getting/setting the receive buffer size
:raises uv.HandleClosedError: handle has already been closed or is closing
:readonly: False
:type: int
Expand All @@ -230,7 +220,7 @@ def receive_buffer_size(self):
@receive_buffer_size.setter
def receive_buffer_size(self, size):
"""
:raises uv.UVError: error while setting the receive buffer size
:raises uv.UVError: error while getting/setting the receive buffer size
:raises uv.HandleClosedError: handle has already been closed or is closing
:param size: size of the receive buffer
:type size: int
Expand All @@ -247,7 +237,7 @@ def fileno(self):
handles this will raise :class:`uv.UVError` with `StatusCode.EINVAL`.
If a handle does not have an attached file descriptor yet this method
wil raise :class:`uv.UVError` with `StatusCode.EBADF`.
will raise :class:`uv.UVError` with `StatusCode.EBADF`.
.. warning::
Expand Down Expand Up @@ -305,8 +295,8 @@ def close(self, on_closed=None):
:class:`uv.WriteRequest`, are cancelled and have their callbacks
called asynchronously with :class:`StatusCode.ECANCELED`
After a handle has been closed no other operations can be performed
on it, they will raise :class:`uv.HandleClosedError`.
After this method has been called on a handle no other operations can be
performed on it, they will raise :class:`uv.HandleClosedError`.
:param on_closed: callback called after the handle has been closed
:type on_closed: (Handle) -> None
Expand All @@ -325,11 +315,5 @@ def destroy(self):
after the handle has been closed. You should never call it directly!
"""
self.uv_handle = None
handles.remove(self)
self.closed = True

# pyuv compatibility
ref = referenced
"""
Same as `referenced` for pyuv compatibility.
"""
self.loop.handles.remove(self)

0 comments on commit 45e2927

Please sign in to comment.