Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix and activate E251 pycodestyle check #98

Merged
merged 1 commit into from
Apr 2, 2023
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Run pycodestyle
shell: bash -l {0}
# We currently only check for some warnings. We should enable & fix more of them.
run: pycodestyle --select=E111,E21,E221,E222,E225,E227,E228,E241,E262,E265,E271,E272,E30,E401,E701,E702,E703,E704,E711,E713,E721,W2,W3,W6 python/
run: pycodestyle --select=E111,E21,E221,E222,E225,E227,E228,E241,E251,E262,E265,E271,E272,E30,E401,E701,E702,E703,E704,E711,E713,E721,W2,W3,W6 python/

env:
MAKEFLAGS: -j2
8 changes: 4 additions & 4 deletions python/ptolemy/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ZeroDimensionalComponent(Component):
variety (i.e., Galois conjugate solutions).
"""

def __init__(self, l, p = None):
def __init__(self, l, p=None):
self.dimension = 0
super(ZeroDimensionalComponent, self).__init__(l)

Expand All @@ -24,9 +24,9 @@ class NonZeroDimensionalComponent(Component):
component (witnesses).
"""

def __init__(self, witnesses = [],
dimension = 'unknown', free_variables = None, genus = None,
p = None):
def __init__(self, witnesses=[],
dimension='unknown', free_variables=None, genus=None,
p=None):

if p is not None:
self.dimension = p.dimension
Expand Down
134 changes: 67 additions & 67 deletions python/ptolemy/coordinates.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion python/ptolemy/findLoops.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def images_of_original_generators(coordinate_object, penalties):
if M is None:
raise Exception("Need to have a manifold")

loops = compute_loops_for_generators(M, penalties = penalties)
loops = compute_loops_for_generators(M, penalties=penalties)

