Skip to content

Commit

Permalink
Merge pull request #43 from kivy/py3
Browse files Browse the repository at this point in the history
Support for Python 3
  • Loading branch information
tito committed Nov 8, 2018
2 parents 4aa2338 + 24db50f commit e73f361
Show file tree
Hide file tree
Showing 20 changed files with 662 additions and 496 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ install:
fi;

- source env/bin/activate;
- pip install --upgrade cython nose
- pip install --upgrade cython pytest
- make test_lib

script:
Expand Down
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build_ext test
.PHONY: build_ext test all

build_ext:
env CFLAGS="-O0" python setup.py build_ext --inplace -g
Expand All @@ -8,8 +8,18 @@ test_lib:
clang objc_classes/test/testlib.m -o objc_classes/test/testlib.dylib -dynamiclib -framework Foundation

tests: build_ext
cd tests && env PYTHONPATH=..:$(PYTHONPATH) nosetests -v
cd tests && env PYTHONPATH=..:$(PYTHONPATH) pytest -v

html:
$(MAKE) -C docs html

distclean:
rm -rf .pytest_cache
rm -rf build
rm -rf pyobjus/config.pxi
rm -rf pyobjus/pyobjus.c
rm -rf pyobjus/*.so
rm -rf pyobjus/*.pyc
rm -rf pyobjus/__pycache__

all: build_ext
2 changes: 1 addition & 1 deletion pyobjus/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from pyobjus import *
from .pyobjus import *
7 changes: 3 additions & 4 deletions pyobjus/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def dprint(*args, **kwargs):

of_type = kwargs.get('of_type', 'd')

print "[{0}]".format(debug_types[of_type]),
for argument in args:
print "{0}".format(argument),
print ''
print("[{}] {}".format(
debug_types[of_type],
" ".join([repr(arg) for arg in args])))
15 changes: 7 additions & 8 deletions pyobjus/dylib_manager.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import os
import ctypes
import pyobjus
from subprocess import call
from objc_py_types import enum
from debug import dprint
try:
from subprocess import call
except:
call = None
from .objc_py_types import enum
from .debug import dprint

def load_dylib(path, **kwargs):
''' Function for loading dynamic library with ctypes
Expand All @@ -20,11 +23,7 @@ def load_dylib(path, **kwargs):
# LOADING USER DEFINED CLASS (dylib) FROM /objc_classes/test/ DIR #
usr_path = kwargs.get('usr_path', True)
if not usr_path:
if os.getcwd().split('/')[-1] != 'pyobjus':
os.chdir('..')
while os.getcwd().split('/')[-1] != 'pyobjus':
os.chdir('..')
root_pyobjus = os.getcwd()
root_pyobjus = os.path.join(os.path.dirname(__file__), "..")
objc_test_dir = os.path.join(root_pyobjus, 'objc_classes', 'test')
ctypes.CDLL(os.path.join(objc_test_dir, path))
else:
Expand Down
1 change: 0 additions & 1 deletion pyobjus/ffi.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ cdef extern from "ffi/ffi.h":
unsigned short alignment
unsigned short type
ffi_type **elements
ctypedef ffi_type ffi_type

cdef ffi_type ffi_type_void
cdef ffi_type ffi_type_uint8
Expand Down
2 changes: 1 addition & 1 deletion pyobjus/objc_cy_types.pxi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from debug import dprint
from .debug import dprint

cdef extern from "CoreFoundation/CoreFoundation.h":

Expand Down
30 changes: 18 additions & 12 deletions pyobjus/objc_py_types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import ctypes
import itertools
from ctypes import Structure
from pyobjus import signature_types_to_list, dev_platform
from .pyobjus import signature_types_to_list, dev_platform
from .debug import dprint

########## NS STRUCT TYPES ##########

Expand Down Expand Up @@ -126,11 +127,11 @@ def getMembers(self, *args, **kwargs):
if members_cpy is not None and len(members_cpy) > self.field_name_ind:
field_name = members_keys[self.field_name_ind]

if _type.find('=') is not -1:
if _type.find(b'=') >= 0:
type_obj = _type[1:-1].split('=', 1)
if type_obj[0] is '?':
if type_obj[0] == b'?':
if not field_name:
# TODO: This is temporary solution. Find more efficient solution for this!
# TODO: This is temporary solution. Find more efficient solution for this!
while True:
field_name, letter, perm_n, perms = self._generate_variable_name(letter, perm_n, perms)
if field_name not in [x for x, y in field_list]:
Expand Down Expand Up @@ -166,14 +167,19 @@ def find_object(self, obj_type, members=None):
Returns:
Requested type
'''
if obj_type[0] in globals():
return globals()[obj_type[0]]
elif obj_type in types.keys():
return types[obj_type]
else:
#if len(cached_unknown_type):
# return cached_unknown_type[0]
return self.make_type(obj_type, members=members)
obj_name = obj_type[0]
if isinstance(obj_name, bytes):
obj_name = obj_name.decode("utf-8")
if obj_name in globals():
return globals()[obj_name]
try:
if obj_type in types.keys():
return types[obj_type]
except TypeError:
pass
#if len(cached_unknown_type):
# return cached_unknown_type[0]
return self.make_type(obj_type, members=members)

def empty_cache(self):
pass
Expand Down

0 comments on commit e73f361

Please sign in to comment.