Skip to content

Commit 33ca0e6

Browse files
authored
Merge branch 'main' into dependabot/pip/dot-config/dependencies-cda5ad296f
2 parents aeeb2f7 + affe940 commit 33ca0e6

File tree

6 files changed

+291
-45
lines changed

6 files changed

+291
-45
lines changed

.config/dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ cpart
1010
cpath
1111
crepository
1212
csource
13+
excinfo
1314
fileh
1415
fqcn
1516
levelname

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"editor.codeActionsOnSave": {
99
"source.fixAll": "explicit"
1010
},
11-
"editor.defaultFormatter": "ms-python.black-formatter"
11+
"editor.defaultFormatter": "charliermarsh.ruff"
1212
},
1313
"mypy.runUsingActiveInterpreter": true,
1414
"mypy.targets": ["src", "tests"],

pyproject.toml

Lines changed: 79 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ no-docstring-rgx = "__.*__"
8484

8585
[tool.pylint.messages_control]
8686
disable = [
87+
"unknown-option-value",
8788
# https://gist.github.com/cidrblock/ec3412bacfeb34dbc2d334c1d53bef83
8889
"C0103", # invalid-name / ruff N815
8990
"C0105", # typevar-name-incorrect-variance / ruff PLC0105
@@ -96,49 +97,67 @@ disable = [
9697
"C0123", # unidiomatic-typecheck / ruff E721
9798
"C0131", # typevar-double-variance / ruff PLC0131
9899
"C0132", # typevar-name-mismatch / ruff PLC0132
99-
# "C0198", # bad-docstring-quotes / ruff Q002
100-
# "C0199", # docstring-first-line-empty / ruff D210
100+
"C0198", # bad-docstring-quotes / ruff Q002
101+
"C0199", # docstring-first-line-empty / ruff D210
101102
"C0201", # consider-iterating-dictionary / ruff SIM118
102103
"C0202", # bad-classmethod-argument / ruff PLC0202
103104
"C0205", # single-string-used-for-slots / ruff PLC0205
104105
"C0208", # use-sequence-for-iteration / ruff PLC0208
105106
"C0301", # line-too-long / ruff E501
107+
"C0303", # trailing-whitespace / ruff W291
106108
"C0304", # missing-final-newline / ruff W292
107109
"C0321", # multiple-statements / ruff PLC0321
108-
"C0325", # superfluous-parens / ruff UP034
109110
"C0410", # multiple-imports / ruff E401
110111
"C0411", # wrong-import-order / ruff I001
111112
"C0412", # ungrouped-imports / ruff I001
112113
"C0413", # wrong-import-position / ruff E402
113114
"C0414", # useless-import-alias / ruff PLC0414
114-
# "C0501", # consider-using-any-or-all / ruff PLC0501
115-
# "C1901", # compare-to-empty-string / ruff PLC1901
116-
# "C2201", # misplaced-comparison-constant / ruff SIM300
117-
"C3001", # unnecessary-lambda-assignment / ruff PLC3001
115+
"C0415", # import-outside-toplevel / ruff PLC0415
116+
"C0501", # consider-using-any-or-all / ruff PLC0501
117+
"C1901", # compare-to-empty-string / ruff PLC1901
118+
"C2201", # misplaced-comparison-constant / ruff SIM300
119+
"C2401", # non-ascii-name / ruff PLC2401
120+
"C2403", # non-ascii-module-import / ruff PLC2403
121+
"C2701", # import-private-name / ruff PLC2701
122+
"C2801", # unnecessary-dunder-call / ruff PLC2801
123+
"C3001", # unnecessary-lambda-assignment / ruff E731
118124
"C3002", # unnecessary-direct-lambda-call / ruff PLC3002
119125
"E0001", # syntax-error / ruff E999
126+
"E0100", # init-is-generator / ruff PLE0100
120127
"E0101", # return-in-init / ruff PLE0101
121128
"E0102", # function-redefined / ruff F811
122129
"E0103", # not-in-loop / ruff PLE0103
123130
"E0104", # return-outside-function / ruff F706
124131
"E0105", # yield-outside-function / ruff F704
125132
"E0107", # nonexistent-operator / ruff B002
126133
"E0112", # too-many-star-expressions / ruff F622
134+
"E0115", # nonlocal-and-global / ruff PLE0115
127135
"E0116", # continue-in-finally / ruff PLE0116
128136
"E0117", # nonlocal-without-binding / ruff PLE0117
129137
"E0118", # used-prior-global-declaration / ruff PLE0118
130138
"E0211", # no-method-argument / ruff N805
131139
"E0213", # no-self-argument / ruff N805
140+
"E0237", # assigning-non-slot / ruff PLE0237
132141
"E0241", # duplicate-bases / ruff PLE0241
133142
"E0302", # unexpected-special-method-signature / ruff PLE0302
143+
"E0303", # invalid-length-returned / ruff PLE0303
144+
"E0304", # invalid-bool-returned / ruff PLE0304
145+
"E0305", # invalid-index-returned / ruff PLE0305
146+
"E0308", # invalid-bytes-returned / ruff PLE0308
147+
"E0309", # invalid-hash-returned / ruff PLE0309
148+
"E0402", # relative-beyond-top-level / ruff TID252
134149
"E0602", # undefined-variable / ruff F821
135150
"E0603", # undefined-all-variable / ruff F822
136151
"E0604", # invalid-all-object / ruff PLE0604
137152
"E0605", # invalid-all-format / ruff PLE0605
153+
"E0643", # potential-index-error / ruff PLE0643
154+
"E0704", # misplaced-bare-raise / ruff PLE0704
138155
"E0711", # notimplemented-raised / ruff F901
156+
"E1132", # repeated-keyword / ruff PLE1132
139157
"E1142", # await-outside-async / ruff PLE1142
140158
"E1205", # logging-too-many-args / ruff PLE1205
141159
"E1206", # logging-too-few-args / ruff PLE1206
160+
"E1300", # bad-format-character / ruff PLE1300
142161
"E1301", # truncated-format-string / ruff F501
143162
"E1302", # mixed-format-string / ruff F506
144163
"E1303", # format-needs-mapping / ruff F502
@@ -147,69 +166,98 @@ disable = [
147166
"E1306", # too-few-format-args / ruff F524
148167
"E1307", # bad-string-format-type / ruff PLE1307
149168
"E1310", # bad-str-strip-call / ruff PLE1310
169+
"E1519", # singledispatch-method / ruff PLE1519
170+
"E1520", # singledispatchmethod-function / ruff PLE5120
150171
"E1700", # yield-inside-async-function / ruff PLE1700
151172
"E2502", # bidirectional-unicode / ruff PLE2502
152173
"E2510", # invalid-character-backspace / ruff PLE2510
153174
"E2512", # invalid-character-sub / ruff PLE2512
154175
"E2513", # invalid-character-esc / ruff PLE2513
155176
"E2514", # invalid-character-nul / ruff PLE2514
156177
"E2515", # invalid-character-zero-width-space / ruff PLE2515
178+
"E4703", # modified-iterating-set / ruff PLE4703
157179
"R0123", # literal-comparison / ruff F632
158180
"R0124", # comparison-with-itself / ruff PLR0124
159181
"R0133", # comparison-of-constants / ruff PLR0133
182+
"R0202", # no-classmethod-decorator / ruff PLR0202
183+
"R0203", # no-staticmethod-decorator / ruff PLR0203
160184
"R0205", # useless-object-inheritance / ruff UP004
161185
"R0206", # property-with-parameters / ruff PLR0206
186+
"R0904", # too-many-public-methods / ruff PLR0904
162187
"R0911", # too-many-return-statements / ruff PLR0911
163188
"R0912", # too-many-branches / ruff PLR0912
164189
"R0913", # too-many-arguments / ruff PLR0913
190+
"R0914", # too-many-locals / ruff PLR0914
165191
"R0915", # too-many-statements / ruff PLR0915
166-
# "R1260", # too-complex / ruff C901
192+
"R0916", # too-many-boolean-expressions / ruff PLR0916
193+
"R1260", # too-complex / ruff C901
167194
"R1701", # consider-merging-isinstance / ruff PLR1701
195+
"R1702", # too-many-nested-blocks / ruff PLR1702
196+
"R1703", # simplifiable-if-statement / ruff SIM108
197+
"R1704", # redefined-argument-from-local / ruff PLR1704
168198
"R1705", # no-else-return / ruff RET505
169-
"R1706", # consider-using-ternary / ruff SIM108
199+
"R1706", # consider-using-ternary / ruff PLR1706
170200
"R1707", # trailing-comma-tuple / ruff COM818
171201
"R1710", # inconsistent-return-statements / ruff PLR1710
172202
"R1711", # useless-return / ruff PLR1711
173203
"R1714", # consider-using-in / ruff PLR1714
174204
"R1715", # consider-using-get / ruff SIM401
175205
"R1717", # consider-using-dict-comprehension / ruff C402
176206
"R1718", # consider-using-set-comprehension / ruff C401
207+
"R1719", # simplifiable-if-expression / ruff PLR1719
177208
"R1720", # no-else-raise / ruff RET506
178-
"R1721", # unnecessary-comprehension / ruff PLR1721
209+
"R1721", # unnecessary-comprehension / ruff C416
179210
"R1722", # consider-using-sys-exit / ruff PLR1722
180211
"R1723", # no-else-break / ruff RET508
181212
"R1724", # no-else-continue / ruff RET507
182213
"R1725", # super-with-arguments / ruff UP008
183214
"R1728", # consider-using-generator / ruff C417
184-
"R1729", # use-a-generator / ruff C417
215+
"R1729", # use-a-generator / ruff C419
216+
"R1730", # consider-using-min-builtin / ruff PLR1730
217+
"R1731", # consider-using-max-builtin / ruff PLR1730
218+
"R1732", # consider-using-with / ruff SIM115
219+
"R1733", # unnecessary-dict-index-lookup / ruff PLR1733
185220
"R1734", # use-list-literal / ruff C405
186221
"R1735", # use-dict-literal / ruff C406
187-
# "R2004", # magic-value-comparison / ruff PLR2004
188-
# "R5501", # else-if-used / ruff PLR5501
189-
# "R6002", # consider-using-alias / ruff UP006
190-
# "R6003", # consider-alternative-union-syntax / ruff UP007
222+
"R1736", # unnecessary-list-index-lookup / ruff PLR1736
223+
"R2004", # magic-value-comparison / ruff PLR2004
224+
"R2044", # empty-comment / ruff PLR2044
225+
"R5501", # else-if-used / ruff PLR5501
226+
"R6002", # consider-using-alias / ruff UP006
227+
"R6003", # consider-alternative-union-syntax / ruff UP007
228+
"R6104", # consider-using-augmented-assign / ruff PLR6104
229+
"R6201", # use-set-for-membership / ruff PLR6201
230+
"R6301", # no-self-use / ruff PLR6301
191231
"W0102", # dangerous-default-value / ruff B006
192232
"W0104", # pointless-statement / ruff B018
193233
"W0106", # expression-not-assigned / ruff B018
194-
"W0107", # unnecessary-pass / ruff PLW0107
234+
"W0107", # unnecessary-pass / ruff PIE790
235+
"W0108", # unnecessary-lambda / ruff PLW0108
195236
"W0109", # duplicate-key / ruff F601
196237
"W0120", # useless-else-on-loop / ruff PLW0120
197238
"W0122", # exec-used / ruff S102
198239
"W0123", # eval-used / ruff PGH001
199240
"W0127", # self-assigning-variable / ruff PLW0127
200241
"W0129", # assert-on-string-literal / ruff PLW0129
201-
"W0130", # duplicate-value / ruff PLW0130
242+
"W0130", # duplicate-value / ruff B033
202243
"W0131", # named-expr-without-context / ruff PLW0131
244+
"W0133", # pointless-exception-statement / ruff PLW0133
203245
"W0150", # lost-exception / ruff B012
204-
# "W0160", # consider-ternary-expression / ruff SIM108
246+
"W0160", # consider-ternary-expression / ruff SIM108
247+
"W0177", # nan-comparison / ruff PLW0117
205248
"W0199", # assert-on-tuple / ruff F631
249+
"W0211", # bad-staticmethod-argument / ruff PLW0211
250+
"W0212", # protected-access / ruff SLF001
251+
"W0245", # super-without-brackets / ruff PLW0245
206252
"W0301", # unnecessary-semicolon / ruff E703
207253
"W0401", # wildcard-import / ruff F403
254+
"W0404", # reimported / ruff F811
208255
"W0406", # import-self / ruff PLW0406
209256
"W0410", # misplaced-future / ruff F404
210257
"W0511", # fixme / ruff PLW0511
211258
"W0602", # global-variable-not-assigned / ruff PLW0602
212259
"W0603", # global-statement / ruff PLW0603
260+
"W0604", # global-at-module-level / ruff PLW0604
213261
"W0611", # unused-import / ruff F401
214262
"W0612", # unused-variable / ruff F841
215263
"W0613", # unused-argument / ruff ARG001
@@ -221,6 +269,7 @@ disable = [
221269
"W0707", # raise-missing-from / ruff TRY200
222270
"W0711", # binary-op-exception / ruff PLW0711
223271
"W0718", # broad-exception-caught / ruff PLW0718
272+
"W0719", # broad-exception-raised / ruff TRY002
224273
"W1113", # keyword-arg-before-vararg / ruff B026
225274
"W1201", # logging-not-lazy / ruff G
226275
"W1202", # logging-format-interpolation / ruff G
@@ -233,17 +282,23 @@ disable = [
233282
"W1305", # format-combined-specification / ruff F525
234283
"W1308", # duplicate-string-formatting-argument / ruff PLW1308
235284
"W1309", # f-string-without-interpolation / ruff F541
236-
"W1310", # format-string-without-interpolation / ruff PLW1310
285+
"W1310", # format-string-without-interpolation / ruff F541
237286
"W1401", # anomalous-backslash-in-string / ruff W605
238287
"W1404", # implicit-str-concat / ruff ISC001
239288
"W1405", # inconsistent-quotes / ruff Q000
289+
"W1406", # redundant-u-string-prefix / ruff UP025
290+
"W1501", # bad-open-mode / ruff PLW1501
240291
"W1508", # invalid-envvar-default / ruff PLW1508
241292
"W1509", # subprocess-popen-preexec-fn / ruff PLW1509
242293
"W1510", # subprocess-run-check / ruff PLW1510
294+
"W1514", # unspecified-encoding / ruff PLW1514
243295
"W1515", # forgotten-debug-statement / ruff T100
244-
# "W1641", # eq-without-hash / ruff PLW1641
245-
# "W2901", # redefined-loop-name / ruff PLW2901
246-
# "W3201", # bad-dunder-name / ruff PLW3201
296+
"W1518", # method-cache-max-size-none / ruff B019
297+
"W1641", # eq-without-hash / ruff PLW1641
298+
"W2101", # useless-with-lock / ruff PLW2101
299+
"W2402", # non-ascii-file-name / ruff N999
300+
"W2901", # redefined-loop-name / ruff PLW2901
301+
"W3201", # bad-dunder-name / ruff PLW3201
247302
"W3301", # nested-min-max / ruff PLW3301
248303
"duplicate-code",
249304
"fixme",
@@ -266,10 +321,11 @@ lines-after-imports = 2 # Ensures consistency for cases when there's variable vs
266321
lines-between-types = 1 # Separate import/from with 1 line
267322

268323
[tool.ruff.per-file-ignores]
324+
# SLF001: Allow private member access in tests
269325
# S101 Allow assert in tests
270326
# S602 Allow shell in test
271327
# T201 Allow print in tests
272-
"tests/**" = ["S101", "S602", "T201"]
328+
"tests/**" = ["SLF001", "S101", "S602", "T201"]
273329

274330
[tool.ruff.pydocstyle]
275331
convention = "pep257"

src/ansible_dev_environment/subcommands/installer.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,16 @@ def _install_galaxy_requirements(self: Installer) -> None:
215215
msg = f"Source installed collections include: {oxford_join(installed)}"
216216
self._output.note(msg)
217217

218-
def _copy_files_using_git_ls_files(
218+
def _find_files_using_git_ls_files(
219219
self: Installer,
220220
local_repo_path: Path | None,
221-
) -> str | None:
221+
) -> tuple[str | None, str | None]:
222222
"""Copy collection files tracked using git ls-files to the build directory.
223223
224224
Args:
225225
local_repo_path: The collection local path.
226226
Returns:
227+
string with the command used to list files or None
227228
string containing a list of files or nothing
228229
"""
229230
msg = "List collection files using git ls-files."
@@ -240,19 +241,21 @@ def _copy_files_using_git_ls_files(
240241
)
241242
except subprocess.CalledProcessError as exc:
242243
err = f"Failed to list collection using git ls-files: {exc} {exc.stderr}"
243-
self._output.critical(err)
244+
self._output.info(err)
245+
return None, None
244246

245-
return tracked_files_output.stdout
247+
return "git ls-files", tracked_files_output.stdout
246248

247-
def _copy_files_using_ls(
249+
def _find_files_using_ls(
248250
self: Installer,
249251
local_repo_path: Path | None,
250-
) -> str | None:
252+
) -> tuple[str | None, str | None]:
251253
"""Copy collection files tracked using ls to the build directory.
252254
253255
Args:
254256
local_repo_path: The collection local path.
255257
Returns:
258+
string with the command used to list files or None
256259
string containing a list of files or nothing
257260
"""
258261
msg = "List collection files using ls."
@@ -269,9 +272,10 @@ def _copy_files_using_ls(
269272
)
270273
except subprocess.CalledProcessError as exc:
271274
err = f"Failed to list collection using ls: {exc} {exc.stderr}"
272-
self._output.critical(err)
275+
self._output.debug(err)
276+
return None, None
273277

274-
return tracked_files_output.stdout
278+
return "ls", tracked_files_output.stdout
275279

276280
def _copy_repo_files(
277281
self: Installer,
@@ -287,35 +291,34 @@ def _copy_repo_files(
287291
"""
288292
if local_repo_path is None:
289293
msg = "Invalid repo path, no files to copy"
290-
self._output.info(msg)
294+
self._output.debug(msg)
291295
return
292296

293297
# Get tracked files from git ls-files command
294-
tracked_files_output = self._copy_files_using_git_ls_files(
298+
found_using, files_stdout = self._find_files_using_git_ls_files(
295299
local_repo_path=local_repo_path,
296300
)
297301

298-
if tracked_files_output is None:
299-
msg = "No tracked files found using git ls-files"
300-
self._output.info(msg)
301-
302-
# If no tracked files found, get files using ls command
303-
tracked_files_output = self._copy_files_using_ls(
302+
if not files_stdout:
303+
found_using, files_stdout = self._find_files_using_ls(
304304
local_repo_path=local_repo_path,
305305
)
306306

307-
if tracked_files_output is None:
308-
msg = "No files found"
309-
self._output.info(msg)
307+
if not files_stdout:
308+
msg = "No files found with either 'git ls-files' or 'ls"
309+
self._output.critical(msg)
310310
return
311311

312+
msg = f"File list generated with '{found_using}'"
313+
self._output.info(msg)
314+
312315
# Parse tracked files output
313-
tracked_files = tracked_files_output.split("\n")
316+
files_list = files_stdout.split("\n")
314317

315318
# Create the destination folder if it doesn't exist
316319
Path(destination_path).mkdir(parents=True, exist_ok=True)
317320

318-
for file in tracked_files:
321+
for file in files_list:
319322
src_file_path = Path(local_repo_path) / file
320323
dest_file_path = Path(destination_path) / file
321324

tests/unit/conftest.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""Fixtures for unit tests."""
2+
3+
from __future__ import annotations
4+
5+
from typing import TYPE_CHECKING
6+
7+
import pytest
8+
9+
from ansible_dev_environment.output import Output
10+
from ansible_dev_environment.utils import TermFeatures
11+
12+
13+
if TYPE_CHECKING:
14+
from pathlib import Path
15+
16+
17+
@pytest.fixture()
18+
def output(tmp_path: Path) -> Output:
19+
"""Create an Output class object as fixture.
20+
21+
:param tmp_path: App configuration object.
22+
"""
23+
return Output(
24+
log_file=str(tmp_path) + "ansible-creator.log",
25+
log_level="notset",
26+
log_append="false",
27+
term_features=TermFeatures(color=False, links=False),
28+
verbosity=0,
29+
)

0 commit comments

Comments
 (0)