Skip to content

Commit ab6d0b8

Browse files
committed
Fix copying of Config and CommandOptions
When copying these dataclasses we also need to copy the lists that they hold, otherwise if there are in-place updates the copied instances will be affected too. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 497c994 commit ab6d0b8

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

RELEASE_NOTES.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@
5252

5353
- The distribution package doesn't include tests and other useless files anymore.
5454

55-
- nox: When discovering path *extra paths*, now paths will not be added if they are also *source paths*, as we don't want any duplicates.
55+
- nox
56+
57+
* When discovering path *extra paths*, now paths will not be added if they are also *source paths*, as we don't want any duplicates.
58+
59+
* Fix copying of `Config` and `CommandOptions` objects.
5660

5761
### Cookiecutter template
5862

src/frequenz/repo/config/nox/config.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,16 @@ def copy(self) -> Self:
5353
Returns:
5454
The copy of self.
5555
"""
56-
return _dataclasses.replace(self)
56+
return _dataclasses.replace(
57+
self,
58+
black=self.black.copy(),
59+
darglint=self.darglint.copy(),
60+
isort=self.isort.copy(),
61+
mypy=self.mypy.copy(),
62+
pydocstyle=self.pydocstyle.copy(),
63+
pylint=self.pylint.copy(),
64+
pytest=self.pytest.copy(),
65+
)
5766

5867

5968
@_dataclasses.dataclass(kw_only=True, slots=True)
@@ -101,7 +110,13 @@ def copy(self, /) -> Self:
101110
Returns:
102111
The copy of self.
103112
"""
104-
return _dataclasses.replace(self)
113+
return _dataclasses.replace(
114+
self,
115+
opts=self.opts.copy(),
116+
sessions=self.sessions.copy(),
117+
source_paths=self.source_paths.copy(),
118+
extra_paths=self.extra_paths.copy(),
119+
)
105120

106121
def path_args(self, session: _nox.Session, /) -> list[str]:
107122
"""Return the file paths to run the checks on.

src/frequenz/repo/config/nox/default.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
method.
2525
"""
2626

27-
import dataclasses
28-
2927
from . import config as _config
3028
from . import util as _util
3129

@@ -87,20 +85,20 @@
8785
api_command_options: _config.CommandsOptions = common_command_options.copy()
8886
"""Default command-line options for APIs."""
8987

90-
api_config: _config.Config = dataclasses.replace(
91-
common_config,
92-
opts=api_command_options,
93-
# We don't check the sources at all because they are automatically generated.
94-
source_paths=[],
95-
# We adapt the path to the tests.
96-
extra_paths=list(_util.replace(common_config.extra_paths, {"tests": "pytests"})),
97-
)
88+
api_config: _config.Config = common_config.copy()
9889
"""Default configuration for APIs.
9990
10091
Same as `common_config`, but with `source_paths` replacing `"src"` with `"py"`
10192
and `extra_paths` replacing `"tests"` with `"pytests"`.
10293
"""
10394

95+
# We don't check the sources at all because they are automatically generated.
96+
api_config.source_paths = []
97+
# We adapt the path to the tests.
98+
api_config.extra_paths = list(
99+
_util.replace(common_config.extra_paths, {"tests": "pytests"})
100+
)
101+
104102
app_command_options: _config.CommandsOptions = common_command_options.copy()
105103
"""Default command-line options for applications."""
106104

0 commit comments

Comments
 (0)