Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bench/basic_micro.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import cppyy, gc, math, os, psutil, time
import cppyy
import gc
import math
import os
import psutil
import time

NLARGE = 20000000

Expand Down
4 changes: 2 additions & 2 deletions bench/bench_functioncalls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import py, pytest, os, sys, math, warnings
import sys
import warnings
from support import setup_make

setup_make("functioncallsDict.so")
Expand All @@ -9,7 +10,6 @@
cppyy.load_library("functioncalls")
cppyy.load_library("functioncallsDict")

import py_functioncalls

all_configs = [('py', 'py_functioncalls'), ('cppyy', 'cppyy.gbl')]

Expand Down
2 changes: 1 addition & 1 deletion bench/bench_runvector.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import py, pytest, os, sys, math, warnings
import warnings
from support import setup_make

setup_make("runvectorDict.so")
Expand Down
3 changes: 2 additions & 1 deletion bench/py_runvector.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import array, sys
import array
import sys

N = 100000000 # 10^8

Expand Down
4 changes: 3 additions & 1 deletion bench/support.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import print_function
import py, sys, subprocess
import py
import sys
import subprocess

currpath = py.path.local(__file__).dirpath()

Expand Down
3 changes: 0 additions & 3 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import os
import shlex

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
5 changes: 3 additions & 2 deletions doc/tutorial/GSLPythonizationTutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"outputs": [],
"source": [
"# first, pull in all headers from the GSL installation directory (/usr/include on my system).\n",
"import glob, os\n",
"import glob\n",
"import os\n",
"GSL_HOME = '/usr/include'\n",
"gsl_headers = [os.path.relpath(x, GSL_HOME) for x in glob.glob(GSL_HOME+'/gsl/*.h')]"
]
Expand Down Expand Up @@ -100,7 +101,7 @@
"rfldct = 'GSLDict'\n",
"\n",
"if not os.path.exists('%s_rflx.cpp' % rfldct):\n",
" import subprocess, sys\n",
" import subprocess\n",
"\n",
" # generate the reflection dictionary\n",
" try:\n",
Expand Down
15 changes: 10 additions & 5 deletions python/cppyy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@

from ._version import __version__

import ctypes, os, sys, sysconfig, warnings
import ctypes
import os
import sys
import sysconfig
import warnings

if not 'CLING_STANDARD_PCH' in os.environ:
if 'CLING_STANDARD_PCH' not in os.environ:
def _set_pch():
try:
import cppyy_backend as cpb
Expand Down Expand Up @@ -177,7 +181,7 @@ def __getitem__(self, cls):
return py_make_smartptr(cls, self.ptrcls)
except AttributeError:
pass
if type(cls) == str and not cls in ('int', 'float'):
if type(cls) == str and cls not in ('int', 'float'):
return py_make_smartptr(getattr(gbl, cls), self.ptrcls)
return self.maker[cls]

Expand Down Expand Up @@ -206,7 +210,7 @@ def cppdef(src):
with _stderr_capture() as err:
errcode = gbl.Cpp.Declare(src)
if not errcode == 0 or err.err:
if 'warning' in err.err.lower() and not 'error' in err.err.lower():
if 'warning' in err.err.lower() and 'error' not in err.err.lower():
warnings.warn(err.err, SyntaxWarning)
return True
raise SyntaxError('Failed to parse the given C++ code%s' % err.err)
Expand Down Expand Up @@ -316,7 +320,8 @@ def add_library_path(path):

apipath_extra = os.path.join(os.path.dirname(apipath), 'site', 'python'+ldversion)
if not os.path.exists(os.path.join(apipath_extra, 'CPyCppyy')):
import glob, libcppyy
import glob
import libcppyy
ape = os.path.dirname(libcppyy.__file__)
# a "normal" structure finds the include directory up to 3 levels up,
# ie. dropping lib/pythonx.y[md]/site-packages
Expand Down
7 changes: 5 additions & 2 deletions python/cppyy/__pyinstaller/hook-cppyy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@


def _backend_files():
import cppyy_backend, glob, os
import cppyy_backend
import glob
import os

all_files = glob.glob(os.path.join(
os.path.dirname(cppyy_backend.__file__), '*'))
Expand All @@ -19,7 +21,8 @@ def datafile(path):
return [datafile(filename) for filename in all_files if os.path.isdir(filename)]

def _api_files():
import cppyy, os
import cppyy
import os

