Skip to content

Commit 0d8b4e4

Browse files
authored
Replace os with pathlib where paths are used (#1984)
1 parent 6aded4b commit 0d8b4e4

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

images/base-notebook/jupyter_server_config.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import stat
66
import subprocess
7+
from pathlib import Path
78

89
from jupyter_core.paths import jupyter_data_dir
910

@@ -24,15 +25,14 @@
2425
[req_distinguished_name]
2526
"""
2627
if "GEN_CERT" in os.environ:
27-
dir_name = jupyter_data_dir()
28-
pem_file = os.path.join(dir_name, "notebook.pem")
29-
os.makedirs(dir_name, exist_ok=True)
28+
dir_name = Path(jupyter_data_dir())
29+
dir_name.mkdir(parents=True, exist_ok=True)
30+
pem_file = dir_name / "notebook.pem"
3031

3132
# Generate an openssl.cnf file to set the distinguished name
32-
cnf_file = os.path.join(os.getenv("CONDA_DIR", "/usr/lib"), "ssl", "openssl.cnf")
33-
if not os.path.isfile(cnf_file):
34-
with open(cnf_file, "w") as fh:
35-
fh.write(OPENSSL_CONFIG)
33+
cnf_file = Path(os.getenv("CONDA_DIR", "/usr/lib")) / "ssl/openssl.cnf"
34+
if not cnf_file.exists():
35+
cnf_file.write_text(OPENSSL_CONFIG)
3636

3737
# Generate a certificate if one doesn't exist on disk
3838
subprocess.check_call(
@@ -50,8 +50,8 @@
5050
]
5151
)
5252
# Restrict access to the file
53-
os.chmod(pem_file, stat.S_IRUSR | stat.S_IWUSR)
54-
c.ServerApp.certfile = pem_file
53+
pem_file.chmod(stat.S_IRUSR | stat.S_IWUSR)
54+
c.ServerApp.certfile = str(pem_file)
5555

5656
# Change default umask for all subprocesses of the Server if set in the environment
5757
if "NB_UMASK" in os.environ:

tests/scipy-notebook/data/matplotlib/matplotlib_1.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Matplotlib: Create a simple plot example.
22
# Refs: https://matplotlib.org/stable/gallery/lines_bars_and_markers/simple_plot.html
33

4-
import os
5-
64
# Optional test with [Matplotlib Jupyter Integration](https://github.com/matplotlib/ipympl)
75
# %matplotlib widget
86
import matplotlib.pyplot as plt
@@ -21,7 +19,8 @@
2119
title="About as simple as it gets, folks",
2220
)
2321
ax.grid()
22+
2423
# Note that the test can be run headless by checking if an image is produced
25-
file_path = os.path.join("/tmp", "test.png")
24+
file_path = "/tmp/test.png"
2625
fig.savefig(file_path)
2726
print(f"File {file_path} saved")

tests/scipy-notebook/data/matplotlib/matplotlib_fonts_1.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# Matplotlib: Test tex fonts
2-
import os
3-
42
import matplotlib
53
import matplotlib.pyplot as plt
64

@@ -22,6 +20,6 @@
2220
ax.plot(x, y, label="a label")
2321
ax.legend(fontsize=15)
2422

25-
file_path = os.path.join("/tmp", "test_fonts.png")
23+
file_path = "/tmp/test_fonts.png"
2624
fig.savefig(file_path)
2725
print(f"File {file_path} saved")

0 commit comments

Comments
 (0)