Skip to content

Commit

Permalink
Merge branch 'release/0.7.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-blanchard committed Dec 16, 2013
2 parents 3b4fdd9 + 1b818e5 commit e74a37f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 16 deletions.
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ License
Changelog
~~~~~~~~~

- v0.7.3

- Fix a couple crashes when certain functions that expect ``str`` were passed
integers.

- v0.7.2

- Fix a couple inconsistencies with ``str`` vs ``bytes`` in Python 3 in
Expand Down
20 changes: 13 additions & 7 deletions drmaa/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
drmaa_version, STRING)


# Python 3 compatability help
if sys.version_info < (3, 0):
bytes = str
str = unicode


_BUFLEN = ATTR_BUFFER


Expand All @@ -54,10 +60,10 @@ class BoolConverter(object):
"""Helper class to convert to/from bool attributes."""

def __init__(self, true=b'y', false=b'n'):
if not isinstance(true, bytes):
if isinstance(true, str):
true = true.encode()
self.true = true
if not isinstance(false, bytes):
if isinstance(false, str):
false = false.encode()
self.false = false

Expand Down Expand Up @@ -132,15 +138,15 @@ def __init__(self, name, type_converter=None):
a converter to translate attribute values to/from the underlying
implementation. See BoolConverter for an example.
"""
if not isinstance(name, bytes):
if isinstance(name, str):
name = name.encode()
self.name = name
self.converter = type_converter

def __set__(self, instance, value):
if self.converter:
v = self.converter.to_drmaa(value)
elif not isinstance(value, bytes):
elif isinstance(value, str):
v = value.encode()
else:
v = value
Expand All @@ -167,7 +173,7 @@ class VectorAttribute(object):
"""

def __init__(self, name):
if not isinstance(name, bytes):
if isinstance(name, str):
name = name.encode()
self.name = name

Expand All @@ -188,7 +194,7 @@ class DictAttribute(object):
"""

def __init__(self, name):
if not isinstance(name, bytes):
if isinstance(name, str):
name = name.encode()
self.name = name

Expand Down Expand Up @@ -290,7 +296,7 @@ def string_vector(v):
vlen = len(v)
values = (STRING * (vlen + 1))()
for i, el in enumerate(v):
values[i] = STRING(el.encode() if not isinstance(el, bytes) else el)
values[i] = STRING(el.encode() if isinstance(el, str) else el)
values[vlen] = STRING()
return values

Expand Down
21 changes: 14 additions & 7 deletions drmaa/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from __future__ import absolute_import, print_function, unicode_literals

import sys
from collections import namedtuple
from ctypes import byref, c_int, create_string_buffer, pointer, POINTER, sizeof

Expand Down Expand Up @@ -50,6 +51,12 @@
py_drmaa_exit, py_drmaa_init)


# Python 3 compatability help
if sys.version_info < (3, 0):
bytes = str
str = unicode


JobInfo = namedtuple("JobInfo",
"""jobId hasExited hasSignal terminatedSignal hasCoreDump
wasAborted exitStatus resourceUsage""")
Expand Down Expand Up @@ -368,8 +375,8 @@ def control(jobId, operation):
jobs submitted by other DRMAA session in other DRMAA implementations
or jobs submitted via native utilities.
"""
if not isinstance(jobId, bytes):
jobId = jobId.encode()
if isinstance(jobId, str):
jobId = jobId.encode()
c(drmaa_control, jobId, string_to_control_action(operation))

# takes string list, num value and boolean, no return value
Expand Down Expand Up @@ -453,9 +460,9 @@ def wait(jobId, timeout=-1):
stat = c_int()
jid_out = create_string_buffer(128)
rusage = pointer(POINTER(drmaa_attr_values_t)())
if not isinstance(jobId, bytes):
jobId = jobId.encode()
c(drmaa_wait, jobId, jid_out, sizeof(jid_out), byref(stat), timeout,
if isinstance(jobId, str):
jobId = jobId.encode()
c(drmaa_wait, jobId, jid_out, sizeof(jid_out), byref(stat), timeout,
rusage)
res_usage = adapt_rusage(rusage)
exited = c_int()
Expand Down Expand Up @@ -501,8 +508,8 @@ def jobStatus(jobId):
jobs return a FAILED status.
"""
status = c_int()
if not isinstance(jobId, bytes):
jobId = jobId.encode()
if isinstance(jobId, str):
jobId = jobId.encode()
c(drmaa_job_ps, jobId, byref(status))
return status_to_string(status.value)

Expand Down
2 changes: 1 addition & 1 deletion drmaa/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
:author: Dan Blanchard ([email protected])
'''

__version__ = '0.7.2'
__version__ = '0.7.3'
VERSION = tuple(int(x) for x in __version__.split('.'))
10 changes: 9 additions & 1 deletion drmaa/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,20 @@
from __future__ import absolute_import, print_function, unicode_literals

import os
import sys
from ctypes import (c_char_p, c_int, c_long, c_size_t, c_uint, c_ulong, CDLL,
POINTER, RTLD_GLOBAL, sizeof, Structure)
from ctypes.util import find_library

from drmaa.errors import error_check, error_buffer


# Python 3 compatability help
if sys.version_info < (3, 0):
bytes = str
str = unicode


# the name of the OS environment variable optionally
# containing the full path to the drmaa library
_drmaa_lib_env_name = 'DRMAA_LIBRARY_PATH'
Expand Down Expand Up @@ -59,7 +67,7 @@


def py_drmaa_init(contact=None):
if not isinstance(contact, bytes) and contact is not None:
if isinstance(contact, str):
contact = contact.encode()
return _lib.drmaa_init(contact, error_buffer, sizeof(error_buffer))

Expand Down

0 comments on commit e74a37f

Please sign in to comment.