Skip to content

Commit fce2f77

Browse files
committed
Add option to set file extensions for pylint and prettier. Add xml check per default. Bump version
1 parent b567782 commit fce2f77

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

src/doblib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "0.19.2"
1+
VERSION = "0.19.3"

src/doblib/ci.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,22 @@ def _ci_isort(self, options, args, paths, ignores):
107107
return utils.call(*cmd, *args, *paths, pipe=False)
108108

109109
def _ci_prettier(self, options, args, paths, ignores):
110-
""" """
110+
"""Run prettier on supported files"""
111111
executable = shutil.which("prettier")
112112
if not executable:
113113
utils.error("prettier is not installed")
114114
return 1
115115

116-
files = []
116+
files = set()
117+
118+
extensions = self.get(
119+
base.SECTION, "prettier", "extension", default=["js", "xml"]
120+
)
117121
for path in paths:
118-
files.extend(glob.glob(f"{path}/**/*.js", recursive=True))
122+
for ext in extensions:
123+
files.update(glob.glob(f"{path}/**/*.{ext}", recursive=True))
119124

120-
files = list(
125+
files = sorted(
121126
filter(
122127
lambda path: not any(
123128
fnmatch(path, f"*/{pattern}")
@@ -132,21 +137,24 @@ def _ci_prettier(self, options, args, paths, ignores):
132137
if not files:
133138
return 0
134139

135-
cmd = ["prettier"]
140+
cmd = ["prettier", "--check"]
136141
if options.fix:
137142
cmd.append("--write")
138143

139144
return utils.call(*cmd, *args, *files, pipe=False)
140145

141146
def _ci_pylint(self, options, args, paths, ignores):
142147
"""Run pylint tests for Odoo"""
143-
files = []
148+
files = set()
149+
150+
extensions = self.get(
151+
base.SECTION, "pylint", "extension", default=["csv", "py", "xml"]
152+
)
144153
for path in paths:
145-
files.extend(glob.glob(f"{path}/**/*.csv", recursive=True))
146-
files.extend(glob.glob(f"{path}/**/*.py", recursive=True))
147-
files.extend(glob.glob(f"{path}/**/*.xml", recursive=True))
154+
for ext in extensions:
155+
files.update(glob.glob(f"{path}/**/*.{ext}", recursive=True))
148156

149-
files = list(
157+
files = sorted(
150158
filter(
151159
lambda path: not any(
152160
fnmatch(path, f"*/{pattern}")
@@ -169,15 +177,15 @@ def _ci_pylint(self, options, args, paths, ignores):
169177

170178
def _ci_paths(self):
171179
return self.get("odoo", "addons_path", default=[]) + self.get(
172-
"bootstrap", "ci_path", default=[]
180+
base.SECTION, "ci_path", default=[]
173181
)
174182

175183
def ci(self, ci, args=None):
176184
"""Run CI tests"""
177185
args, left = load_ci_arguments(args or [])
178186

179187
# Always include this script in the tests
180-
ignores = self.get("bootstrap", "blacklist", default=[])
188+
ignores = self.get(base.SECTION, "blacklist", default=[])
181189
func = getattr(self, f"_ci_{ci}", None)
182190
if ci in CI and callable(func):
183191
return func(args, left, self._ci_paths(), ignores)

tests/test_ci.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from unittest import mock
77

88
import pytest
9-
109
from doblib import base
1110
from doblib.ci import CIEnvironment
1211

@@ -145,15 +144,16 @@ def test_ci_prettier(which, call, env):
145144
with mock.patch(
146145
"glob.glob",
147146
return_value=[
148-
"test15/path/file.py",
149-
"folder/test123/file.py",
150147
"folder/path/test196.py",
148+
"folder/test123/file.py",
149+
"test15/path/file.py",
151150
"test2/path/file.py",
152151
],
153152
):
154153
assert env.ci("prettier", ["--fix"]) == 42
155154
call.assert_called_once_with(
156155
"prettier",
156+
"--check",
157157
"--write",
158158
"test2/path/file.py",
159159
pipe=False,
@@ -178,8 +178,6 @@ def test_ci_pylint(call, glob, env):
178178
"pylint",
179179
"--rcfile=.pylintrc",
180180
"test2/path/file.py",
181-
"test2/path/file.py",
182-
"test2/path/file.py",
183181
pipe=False,
184182
)
185183

@@ -191,8 +189,6 @@ def test_ci_pylint(call, glob, env):
191189
"pylint",
192190
"--rcfile=.pylintrc",
193191
"test2/path/file.py",
194-
"test2/path/file.py",
195-
"test2/path/file.py",
196192
pipe=False,
197193
)
198194

0 commit comments

Comments
 (0)