# FIXME: We should add an interface in InterOp.
paths = str(cppyy.gbl.runtime.gCling.GetIncludePath()).split('-I')
Expand Down
5 changes: 2 additions & 3 deletions python/cppyy/_cpython_cppyy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
""" CPython-specific touch-ups
"""

from . import _stdcpp_fix
from cppyy_backend import loader

__all__ = [
Expand Down Expand Up @@ -92,7 +91,7 @@ def __getitem__(self, *args):
self._instantiations[args] = pyclass

# special case pythonization (builtin_map is not available from the C-API)
if 'push_back' in pyclass.__dict__ and not '__iadd__' in pyclass.__dict__:
if 'push_back' in pyclass.__dict__ and '__iadd__' not in pyclass.__dict__:
if 'reserve' in pyclass.__dict__:
def iadd(self, ll):
self.reserve(len(ll))
Expand Down Expand Up @@ -196,7 +195,7 @@ def load_reflection_info(name):
name = name + ".so"
result = CppInterOp.LoadLibrary(name)
if name.endswith("Dict.so"):
header = name[:-7] + ".h";
header = name[:-7] + ".h"
CppInterOp.Declare('#include "' + header +'"')

if result == False:
Expand Down
5 changes: 2 additions & 3 deletions python/cppyy/_pypy_cppyy.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
""" PyPy-specific touch-ups
"""

from . import _stdcpp_fix

import os, sys
import os
import sys
from cppyy_backend import loader

__all__ = [
Expand Down Expand Up @@ -46,7 +46,6 @@ def fixup_legacy():


#- exports -------------------------------------------------------------------
import sys
_thismodule = sys.modules[__name__]
for name in __all__:
try:
Expand Down
3 changes: 2 additions & 1 deletion python/cppyy/_typemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def initialize(backend):
# void*
import ctypes
def voidp_init(self, arg=0):
import cppyy, ctypes
import cppyy
import ctypes
if arg == cppyy.nullptr: arg = 0
ctypes.c_void_p.__init__(self, arg)
tm['void*'] = _create_mapper(ctypes.c_void_p, {'__init__' : voidp_init})
3 changes: 2 additions & 1 deletion python/cppyy/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def __init__(self, hook_okay):
self._hook_okay = hook_okay

def __getattr__(self, attr):
import cppyy, sys
import cppyy
import sys
if attr == '__all__':
# copy all exported items from cppyy itself
for v in cppyy.__all__:
Expand Down
1 change: 0 additions & 1 deletion python/cppyy/numba_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import cppyy.types as cpp_types
import cppyy.reflex as cpp_refl

import numba
import numba.extending as nb_ext
import numba.core.cgutils as nb_cgu
import numba.core.datamodel as nb_dm
Expand Down
8 changes: 5 additions & 3 deletions python/cppyy_compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"""

def pypy58_57_compat():
import imp, os
import imp
import os

# first load and move the builtin cppyy module
if not 'cppyy' in sys.modules:
if 'cppyy' not in sys.modules:
try:
olddir = os.getcwd()
from cppyy_backend import loader
Expand Down Expand Up @@ -43,7 +44,8 @@ def pypy58_57_compat():
# for pypy5.9 we may need to move to the location of the backend, if '.' happens
# to be in LD_LIBRARY_PATH, but not the full directory
def py59_compat():
import os, cppyy_backend
import os
import cppyy_backend
olddir = os.getcwd()
c = cppyy_backend.loader.load_cpp_backend()
os.chdir(os.path.dirname(c._name))
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import codecs, glob, os, sys, re
from setuptools import setup, find_packages, Extension
import codecs
import os
import sys
import re
from setuptools import setup, find_packages
from distutils import log

from setuptools.command.install import install as _install
Expand Down
5 changes: 3 additions & 2 deletions test/bindexplib.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from __future__ import print_function

import os, sys, subprocess
import sys
import subprocess

target = sys.argv[1]
output = sys.argv[2]

def isokay(name):
# filter standard symbols
return name[0] != '_' and not name in {'memcpy', 'memmove', 'memset'}
return name[0] != '_' and name not in {'memcpy', 'memmove', 'memset'}

popen = subprocess.Popen(['dumpbin', '/SYMBOLS', target+'.obj'],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
Expand Down
8 changes: 5 additions & 3 deletions test/make_dict_win32.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import glob, os, sys, subprocess
import glob
import os
import sys
import subprocess

USES_PYTHON_CAPI = set(('pythonizables',))

Expand All @@ -24,7 +27,7 @@

if os.path.exists(fn+'Dict.dll'):
dct_time = os.stat(fn+'Dict.dll').st_mtime
if not '-f' in sys.argv:
if '-f' not in sys.argv:
mustbuild = False
for ext in ['.h', '.cxx', '.xml']:
if os.stat(fn+ext).st_mtime > dct_time:
Expand Down Expand Up @@ -86,7 +89,6 @@ def get_python_lib_dir():
if os.system(BUILDOBJ_CMD):
sys.exit(1)

import cppyy_backend
CREATEDEF_CMD = "python bindexplib.py {fn} {fn}Dict".format(fn=fn)
if os.system(CREATEDEF_CMD):
sys.exit(1)
Expand Down
5 changes: 4 additions & 1 deletion test/support.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from __future__ import print_function
import os, py, sys, subprocess
import os
import py
import sys
import subprocess

currpath = py.path.local(__file__).dirpath()

Expand Down
3 changes: 1 addition & 2 deletions test/test_aclassloader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import py, os, sys
from pytest import raises, mark
import py
from .support import setup_make

currpath = py.path.local(__file__).dirpath()
Expand Down
20 changes: 10 additions & 10 deletions test/test_advancedcpp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import py, os, sys
import py
from pytest import raises, skip, mark
from .support import setup_make, pylong, IS_WINDOWS, IS_MAC, IS_LINUX, ispypy, IS_CLANG_REPL, IS_MAC_ARM, IS_MAC_X86
from .support import setup_make, pylong, IS_WINDOWS, IS_MAC, ispypy, IS_CLANG_REPL, IS_MAC_ARM

currpath = py.path.local(__file__).dirpath()
test_dct = str(currpath.join("advancedcppDict"))
Expand Down Expand Up @@ -192,8 +192,8 @@ def test04_template_types(self):
assert gbl.T1 is gbl.T1
assert gbl.T2 is gbl.T2
assert gbl.T3 is gbl.T3
assert not gbl.T1 is gbl.T2
assert not gbl.T2 is gbl.T3
assert gbl.T1 is not gbl.T2
assert gbl.T2 is not gbl.T3

assert gbl.T1('int') is gbl.T1('int')
assert gbl.T1(int) is gbl.T1('int')
Expand Down Expand Up @@ -472,19 +472,19 @@ def test10_object_identity(self):
assert o is o2

o3 = cppyy.bind_object(addr, some_class_with_data)
assert not o is o3
assert o is not o3

d1 = some_class_with_data()
d2 = d1.gime_copy()
assert not d1 is d2
assert d1 is not d2

dd1a = d1.gime_data()
dd1b = d1.gime_data()
assert dd1a is dd1b

dd2 = d2.gime_data()
assert not dd1a is dd2
assert not dd1b is dd2
assert dd1a is not dd2
assert dd1b is not dd2

d2.__destruct__()
d1.__destruct__()
Expand Down Expand Up @@ -568,7 +568,7 @@ def test12_actual_type(self):
b1 = cppyy.bind_object(voidp, base_class)
assert isinstance(b1, base_class)
assert cppyy.addressof(b1) == cppyy.addressof(d)
assert not (b1 is d)
assert b1 is not d

def test13_actual_type_virtual_multi(self):
"""Test auto-downcast in adverse inheritance situation"""
Expand Down Expand Up @@ -754,7 +754,7 @@ def test23_using(self):
assert cppyy.gbl.UsingBase1().vcheck() == 'A'

D1 = cppyy.gbl.UsingDerived1
assert not 'UsingBase1' in D1.__init__.__doc__
assert 'UsingBase1' not in D1.__init__.__doc__

d1a = D1()
assert d1a.m_int == 13
Expand Down
7 changes: 3 additions & 4 deletions test/test_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import py, os, sys
from pytest import raises, skip, mark
from pytest import skip, mark
from .support import ispypy, IS_MAC, IS_LINUX_ARM


Expand Down Expand Up @@ -188,12 +187,12 @@ class APICheck4Executor : public CPyCppyy::Executor {
a4 = cppyy.gbl.CreateAPICheck4()
assert a4
assert type(a4) == cppyy.gbl.APICheck4
assert a4.wasExecutorCalled();
assert a4.wasExecutorCalled()
del a4

cppyy.gbl.unregister_a4()

a4 = cppyy.gbl.CreateAPICheck4b()
assert a4
assert type(a4) == cppyy.gbl.APICheck4
assert not a4.wasExecutorCalled();
assert not a4.wasExecutorCalled()
Loading
Loading