Skip to content

Commit 2380bb1

Browse files
committed
Use pathlib in context manager for working directory, see #70
1 parent 5bcd468 commit 2380bb1

File tree

1 file changed

+7
-6
lines changed
  • mkdocs_git_authors_plugin

1 file changed

+7
-6
lines changed

mkdocs_git_authors_plugin/ci.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
import os
1010
from contextlib import contextmanager
1111
import logging
12-
12+
from pathlib import Path
13+
from typing import Union
1314
from mkdocs_git_authors_plugin.git.command import GitCommand
1415

1516

1617
@contextmanager
17-
def working_directory(path):
18+
def working_directory(path: Union[str, Path]):
1819
"""
1920
Temporarily change working directory.
2021
A context manager which changes the working directory to the given
@@ -26,13 +27,13 @@ def working_directory(path):
2627
# Do something in new directory
2728
# Back to old directory
2829
```
29-
"""
30-
prev_cwd = os.getcwd()
31-
os.chdir(str(path))
30+
"""
31+
origin = Path().absolute()
3232
try:
33+
os.chdir(path)
3334
yield
3435
finally:
35-
os.chdir(prev_cwd)
36+
os.chdir(origin)
3637

3738

3839
def raise_ci_warnings(path: str) -> None:

0 commit comments

Comments
 (0)