aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhirosassa <hiro.sassa@gmail.com>2021-07-19 10:17:12 +0900
committerGitHub <noreply@github.com>2021-07-18 18:17:12 -0700
commitda0dbb3567920a7b9faf25fce00443da7d7b1e00 (patch)
tree6261eae38aa770539cb86b3d1fc4fc1938867af9
parent28cb5b748abb2af5e9e846dabf3f4dc836f53162 (diff)
downloadyapf-da0dbb3567920a7b9faf25fce00443da7d7b1e00.tar.gz
change ignore config format for pyproject.toml (#946)
-rw-r--r--README.rst9
-rw-r--r--yapf/yapflib/file_resources.py18
-rw-r--r--yapftests/file_resources_test.py12
3 files changed, 17 insertions, 22 deletions
diff --git a/README.rst b/README.rst
index b381c4d..0b8a83e 100644
--- a/README.rst
+++ b/README.rst
@@ -156,11 +156,12 @@ If you use ``pyproject.toml``, exclude patterns are specified by ``ignore_patten
in ``[tool.yapfignore]`` section. For example:
.. code-block:: ini
+
[tool.yapfignore]
- ignore_patterns="""
- temp/**/*.py
- temp2/*.py
- """
+ ignore_patterns = [
+ "temp/**/*.py",
+ "temp2/*.py"
+ ]
Formatting style
================
diff --git a/yapf/yapflib/file_resources.py b/yapf/yapflib/file_resources.py
index 4c0fbf2..1c405a2 100644
--- a/yapf/yapflib/file_resources.py
+++ b/yapf/yapflib/file_resources.py
@@ -57,19 +57,13 @@ def _GetExcludePatternsFromPyprojectToml(filename):
"toml package is needed for using pyproject.toml as a configuration file"
)
- pyproject_toml = toml.load(filename)
if os.path.isfile(filename) and os.access(filename, os.R_OK):
- excludes = pyproject_toml.get('tool',
- {}).get('yapfignore',
- {}).get('ignore_patterns', None)
- if excludes is None:
- return []
-
- for line in excludes.split('\n'):
- if line.strip() and not line.startswith('#'):
- ignore_patterns.append(line.strip())
- if any(e.startswith('./') for e in ignore_patterns):
- raise errors.YapfError('path in pyproject.toml should not start with ./')
+ pyproject_toml = toml.load(filename)
+ ignore_patterns = pyproject_toml.get('tool',
+ {}).get('yapfignore',
+ {}).get('ignore_patterns', [])
+ if any(e.startswith('./') for e in ignore_patterns):
+ raise errors.YapfError('path in pyproject.toml should not start with ./')
return ignore_patterns
diff --git a/yapftests/file_resources_test.py b/yapftests/file_resources_test.py
index 6afd8a4..5ccacb8 100644
--- a/yapftests/file_resources_test.py
+++ b/yapftests/file_resources_test.py
@@ -82,9 +82,9 @@ class GetExcludePatternsForDir(unittest.TestCase):
ignore_patterns = ['temp/**/*.py', 'temp2/*.py']
with open(local_ignore_file, 'w') as f:
f.write('[tool.yapfignore]\n')
- f.write('ignore_patterns="""')
- f.writelines('\n'.join(ignore_patterns))
- f.write('"""')
+ f.write('ignore_patterns=[')
+ f.writelines('\n,'.join([f'"{p}"' for p in ignore_patterns]))
+ f.write(']')
self.assertEqual(
sorted(file_resources.GetExcludePatternsForDir(self.test_tmpdir)),
@@ -99,9 +99,9 @@ class GetExcludePatternsForDir(unittest.TestCase):
ignore_patterns = ['temp/**/*.py', './wrong/syntax/*.py']
with open(local_ignore_file, 'w') as f:
f.write('[tool.yapfignore]\n')
- f.write('ignore_patterns="""')
- f.writelines('\n'.join(ignore_patterns))
- f.write('"""')
+ f.write('ignore_patterns=[')
+ f.writelines('\n,'.join([f'"{p}"' for p in ignore_patterns]))
+ f.write(']')
with self.assertRaises(errors.YapfError):
file_resources.GetExcludePatternsForDir(self.test_tmpdir)