summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-10-12 13:09:09 +0500
committerEgor Tensin <egor@tensin.name>2026-10-12 13:09:09 +0500
commit59e69c1d68f6e1c92e3ea34433ceeb1a2c83b94d (patch)
treed4b5be7d175a95017efbfe449adad37c32289b35
parentREADME: update (diff)
downloadcmake-common-59e69c1d68f6e1c92e3ea34433ceeb1a2c83b94d.tar.gz
cmake-common-59e69c1d68f6e1c92e3ea34433ceeb1a2c83b94d.zip
use contextlib.chdir
-rw-r--r--project/boost/directory.py3
-rw-r--r--project/format.py3
-rw-r--r--project/utils.py10
-rw-r--r--pyproject.toml2
4 files changed, 5 insertions, 13 deletions
diff --git a/project/boost/directory.py b/project/boost/directory.py
index cc3d129..771f6ee 100644
--- a/project/boost/directory.py
+++ b/project/boost/directory.py
@@ -3,6 +3,7 @@
# For details, see https://github.com/egor-tensin/cmake-common
# Distributed under the MIT License.
+from contextlib import chdir
import logging
import os.path
@@ -18,7 +19,7 @@ class BoostDir:
self.path = path
def _go(self):
- return utils.cd(self.path)
+ return chdir(self.path)
def build(self, params):
with self._go():
diff --git a/project/format.py b/project/format.py
index fc5ae0e..9ea3936 100644
--- a/project/format.py
+++ b/project/format.py
@@ -11,6 +11,7 @@ formatting the files in-place.
"""
import argparse
+from contextlib import chdir
import difflib
import os
import sys
@@ -130,7 +131,7 @@ def do_format(
version=DEFAULT_VERSION, style=DEFAULT_STYLE, in_place=False, exclude=None
):
clang_format = ClangFormat(version, style)
- with utils.cd(git_root_dir()):
+ with chdir(git_root_dir()):
cpp_files = filter_files(list_cpp_files(), exclude)
if in_place:
clang_format.format_in_place(cpp_files)
diff --git a/project/utils.py b/project/utils.py
index 87ac8d1..d3a9b10 100644
--- a/project/utils.py
+++ b/project/utils.py
@@ -77,16 +77,6 @@ def setup_logging(verbose=False):
sys.exit(1)
-@contextmanager
-def cd(path):
- cwd = os.getcwd()
- os.chdir(path)
- try:
- yield
- finally:
- os.chdir(cwd)
-
-
def run(cmd, **kwargs):
logging.info("Running: %s", shlex.join(cmd))
return subprocess.run(cmd, check=True, **kwargs)
diff --git a/pyproject.toml b/pyproject.toml
index 0bb2215..ef30076 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -13,7 +13,7 @@ dynamic = ["version"]
authors = [{name = "Egor Tensin", email = "egor@tensin.name"}]
readme = "README.md"
requires-python = ">=3.11"
-# ^^^ For enum.StrEnum, at least?
+# ^^^ For enum.StrEnum/contextlib.chdir, at least?
classifiers = [
"Development Status :: 4 - Beta",