diff options
author | hirosassa <hiro.sassa@gmail.com> | 2021-07-19 10:17:12 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-18 18:17:12 -0700 |
commit | da0dbb3567920a7b9faf25fce00443da7d7b1e00 (patch) | |
tree | 6261eae38aa770539cb86b3d1fc4fc1938867af9 | |
parent | 28cb5b748abb2af5e9e846dabf3f4dc836f53162 (diff) | |
download | yapf-da0dbb3567920a7b9faf25fce00443da7d7b1e00.tar.gz |
change ignore config format for pyproject.toml (#946)
-rw-r--r-- | README.rst | 9 | ||||
-rw-r--r-- | yapf/yapflib/file_resources.py | 18 | ||||
-rw-r--r-- | yapftests/file_resources_test.py | 12 |
3 files changed, 17 insertions, 22 deletions
@@ -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) |