Skip to content

Commit c82c509

Browse files
author
Release Manager
committed
gh-38644: pathlib in simplicial sets examples use `pathlib.Path` instead of `os` in the modified file plus a few pep8 changes there ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. URL: #38644 Reported by: Frédéric Chapoton Reviewer(s): Kwankyu Lee
2 parents 94741f9 + dda7e93 commit c82c509

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

src/sage/topology/simplicial_set_examples.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# ****************************************************************************
3131

3232
import re
33-
import os
33+
from pathlib import Path
3434

3535
from sage.env import SAGE_ENV
3636
from sage.misc.cachefunc import cached_method, cached_function
@@ -48,6 +48,8 @@
4848
from sage.misc.lazy_import import lazy_import
4949
lazy_import('sage.categories.simplicial_sets', 'SimplicialSets')
5050

51+
kenzo_path = Path(SAGE_ENV['SAGE_EXTCODE']) / 'kenzo'
52+
5153

5254
# ######################################################################
5355
# The nerve of a finite monoid, used in sage.categories.finite_monoid.
@@ -96,7 +98,7 @@ def __init__(self, monoid):
9698
# of monoid elements). Omit the base point.
9799
self._simplex_data = ()
98100

99-
def __eq__(self, other):
101+
def __eq__(self, other) -> bool:
100102
"""
101103
Return ``True`` if ``self`` and ``other`` are equal.
102104
@@ -119,7 +121,7 @@ def __eq__(self, other):
119121
and self._monoid == other._monoid
120122
and self.base_point() == other.base_point())
121123

122-
def __ne__(self, other):
124+
def __ne__(self, other) -> bool:
123125
"""
124126
Return the negation of `__eq__`.
125127
@@ -214,13 +216,13 @@ def n_skeleton(self, n):
214216
face_dict[(g,)] = x
215217
start = 1
216218

217-
for d in range(start+1, n+1):
219+
for d in range(start + 1, n + 1):
218220
for g in monoid:
219221
if g == one:
220222
continue
221223
new_faces = {}
222224
for t in face_dict.keys():
223-
if len(t) != d-1:
225+
if len(t) != d - 1:
224226
continue
225227
# chain: chain of group elements to multiply,
226228
# as a tuple.
@@ -235,8 +237,8 @@ def n_skeleton(self, n):
235237

236238
# Compute faces of x.
237239
faces = [face_dict[chain[1:]]]
238-
for i in range(d-1):
239-
product = chain[i] * chain[i+1]
240+
for i in range(d - 1):
241+
product = chain[i] * chain[i + 1]
240242
if product == one:
241243
# Degenerate.
242244
if d == 2:
@@ -294,11 +296,11 @@ def Sphere(n):
294296
w_0 = AbstractSimplex(0, name='w_0')
295297
return SimplicialSet_finite({v_0: None, w_0: None}, base_point=v_0,
296298
name='S^0')
297-
degens = range(n-2, -1, -1)
299+
degens = range(n - 2, -1, -1)
298300
degen_v = v_0.apply_degeneracies(*degens)
299301
sigma = AbstractSimplex(n, name='sigma_{}'.format(n),
300302
latex_name='\\sigma_{}'.format(n))
301-
return SimplicialSet_finite({sigma: [degen_v] * (n+1)}, base_point=v_0,
303+
return SimplicialSet_finite({sigma: [degen_v] * (n + 1)}, base_point=v_0,
302304
name='S^{}'.format(n),
303305
latex_name='S^{{{}}}'.format(n))
304306

@@ -616,22 +618,20 @@ def ComplexProjectiveSpace(n):
616618
latex_name='CP^{2}')
617619
return K
618620
if n == 3:
619-
file = os.path.join(SAGE_ENV['SAGE_EXTCODE'], 'kenzo', 'CP3.txt')
621+
file = kenzo_path / 'CP3.txt'
620622
data = simplicial_data_from_kenzo_output(file)
621-
v = [_ for _ in data.keys() if _.dimension() == 0][0]
622-
K = SimplicialSet_finite(data, base_point=v, name='CP^3',
623-
latex_name='CP^{3}')
624-
return K
623+
v = [sigma for sigma in data if sigma.dimension() == 0][0]
624+
return SimplicialSet_finite(data, base_point=v, name='CP^3',
625+
latex_name='CP^{3}')
625626
if n == 4:
626-
file = os.path.join(SAGE_ENV['SAGE_EXTCODE'], 'kenzo', 'CP4.txt')
627+
file = kenzo_path / 'CP4.txt'
627628
data = simplicial_data_from_kenzo_output(file)
628-
v = [_ for _ in data.keys() if _.dimension() == 0][0]
629-
K = SimplicialSet_finite(data, base_point=v, name='CP^4',
630-
latex_name='CP^{4}')
631-
return K
629+
v = [sigma for sigma in data if sigma.dimension() == 0][0]
630+
return SimplicialSet_finite(data, base_point=v, name='CP^4',
631+
latex_name='CP^{4}')
632632

633633

634-
def simplicial_data_from_kenzo_output(filename):
634+
def simplicial_data_from_kenzo_output(filename) -> dict:
635635
"""
636636
Return data to construct a simplicial set, given Kenzo output.
637637
@@ -649,7 +649,8 @@ def simplicial_data_from_kenzo_output(filename):
649649
650650
sage: from sage.topology.simplicial_set_examples import simplicial_data_from_kenzo_output
651651
sage: from sage.topology.simplicial_set import SimplicialSet
652-
sage: sphere = os.path.join(SAGE_ENV['SAGE_EXTCODE'], 'kenzo', 'S4.txt')
652+
sage: from pathlib import Path
653+
sage: sphere = Path(SAGE_ENV['SAGE_EXTCODE']) / 'kenzo' /'S4.txt'
653654
sage: S4 = SimplicialSet(simplicial_data_from_kenzo_output(sphere)) # needs pyparsing
654655
sage: S4.homology(reduced=False) # needs pyparsing
655656
{0: Z, 1: 0, 2: 0, 3: 0, 4: Z}
@@ -667,7 +668,7 @@ def simplicial_data_from_kenzo_output(filename):
667668
dim_idx = data.find('Dimension = {}:'.format(dim), start)
668669
while dim_idx != -1:
669670
start = dim_idx + len('Dimension = {}:'.format(dim))
670-
new_dim_idx = data.find('Dimension = {}:'.format(dim+1), start)
671+
new_dim_idx = data.find('Dimension = {}:'.format(dim + 1), start)
671672
if new_dim_idx == -1:
672673
end = len(data)
673674
else:

0 commit comments

Comments
 (0)