File tree Expand file tree Collapse file tree 1 file changed +24
-3
lines changed
mkdocs_git_authors_plugin Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Original file line number Diff line number Diff line change 77"""
88
99import os
10+ from contextlib import contextmanager
1011import logging
1112
12- from pathlib import Path
1313from mkdocs_git_authors_plugin .git .command import GitCommand
1414
15+ @contextmanager
16+ def working_directory (path ):
17+ """
18+ Temporarily change working directory.
19+ A context manager which changes the working directory to the given
20+ path, and then changes it back to its previous value on exit.
21+ Usage:
22+ ```python
23+ # Do something in original directory
24+ with working_directory('/my/new/path'):
25+ # Do something in new directory
26+ # Back to old directory
27+ ```
28+ """
29+ prev_cwd = os .getcwd ()
30+ os .chdir (str (path ))
31+ try :
32+ yield
33+ finally :
34+ os .chdir (prev_cwd )
35+
1536
1637def raise_ci_warnings (path : str ) -> None :
1738 """
@@ -20,7 +41,7 @@ def raise_ci_warnings(path: str) -> None:
2041 Args:
2142 path (str): path to the root of the git repo
2243 """
23- with Path (path ):
44+ with working_directory (path ):
2445 if not is_shallow_clone ():
2546 return None
2647
@@ -90,7 +111,7 @@ def commit_count() -> int:
90111 """
91112 gc = GitCommand ('rev-list' ,['--count' ,'HEAD' ])
92113 gc .run ()
93- n_commits = int (gc ._stdout [0 ])
114+ n_commits = int (gc ._stdout [0 ]) # type: ignore
94115 assert n_commits >= 0
95116 return n_commits
96117
You can’t perform that action at this time.
0 commit comments