return (
[ _evaluate_path(coordinate_object, loop ) for loop in loops ],
Expand Down
48 changes: 24 additions & 24 deletions python/ptolemy/geometricRep.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
def compute_geometric_solution(M, N = 2, numerical = False,
engine = None,
memory_limit = 750000000, directory = None,
prefer_rur = False, data_url = False,
verbose = None):
def compute_geometric_solution(M, N=2, numerical=False,
engine=None,
memory_limit=750000000, directory=None,
prefer_rur=False, data_url=False,
verbose=None):
"""
Given a manifold M, compute the exact or numerical solutions to the
Ptolemy variety (pass numerical = True for numerical solutions). The additional
Expand All @@ -17,19 +17,19 @@ def compute_geometric_solution(M, N = 2, numerical = False,
verbose = (engine == 'retrieve')

obstruction_class = 'all' if N % 2 == 0 else None
varieties = M.ptolemy_variety(N, obstruction_class = obstruction_class)
varieties = M.ptolemy_variety(N, obstruction_class=obstruction_class)

if engine == 'retrieve':
sols = varieties.retrieve_solutions(numerical = numerical,
prefer_rur = prefer_rur,
data_url = data_url,
verbose = verbose)
sols = varieties.retrieve_solutions(numerical=numerical,
prefer_rur=prefer_rur,
data_url=data_url,
verbose=verbose)
else:
sols = varieties.compute_solutions(engine = engine,
numerical = numerical,
memory_limit = memory_limit,
directory = directory,
verbose = verbose)
sols = varieties.compute_solutions(engine=engine,
numerical=numerical,
memory_limit=memory_limit,
directory=directory,
verbose=verbose)

for sol in sols.flatten(3):
if sol.is_geometric():
Expand All @@ -38,11 +38,11 @@ def compute_geometric_solution(M, N = 2, numerical = False,
return None


def retrieve_geometric_solution(M, N = 2,
numerical = False,
prefer_rur = False,
data_url = None,
verbose = True):
def retrieve_geometric_solution(M, N=2,
numerical=False,
prefer_rur=False,
data_url=None,
verbose=True):
"""
Given a manifold M, retrieve the exact or numerical solutions to the
Ptolemy variety (pass numerical = True for numerical solutions). The additional
Expand All @@ -53,7 +53,7 @@ def retrieve_geometric_solution(M, N = 2,

"""

return compute_geometric_solution(M, N, numerical = numerical,
engine = 'retrieve',
prefer_rur = prefer_rur,
data_url = data_url, verbose = verbose)
return compute_geometric_solution(M, N, numerical=numerical,
engine='retrieve',
prefer_rur=prefer_rur,
data_url=data_url, verbose=verbose)
20 changes: 10 additions & 10 deletions python/ptolemy/manifoldMethods.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ def get_generalized_ptolemy_obstruction_classes(manifold, N):
already_seen.add(
tuple([(x * u) % N for x in H2_element]))

return [PtolemyGeneralizedObstructionClass(H2_element, index = index,
N = N, manifold = manifold)
return [PtolemyGeneralizedObstructionClass(H2_element, index=index,
N=N, manifold=manifold)
for index, H2_element
in enumerate(filtered_H2_elements)]

Expand Down Expand Up @@ -172,8 +172,8 @@ def compute_solutions(self, *args, **kwargs):
for p in self ])


def get_ptolemy_variety(manifold, N, obstruction_class = None,
simplify = True, eliminate_fixed_ptolemys = False):
def get_ptolemy_variety(manifold, N, obstruction_class=None,
simplify=True, eliminate_fixed_ptolemys=False):
"""
Generates Ptolemy variety as described in
(1) Garoufalidis, Thurston, Zickert
Expand Down Expand Up @@ -340,8 +340,8 @@ def get_ptolemy_variety(manifold, N, obstruction_class = None,
isinstance(obstruction_class, PtolemyGeneralizedObstructionClass)):
return PtolemyVariety(
manifold, N, obstruction_class,
simplify = simplify,
eliminate_fixed_ptolemys = eliminate_fixed_ptolemys)
simplify=simplify,
eliminate_fixed_ptolemys=eliminate_fixed_ptolemys)

# Will we return a list of obstruction classes versus a list
list_obstruction_classes = False
Expand Down Expand Up @@ -382,8 +382,8 @@ def get_ptolemy_variety(manifold, N, obstruction_class = None,
return PtolemyVarietyList([
PtolemyVariety(
manifold, N, obstruction_class,
simplify = simplify,
eliminate_fixed_ptolemys = eliminate_fixed_ptolemys)
simplify=simplify,
eliminate_fixed_ptolemys=eliminate_fixed_ptolemys)
for obstruction_class in obstruction_classes])

# Otherwise try to interpret obstruction_class as an index
Expand All @@ -393,5 +393,5 @@ def get_ptolemy_variety(manifold, N, obstruction_class = None,
raise Exception("Bad index for obstruction class")

return PtolemyVariety(manifold, N, obstruction_class,
simplify = simplify,
eliminate_fixed_ptolemys = eliminate_fixed_ptolemys)
simplify=simplify,
eliminate_fixed_ptolemys=eliminate_fixed_ptolemys)
12 changes: 6 additions & 6 deletions python/ptolemy/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_simultaneous_smith_normal_form(in1, in2, u0, u1, u2, d1, d2):


def has_full_rank(matrix):
return len(_internal_to_pari(matrix).mattranspose().matker(flag = 1)) == 0
return len(_internal_to_pari(matrix).mattranspose().matker(flag=1)) == 0


def _debug_print_matrix(m):
Expand Down Expand Up @@ -249,14 +249,14 @@ def _inner_product(v1, v2):


def smith_normal_form(m):
u, v, d = _internal_to_pari(m).matsnf(flag = 1)
u, v, d = _internal_to_pari(m).matsnf(flag=1)
return (_pari_to_internal(u),
_pari_to_internal(v),
_pari_to_internal(d))


def _smith_normal_form_with_inverse(m):
u, v, d = _internal_to_pari(m).matsnf(flag = 1)
u, v, d = _internal_to_pari(m).matsnf(flag=1)
return (_pari_to_internal(u**(-1)),
_pari_to_internal(v),
_pari_to_internal(d))
Expand Down Expand Up @@ -300,13 +300,13 @@ def _assert_at_most_one_zero_entry_per_row_or_column(m):


def get_independent_rows(rows, explain_rows,
desired_determinant = None,
sort_rows_key = None):
desired_determinant=None,
sort_rows_key=None):

row_explain_pairs = list(zip(rows, explain_rows))
if sort_rows_key:
row_explain_pairs.sort(
key = (
key=(
lambda row_explain_pair: sort_rows_key(
row_explain_pair[1])))

Expand Down
8 changes: 4 additions & 4 deletions python/ptolemy/numericalSolutionsToGroebnerBasis.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def numerical_solutions_with_one(polys):


class PariPolynomialAndVariables:
def __init__(self, polynomial, variables = None):
def __init__(self, polynomial, variables=None):

if isinstance(polynomial, Polynomial):

Expand All @@ -33,12 +33,12 @@ def get_variable_if_univariate(self):
def substitute(self, var, value):

return PariPolynomialAndVariables(
polynomial = self.pari_polynomial.substpol(var, value),
variables = [ v for v in self.variables if not v == var ])
polynomial=self.pari_polynomial.substpol(var, value),
variables=[ v for v in self.variables if not v == var ])

def get_roots(self):
return self.pari_polynomial.polroots(
precision = 3.4 * pari.get_real_precision())
precision=3.4 * pari.get_real_precision())


def numerical_solutions(polys):
Expand Down
12 changes: 6 additions & 6 deletions python/ptolemy/polynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def variables(self):
"""Return a list containing the variable names."""
return [var[0] for var in self._vars if var[1] > 0]

