Skip to content

Commit 4a711c5

Browse files
committed
Replace remaining os.path usage with pathlib across codebase
Modernize all remaining os.path operations to use pathlib.Path for consistency: - sphinx_exercise/__init__.py: Use Path for package/locale directory - sphinx_exercise/post_transforms.py: Use Path.with_suffix('') - sphinx_exercise/translations/_convert.py: Use Path.resolve() This completes the migration to pathlib throughout the codebase, keeping only os.sep in tests where it's appropriate for path separator normalization.
1 parent 4d3db76 commit 4a711c5

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

sphinx_exercise/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
__version__ = "1.0.1"
1111

12-
import os
1312
from pathlib import Path
1413
from typing import Any, Dict, Set, Union, cast
1514
from sphinx.config import Config
@@ -215,9 +214,9 @@ def setup(app: Sphinx) -> Dict[str, Any]:
215214
app.add_css_file("exercise.css")
216215

217216
# add translations
218-
package_dir = os.path.abspath(os.path.dirname(__file__))
219-
locale_dir = os.path.join(package_dir, "translations", "locales")
220-
app.add_message_catalog(MESSAGE_CATALOG_NAME, locale_dir)
217+
package_dir = Path(__file__).parent.resolve()
218+
locale_dir = package_dir / "translations" / "locales"
219+
app.add_message_catalog(MESSAGE_CATALOG_NAME, str(locale_dir))
221220

222221
return {
223222
"version": "builtin",

sphinx_exercise/post_transforms.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import os
1+
from pathlib import Path
2+
23
import sphinx.addnodes as sphinx_nodes
34
from sphinx.transforms.post_transforms import SphinxPostTransform
45
from sphinx.util import logging
@@ -196,7 +197,7 @@ def run(self):
196197
except AttributeError:
197198
docname = self.env.docname # for builder such as JupyterBuilder that don't support current_docname
198199
docpath = self.env.doc2path(docname)
199-
path = os.path.splitext(docpath)[0]
200+
path = str(Path(docpath).with_suffix(""))
200201
msg = f"undefined label: {target_label}"
201202
logger.warning(msg, location=path, color="red")
202203
return

sphinx_exercise/translations/_convert.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
import os
32
from pathlib import Path
43
import subprocess
54

@@ -54,9 +53,9 @@ def convert_json(folder=None):
5453
subprocess.check_call(
5554
[
5655
"msgfmt",
57-
os.path.abspath(path),
56+
str(path.resolve()),
5857
"-o",
59-
os.path.abspath(path.parent / f"{MESSAGE_CATALOG_NAME}.mo"),
58+
str((path.parent / f"{MESSAGE_CATALOG_NAME}.mo").resolve()),
6059
]
6160
)
6261

0 commit comments

Comments
 (0)