Skip to main content

Switch from import pathlib to from pathlib import Path

ID
b37068a
date
2025-01-28 07:30:06+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
4c335fa
message
Switch from `import pathlib` to `from pathlib import Path`

For https://github.com/alexwlchan/alexwlchan/issues/20
changed files
7 files, 18 additions, 18 deletions

Changed files

cog_helpers.py (3118) → cog_helpers.py (3120)

diff --git a/cog_helpers.py b/cog_helpers.py
index 9dbc8a4..d747cce 100644
--- a/cog_helpers.py
+++ b/cog_helpers.py
@@ -8,7 +8,7 @@ https://nedbatchelder.com/code/cog
 """
 
 import os
-import pathlib
+from pathlib import Path
 import textwrap
 from typing import TypedDict
 
@@ -49,7 +49,7 @@ def create_description_table(
     if ignore_files is None:
         ignore_files = set()
 
-    folder = pathlib.Path(folder_name)
+    folder = Path(folder_name)
 
     for f in ignore_files:
         if not (folder / f).exists():

images/save_xkcd.py (1117) → images/save_xkcd.py (1119)

diff --git a/images/save_xkcd.py b/images/save_xkcd.py
index 014114e..61cad61 100755
--- a/images/save_xkcd.py
+++ b/images/save_xkcd.py
@@ -8,13 +8,13 @@ many already exist) but to create a mini-library of my personal favourites.
 
 import json
 import os
-import pathlib
+from pathlib import Path
 import sys
 from urllib.request import urlretrieve
 
 import httpx
 
-BACKUP_ROOT = pathlib.Path("/Volumes/Media (Sapphire)/backups/xkcd")
+BACKUP_ROOT = Path("/Volumes/Media (Sapphire)/backups/xkcd")
 
 
 if __name__ == "__main__":

images/squarify.py (1046) → images/squarify.py (1048)

diff --git a/images/squarify.py b/images/squarify.py
index 5472b49..85c40bb 100755
--- a/images/squarify.py
+++ b/images/squarify.py
@@ -3,7 +3,7 @@
 Creates a square crop of an image.
 """
 
-import pathlib
+from pathlib import Path
 import sys
 
 from PIL import Image
@@ -11,7 +11,7 @@ from PIL import Image
 
 if __name__ == '__main__':
     try:
-        path = pathlib.Path(sys.argv[1])
+        path = Path(sys.argv[1])
     except IndexError:
         sys.exit(f"Usage: {__file__} IMAGE_PATH")
     

images/test_srgbify.py (2665) → images/test_srgbify.py (2667)

diff --git a/images/test_srgbify.py b/images/test_srgbify.py
index 790ec75..8e5ccaf 100644
--- a/images/test_srgbify.py
+++ b/images/test_srgbify.py
@@ -1,5 +1,5 @@
 import filecmp
-import pathlib
+from pathlib import Path
 
 from PIL import Image
 
@@ -66,7 +66,7 @@ def test_it_converts_images_with_a_grey_profile():
     assert new_im.mode == "RGB"
 
 
-def test_it_preserves_rotation_from_exif_orientation(tmp_path: pathlib.Path):
+def test_it_preserves_rotation_from_exif_orientation(tmp_path: Path):
     """
     This is based on a photo exported from my Apple Photos Library
     which was rotated by 90 degrees upon transformation.

textexpander/get_mastodon_text.py (2677) → textexpander/get_mastodon_text.py (2679)

diff --git a/textexpander/get_mastodon_text.py b/textexpander/get_mastodon_text.py
index b2c2acc..9a0c9dc 100755
--- a/textexpander/get_mastodon_text.py
+++ b/textexpander/get_mastodon_text.py
@@ -7,7 +7,7 @@ as a blockquote.
 import datetime
 import html
 import os
-import pathlib
+from pathlib import Path
 import re
 import subprocess
 
@@ -15,7 +15,7 @@ import httpx
 import hyperlink
 
 
-ATTACHMENTS_DIR = pathlib.Path.home() / "textfiles" / "Attachments" / "mastodon"
+ATTACHMENTS_DIR = Path.home() / "textfiles" / "Attachments" / "mastodon"
 
 
 def download(url):

web/save_tumblr_likes.py (12359) → web/save_tumblr_likes.py (12345)

diff --git a/web/save_tumblr_likes.py b/web/save_tumblr_likes.py
index 7eeead5..31119d3 100644
--- a/web/save_tumblr_likes.py
+++ b/web/save_tumblr_likes.py
@@ -3,7 +3,7 @@ import errno
 import functools
 import json
 import os
-import pathlib
+from pathlib import Path
 import shutil
 import subprocess
 import sys
@@ -19,7 +19,7 @@ from sqlite_utils.db import NotFoundError
 import termcolor
 
 
-BACKUP_ROOT = pathlib.Path("/Volumes/Media (Sapphire)/backups/tumblr")
+BACKUP_ROOT = Path("/Volumes/Media (Sapphire)/backups/tumblr")
 
 
 def get_liked_posts(blog_identifier: str, days: int):
@@ -87,7 +87,7 @@ def log_result(format_template):
     return decorator
 
 
-def get_saved_blog_name(*, post_id: str, blog_name: str, db_path: pathlib.Path) -> str:
+def get_saved_blog_name(*, post_id: str, blog_name: str, db_path: Path) -> str:
     """
     Look up the blog name associated with this post ID.
 
@@ -355,5 +355,5 @@ if __name__ == "__main__":
         download_tumblr_post(
             post_url=post_data["post_url"],
             post_data=post_data,
-            download_root=pathlib.Path(BACKUP_ROOT),
+            download_root=Path(BACKUP_ROOT),
         )

web/save_youtube_videos.py (5850) → web/save_youtube_videos.py (5836)

diff --git a/web/save_youtube_videos.py b/web/save_youtube_videos.py
index c6f4d46..be37cb0 100755
--- a/web/save_youtube_videos.py
+++ b/web/save_youtube_videos.py
@@ -6,7 +6,7 @@ Make a local copy of one or more YouTube videos.
 import functools
 import json
 import os
-import pathlib
+from pathlib import Path
 import subprocess
 import sys
 import textwrap
@@ -18,7 +18,7 @@ from sqlite_utils.db import NotFoundError
 import termcolor
 
 
-BACKUP_ROOT = pathlib.Path("/Volumes/Media (Sapphire)/backups/youtube/videos")
+BACKUP_ROOT = Path("/Volumes/Media (Sapphire)/backups/youtube/videos")
 
 
 def youtube_dl(*args, **kwargs):
@@ -87,7 +87,7 @@ def log_result(format_template):
 
 
 def classify_file_type(
-    video_id: str, filename: pathlib.Path
+    video_id: str, filename: Path
 ) -> Literal["video", "info", "thumbnail", "subtitles"] | None:
     """
     Given an already-downloaded file, work out what sort of file it is.
@@ -127,7 +127,7 @@ def classify_file_type(
     raise ValueError(f"Unrecognised filename: {filename}")
 
 
-def fix_info_json(path: pathlib.Path) -> None:
+def fix_info_json(path: Path) -> None:
     """
     Tidy up the contents of the info.json fie.
     """