Skip to content

Commit 43c9e24

Browse files
authored
Merge pull request #131 from ShikharJ/PEP8
Formatted .py files according to PEP8 guidelines
2 parents a2c292d + 2d311ce commit 43c9e24

20 files changed

+394
-183
lines changed

setup.py

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import os
44
import subprocess
55
import sys
6+
from distutils.command.build_ext import build_ext as _build_ext
7+
from distutils.command.build import build as _build
68

79
# Make sure the system has the right Python version.
810
if sys.version_info[:2] < (2, 7):
9-
print("SymEngine requires Python 2.7 or newer. Python %d.%d detected" % sys.version_info[:2])
11+
print("SymEngine requires Python 2.7 or newer. "
12+
"Python %d.%d detected" % sys.version_info[:2])
1013
sys.exit(-1)
1114

1215
# use setuptools by default as per the official advice at:
@@ -18,12 +21,9 @@
1821
if use_distutils.lower() == 'true':
1922
use_setuptools = False
2023
else:
21-
print("Value {} for USE_DISTUTILS treated as False".\
24+
print("Value {} for USE_DISTUTILS treated as False".
2225
format(use_distutils))
2326

24-
from distutils.command.build_ext import build_ext as _build_ext
25-
from distutils.command.build import build as _build
26-
2727
if use_setuptools:
2828
try:
2929
from setuptools import setup
@@ -35,30 +35,37 @@
3535
from distutils.core import setup
3636
from distutils.command.install import install as _install
3737

38-
cmake_opts = [("PYTHON_BIN", sys.executable), ("CMAKE_INSTALL_RPATH_USE_LINK_PATH", "yes")]
38+
cmake_opts = [("PYTHON_BIN", sys.executable),
39+
("CMAKE_INSTALL_RPATH_USE_LINK_PATH", "yes")]
3940
cmake_generator = [None]
4041
cmake_build_type = ["Release"]
4142

43+
4244
def process_opts(opts):
4345
return ['-D'+'='.join(o) for o in opts]
4446

47+
4548
def get_build_dir(dist):
4649
source_dir = path.dirname(path.realpath(__file__))
4750
build = dist.get_command_obj('build')
4851
build_ext = dist.get_command_obj('build_ext')
4952
return source_dir if build_ext.inplace else build.build_platlib
5053

54+
5155
global_user_options = [
52-
('symengine-dir=', None, 'path to symengine installation or build directory'),
56+
('symengine-dir=', None,
57+
'path to symengine installation or build directory'),
5358
('generator=', None, 'cmake build generator'),
5459
('build-type=', None, 'build type: Release or Debug'),
5560
('define=', 'D',
5661
'options to cmake <var>:<type>=<value>'),
5762
]
5863

64+
5965
class BuildWithCmake(_build):
6066
sub_commands = [('build_ext', None)]
6167

68+
6269
class BuildExtWithCmake(_build_ext):
6370
_build_opts = _build_ext.user_options
6471
user_options = list(global_user_options)
@@ -98,22 +105,25 @@ def cmake_build(self):
98105
if build_dir != source_dir and path.exists("CMakeCache.txt"):
99106
os.remove("CMakeCache.txt")
100107

101-
cmake_cmd = ["cmake", source_dir, "-DCMAKE_BUILD_TYPE=" + cmake_build_type[0]]
108+
cmake_cmd = ["cmake", source_dir,
109+
"-DCMAKE_BUILD_TYPE=" + cmake_build_type[0]]
102110
cmake_cmd.extend(process_opts(cmake_opts))
103111
if not path.exists(path.join(build_dir, "CMakeCache.txt")):
104112
cmake_cmd.extend(self.get_generator())
105113
if subprocess.call(cmake_cmd, cwd=build_dir) != 0:
106114
raise EnvironmentError("error calling cmake")
107115

108-
if subprocess.call(["cmake", "--build", ".", "--config", cmake_build_type[0]],
109-
cwd=build_dir) != 0:
116+
if subprocess.call(["cmake", "--build", ".",
117+
"--config", cmake_build_type[0]],
118+
cwd=build_dir) != 0:
110119
raise EnvironmentError("error building project")
111120

112121
def get_generator(self):
113122
if cmake_generator[0]:
114123
return ["-G", cmake_generator[0]]
115124
else:
116-
import platform, sys
125+
import platform
126+
import sys
117127
if (platform.system() == "Windows"):
118128
compiler = str(self.compiler).lower()
119129
if ("msys" in compiler):
@@ -128,9 +138,11 @@ def get_generator(self):
128138

129139
def run(self):
130140
self.cmake_build()
131-
# can't use super() here because _build_ext is an old style class in 2.7
141+
# can't use super() here because
142+
# _build_ext is an old style class in 2.7
132143
_build_ext.run(self)
133144

145+
134146
class InstallWithCmake(_install):
135147
_install_opts = _install.user_options
136148
user_options = list(global_user_options)
@@ -157,7 +169,8 @@ def finalize_options(self):
157169

158170
cmake_build_type[0] = self.build_type
159171
cmake_opts.extend([('PYTHON_INSTALL_PATH', self.install_platlib)])
160-
cmake_opts.extend([('PYTHON_INSTALL_HEADER_PATH', self.install_headers)])
172+
cmake_opts.extend([('PYTHON_INSTALL_HEADER_PATH',
173+
self.install_headers)])
161174

162175
def cmake_install(self):
163176
source_dir = path.dirname(path.realpath(__file__))
@@ -170,8 +183,10 @@ def cmake_install(self):
170183
if subprocess.call(cmake_cmd, cwd=build_dir) != 0:
171184
raise EnvironmentError("error calling cmake")
172185

173-
if subprocess.call(["cmake", "--build", ".", "--config", cmake_build_type[0], "--target", "install"],
174-
cwd=build_dir) != 0:
186+
if subprocess.call(["cmake", "--build", ".",
187+
"--config", cmake_build_type[0],
188+
"--target", "install"],
189+
cwd=build_dir) != 0:
175190
raise EnvironmentError("error installing")
176191

177192
import compileall
@@ -182,24 +197,25 @@ def run(self):
182197
_install.run(self)
183198
self.cmake_install()
184199

200+
185201
long_description = '''
186202
SymEngine is a standalone fast C++ symbolic manipulation library.
187203
Optional thin Python wrappers (SymEngine) allow easy usage from Python and
188204
integration with SymPy and Sage.'''
189205

190-
setup(name = "symengine",
206+
setup(name="symengine",
191207
version="0.2.1.dev",
192-
description = "Python library providing wrappers to SymEngine",
193-
setup_requires = ['cython>=0.19.1'],
194-
long_description = long_description,
195-
author = "SymEngine development team",
196-
author_email = "[email protected]",
197-
license = "MIT",
198-
url = "https://github.com/symengine/symengine.py",
208+
description="Python library providing wrappers to SymEngine",
209+
setup_requires=['cython>=0.19.1'],
210+
long_description=long_description,
211+
author="SymEngine development team",
212+
author_email="[email protected]",
213+
license="MIT",
214+
url="https://github.com/symengine/symengine.py",
199215
cmdclass={
200-
'build' : BuildWithCmake,
201-
'build_ext' : BuildExtWithCmake,
202-
'install' : InstallWithCmake,
216+
'build': BuildWithCmake,
217+
'build_ext': BuildExtWithCmake,
218+
'install': InstallWithCmake,
203219
},
204220
classifiers=[
205221
'License :: OSI Approved :: MIT License',
@@ -213,4 +229,4 @@ def run(self):
213229
'Programming Language :: Python :: 3.4',
214230
'Programming Language :: Python :: 3.5',
215231
]
216-
)
232+
)

symengine/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
__version__ = "0.2.1.dev"
1818

19+
1920
def test():
20-
import pytest, os
21+
import pytest
22+
import os
2123
return not pytest.cmdline.main(
2224
[os.path.dirname(os.path.abspath(__file__))])

symengine/sympy_compat.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
from .compatibility import with_metaclass
44
from .lib.symengine_wrapper import (sympify, sympify as S,
55
SympifyError, sqrt, I, E, pi, Matrix, Derivative, exp,
6-
Lambdify as lambdify, symarray, diff, zeros, eye, diag, ones, zeros,
6+
Lambdify as lambdify, symarray, diff, eye, diag, ones, zeros,
77
expand, Subs, FunctionSymbol as AppliedUndef)
8+
from types import ModuleType
9+
import sys
810

911

1012
class BasicMeta(type):
@@ -21,6 +23,7 @@ class Number(Basic):
2123
_classes = (symengine.Number,)
2224
pass
2325

26+
2427
class Symbol(symengine.PySymbol, Basic):
2528
_classes = (symengine.Symbol,)
2629
pass
@@ -29,7 +32,7 @@ class Symbol(symengine.PySymbol, Basic):
2932
class Rational(Number):
3033
_classes = (symengine.Rational, symengine.Integer)
3134

32-
def __new__(cls, num, den = 1):
35+
def __new__(cls, num, den=1):
3336
return symengine.Integer(num) / den
3437

3538

@@ -68,10 +71,7 @@ def __new__(cls, name):
6871
return symengine.UndefFunction(name)
6972

7073

71-
from types import ModuleType
72-
7374
functions = ModuleType(__name__ + ".functions")
74-
import sys
7575
sys.modules[functions.__name__] = functions
7676

7777
functions.sqrt = sqrt
@@ -94,7 +94,7 @@ class _RegisteredFunction(with_metaclass(_FunctionRegistrarMeta, Function)):
9494
class log(_RegisteredFunction):
9595
_classes = (symengine.Log,)
9696

97-
def __new__(cls, a, b = E):
97+
def __new__(cls, a, b=E):
9898
return symengine.log(a, b)
9999

100100

@@ -118,6 +118,7 @@ class tan(_RegisteredFunction):
118118
def __new__(cls, a):
119119
return symengine.tan(a)
120120

121+
121122
class gamma(_RegisteredFunction):
122123
_classes = (symengine.Gamma,)
123124

@@ -250,6 +251,7 @@ class atan2(_RegisteredFunction):
250251
def __new__(cls, a, b):
251252
return symengine.atan2(a, b)
252253

254+
253255
'''
254256
for i in ("""Sin Cos Tan Gamma Cot Csc Sec ASin ACos ATan
255257
ACot ACsc ASec Sinh Cosh Tanh Coth ASinh ACosh ATanh

symengine/tests/test_arit.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from symengine import Symbol, Integer, Add, Pow
44

5+
56
def test_arit1():
67
x = Symbol("x")
78
y = Symbol("y")
@@ -12,6 +13,7 @@ def test_arit1():
1213
e = x + 1
1314
e = 1 + x
1415

16+
1517
def test_arit2():
1618
x = Symbol("x")
1719
y = Symbol("y")
@@ -26,11 +28,13 @@ def test_arit2():
2628
assert not x+x == 3*x
2729
assert not x+x != 2*x
2830

31+
2932
def test_arit3():
3033
x = Symbol("x")
3134
y = Symbol("y")
3235
raises(TypeError, lambda: ("x"*x))
3336

37+
3438
def test_arit4():
3539
x = Symbol("x")
3640
y = Symbol("y")
@@ -39,6 +43,7 @@ def test_arit4():
3943
assert x*x*x == x**3
4044
assert x*y*x*x == x**3*y
4145

46+
4247
def test_arit5():
4348
x = Symbol("x")
4449
y = Symbol("y")
@@ -50,6 +55,7 @@ def test_arit5():
5055
assert f == x**2 + 2*x*y + y**2
5156
assert isinstance(f, Add)
5257

58+
5359
def test_arit6():
5460
x = Symbol("x")
5561
y = Symbol("y")
@@ -62,6 +68,7 @@ def test_arit6():
6268
e = 2*x
6369
assert str(e) == "2*x"
6470

71+
6572
def test_arit7():
6673
x = Symbol("x")
6774
y = Symbol("y")
@@ -72,6 +79,7 @@ def test_arit7():
7279

7380
assert 2*x*y - x*y == x*y
7481

82+
7583
def test_arit8():
7684
x = Symbol("x")
7785
y = Symbol("y")
@@ -85,6 +93,7 @@ def test_arit8():
8593
assert (2 * x**3 * y**2 * z)**3 / 8 == x**9 * y**6 * z**3
8694
assert (2*y**(-2*x**2)) * (3*y**(2*x**2)) == 6
8795

96+
8897
def test_expand1():
8998
x = Symbol("x")
9099
y = Symbol("y")
@@ -94,22 +103,26 @@ def test_expand1():
94103
assert ((2*x**2+3*y)**2).expand() == 4*x**4 + 12*x**2*y + 9*y**2
95104
assert ((2*x/3+y/4)**2).expand() == 4*x**2/9 + x*y/3 + y**2/16
96105

106+
97107
def test_arit9():
98108
x = Symbol("x")
99109
y = Symbol("y")
100110
assert 1/x == 1/x
101111
assert 1/x != 1/y
102112

113+
103114
def test_expand2():
104115
y = Symbol("y")
105116
z = Symbol("z")
106117
assert ((1/(y*z) - y*z)*y*z).expand() == 1-(y*z)**2
107118

119+
108120
def test_expand3():
109121
x = Symbol("x")
110122
y = Symbol("y")
111123
assert ((1/(x*y) - x*y+2)*(1+x*y)).expand() == 3 + 1/(x*y) + x*y - (x*y)**2
112124

125+
113126
def test_args():
114127
x = Symbol("x")
115128
y = Symbol("y")
@@ -119,6 +132,7 @@ def test_args():
119132
assert (2*x**2).args == (2, x**2)
120133
assert set((2*x**2*y).args) == set((Integer(2), x**2, y))
121134

135+
122136
def test_atoms():
123137
x = Symbol("x")
124138
y = Symbol("y")
@@ -128,6 +142,7 @@ def test_atoms():
128142
assert (x ** y + z).atoms() == set([x, y, z])
129143
assert (x**y + z).atoms(Symbol) == set([x, y, z])
130144

145+
131146
def test_free_symbols():
132147
x = Symbol("x")
133148
y = Symbol("y")

symengine/tests/test_dict_basic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from symengine import symbols, DictBasic, sin, Integer
44

5+
56
def test_DictBasic():
67
x, y, z = symbols("x y z")
78
d = DictBasic({x: 2, y: z})
@@ -24,4 +25,4 @@ def test_DictBasic():
2425
assert set(d.values()) == set([x, z])
2526

2627
e = y + sin(2*z)
27-
assert e.subs(d) == z + sin(x)
28+
assert e.subs(d) == z + sin(x)

0 commit comments

Comments
 (0)