From ca805ace01da29f93eb66ee350247ce8922220f9 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Tue, 23 Jul 2024 19:08:20 +0800 Subject: [PATCH] Skip to format files under `venv` and `env` (#2708) * update black * changelog * update * review --- .../changes/exclue-venv-2024-6-22-15-39-49.md | 7 +++++++ .../typespec-python/generator/pygen/__init__.py | 2 +- packages/typespec-python/generator/pygen/black.py | 15 +++++++-------- 3 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 .chronus/changes/exclue-venv-2024-6-22-15-39-49.md diff --git a/.chronus/changes/exclue-venv-2024-6-22-15-39-49.md b/.chronus/changes/exclue-venv-2024-6-22-15-39-49.md new file mode 100644 index 0000000000..d4436766fc --- /dev/null +++ b/.chronus/changes/exclue-venv-2024-6-22-15-39-49.md @@ -0,0 +1,7 @@ +--- +changeKind: internal +packages: + - "@azure-tools/typespec-python" +--- + +Skip to format files under `venv`/`env` and any folder start with `.` diff --git a/packages/typespec-python/generator/pygen/__init__.py b/packages/typespec-python/generator/pygen/__init__.py index 6050cbec00..8def09e632 100644 --- a/packages/typespec-python/generator/pygen/__init__.py +++ b/packages/typespec-python/generator/pygen/__init__.py @@ -54,7 +54,7 @@ def write_file(self, filename: Union[str, Path], file_content: str) -> None: fd.write(file_content) def list_file(self) -> List[str]: - return [str(f) for f in self.output_folder.glob("**/*") if f.is_file()] + return [str(f.relative_to(self.output_folder)) for f in self.output_folder.glob("**/*") if f.is_file()] class Plugin(ReaderAndWriter, ABC): diff --git a/packages/typespec-python/generator/pygen/black.py b/packages/typespec-python/generator/pygen/black.py index b1d48aff82..78c55dfc83 100644 --- a/packages/typespec-python/generator/pygen/black.py +++ b/packages/typespec-python/generator/pygen/black.py @@ -37,15 +37,14 @@ def process(self) -> bool: [ Path(f) for f in self.list_file() - if all( - item not in f - for item in ( - "__pycache__", - "node_modules", - ".tox", - ".mypy_cache", - ) + if Path(f).parts[0] + not in ( + "__pycache__", + "node_modules", + "venv", + "env", ) + and not Path(f).parts[0].startswith(".") and Path(f).suffix == ".py" ], )