def degree(self, var = None):
def degree(self, var=None):
"""Return the total degree of this monomial."""
return sum([this_degree
for this_var, this_degree in self._vars
Expand Down Expand Up @@ -267,7 +267,7 @@ def from_variable_name(cls, var):

# constructor takes a tuple of polynomials which are combined

def __init__(self, monomials = ()):
def __init__(self, monomials=()):

# combine monomials with the same variables and exponents
# and bring them into canonical order
Expand Down Expand Up @@ -382,7 +382,7 @@ def __str__(self):

def to_string(self, print_coefficient_method):
s = " ".join([monomial.to_string(print_coefficient_method,
force_print_sign = True)
force_print_sign=True)
for monomial in self._monomials])
if s and s[0] == '+':
return s[1:].lstrip()
Expand Down Expand Up @@ -478,7 +478,7 @@ def is_monic(self):
"""Assert univariance; return True iff this polynomial is monic."""
return self.leading_coefficient() == 1

def get_coefficients(self, conversion_function = lambda x:x):
def get_coefficients(self, conversion_function=lambda x:x):
"""Assert univariance; return the coefficients in degree order."""
assert self.is_univariate()
degree = self.degree()
Expand Down Expand Up @@ -636,7 +636,7 @@ def _storage_type_policy(type_a, type_b):
return type_a


def _operator_type_policy(obj_a, obj_b, op = operator.add):
def _operator_type_policy(obj_a, obj_b, op=operator.add):

try:

Expand Down Expand Up @@ -720,7 +720,7 @@ def debug_print(s):
# pop the top operator from the stack and apply it to the
# two top operands from the stack, repeat as long as there are preceding
# operators left on the stack.
def eval_preceding_operators_on_stack(operator = None):
def eval_preceding_operators_on_stack(operator=None):
while operator_stack:
top_operator = operator_stack[-1]

Expand Down
36 changes: 18 additions & 18 deletions python/ptolemy/processComponents.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ def process_component(py_eval, manifold_thunk, variables,
# process Groebner Basis ???, add to NonZeroDimensionalComponent ???

return NonZeroDimensionalComponent(
witnesses = witnesses,
dimension = dimension,
free_variables = free_variables)
witnesses=witnesses,
dimension=dimension,
free_variables=free_variables)


def process_witnesses(py_eval, manifold_thunk, witnesses_section, for_dimension,
Expand All @@ -110,9 +110,9 @@ def process_solutions_provider(py_eval, manifold_thunk, text, for_dimension,
return SolutionContainer(
coordinates.PtolemyCoordinates(
processRurFile.parse_maple_like_rur(rur_section[0]),
is_numerical = False,
py_eval_section = py_eval,
manifold_thunk = manifold_thunk))
is_numerical=False,
py_eval_section=py_eval,
manifold_thunk=manifold_thunk))

gb_section = processFileBase.find_section(text, "GROEBNER=BASIS")

Expand All @@ -135,14 +135,14 @@ def process_solutions_provider(py_eval, manifold_thunk, text, for_dimension,
term_order = params["TERM=ORDER"].strip().lower()

return PtolemyVarietyPrimeIdealGroebnerBasis(
polys = polys,
term_order = term_order,
size = None,
dimension = 0,
is_prime = True,
free_variables = None,
py_eval = py_eval,
manifold_thunk = manifold_thunk)
polys=polys,
term_order=term_order,
size=None,
dimension=0,
is_prime=True,
free_variables=None,
py_eval=py_eval,
manifold_thunk=manifold_thunk)

rs_rur = processFileBase.find_section(text, "RS=RUR")

Expand All @@ -152,9 +152,9 @@ def process_solutions_provider(py_eval, manifold_thunk, text, for_dimension,
return SolutionContainer(
coordinates.PtolemyCoordinates(
processRurFile.parse_rs_rur(rs_rur[0], variables),
is_numerical = False,
py_eval_section = py_eval,
manifold_thunk = manifold_thunk))
is_numerical=False,
py_eval_section=py_eval,
manifold_thunk=manifold_thunk))

raise Exception("No parsable solution type given: %s..." % text[:100])

Expand All @@ -163,7 +163,7 @@ class SolutionContainer():
def __init__(self, solutions):
self._solutions = solutions

def solutions(self, numerical = False):
def solutions(self, numerical=False):
if numerical:
return self._solutions.numerical()
else:
Expand Down
2 changes: 1 addition & 1 deletion python/ptolemy/processFileBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def get_manifold_thunk(text):
Returned as thunk that evaluates to a snappy manifold.
"""

def get_manifold(text = text):
def get_manifold(text=text):
triangulation_text = utilities.join_long_lines(
find_unique_section(text, "TRIANGULATION"))

Expand Down
Loading