Skip to content

Commit

Permalink
gh-38465: using pathlib.Path around SAGE_EXTCODE
Browse files Browse the repository at this point in the history
    
replacing `os` by the much lighter `pathlib` library in some places

### 📝 Checklist

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
    
URL: #38465
Reported by: Frédéric Chapoton
Reviewer(s): Kwankyu Lee
  • Loading branch information
Release Manager committed Aug 27, 2024
2 parents bd776a3 + 734d91d commit d7837bc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
15 changes: 8 additions & 7 deletions src/sage/features/threejs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# sage_setup: distribution = sagemath-environment
import os
from pathlib import Path

from . import StaticFile

Expand All @@ -26,16 +26,17 @@ def __init__(self):
"""
from sage.env import SAGE_SHARE, THREEJS_DIR

share_dir = Path(SAGE_SHARE)
threejs_search_path = THREEJS_DIR or (
os.path.join(SAGE_SHARE, "jupyter", "nbextensions", "threejs-sage"),
os.path.join(SAGE_SHARE, "sagemath", "threejs-sage"),
os.path.join(SAGE_SHARE, "sage", "threejs"),
os.path.join(SAGE_SHARE, "threejs-sage")
(share_dir / "jupyter" / "nbextensions" / "threejs-sage"),
(share_dir / "sagemath" / "threejs-sage"),
(share_dir / "sage" / "threejs"),
(share_dir / "threejs-sage")
)

try:
version = self.required_version()
filename = os.path.join(version, "three.min.js")
filename = Path(version) / "three.min.js"
except FileNotFoundError:
filename = 'unknown'

Expand Down Expand Up @@ -64,7 +65,7 @@ def required_version(self):
"""
from sage.env import SAGE_EXTCODE

filename = os.path.join(SAGE_EXTCODE, 'threejs', 'threejs-version.txt')
filename = Path(SAGE_EXTCODE) / 'threejs' / 'threejs-version.txt'

with open(filename) as f:
return f.read().strip()
Expand Down
11 changes: 5 additions & 6 deletions src/sage/graphs/graph_plot_js.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@
Functions
---------
"""
from pathlib import Path
from sage.misc.temporary_file import tmp_filename
from sage.misc.lazy_import import lazy_import
import os
lazy_import("sage.plot.colors", "rainbow")

# ****************************************************************************
Expand Down Expand Up @@ -317,13 +317,12 @@ def gen_html_code(G,
"edge_thickness": int(edge_thickness)})

from sage.env import SAGE_EXTCODE, SAGE_SHARE
js_code_file = open(SAGE_EXTCODE + "/graphs/graph_plot_js.html", 'r')
js_code = js_code_file.read().replace("// GRAPH_DATA_HEREEEEEEEEEEE", string)
js_code_file.close()
with open(Path(SAGE_EXTCODE) / "graphs" / "graph_plot_js.html", 'r') as f:
js_code = f.read().replace("// GRAPH_DATA_HEREEEEEEEEEEE", string)

# Add d3.js script depending on whether d3js package is installed.
d3js_filepath = os.path.join(SAGE_SHARE, 'd3js', 'd3.min.js')
if os.path.exists(d3js_filepath):
d3js_filepath = Path(SAGE_SHARE) / 'd3js' / 'd3.min.js'
if d3js_filepath.exists():
with open(d3js_filepath, 'r') as d3js_code_file:
d3js_script = '<script>' + d3js_code_file.read() + '</script>'
else:
Expand Down
8 changes: 4 additions & 4 deletions src/sage/groups/perm_gps/permgroup_named.py
Original file line number Diff line number Diff line change
Expand Up @@ -2794,8 +2794,8 @@ def ramification_module_decomposition_hurwitz_curve(self):

F = self.base_ring()
q = F.order()
libgap.Read(str(Path(SAGE_EXTCODE) / 'gap' / 'joyner' /
'hurwitz_crv_rr_sp.gap'))
libgap.Read(Path(SAGE_EXTCODE) / 'gap' / 'joyner' /
'hurwitz_crv_rr_sp.gap')
mults = libgap.eval(f"ram_module_hurwitz({q})")
return mults.sage()

Expand Down Expand Up @@ -2838,8 +2838,8 @@ def ramification_module_decomposition_modular_curve(self):
raise ValueError("degree must be 2")
F = self.base_ring()
q = F.order()
libgap.Read(str(Path(SAGE_EXTCODE) / 'gap' / 'joyner' /
'modular_crv_rr_sp.gap'))
libgap.Read(Path(SAGE_EXTCODE) / 'gap' / 'joyner' /
'modular_crv_rr_sp.gap')
mults = libgap.eval(f"ram_module_X({q})")
return mults.sage()

Expand Down

0 comments on commit d7837bc

Please sign in to comment.