Skip to content

Commit 064cff2

Browse files
committed
Revert "Use sets for config paths and sessions"
This commit introduced an issue because while `dict`s preserve order in Python, sets don't, and it is unexpected for these variables to have a random (and non-reproducible) order (in particular `sessions`). This reverts commit d2dd6c6. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 59eb613 commit 064cff2

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"""
1414

1515
import dataclasses as _dataclasses
16+
import itertools as _itertools
1617
from typing import Self
1718

1819
import nox as _nox
@@ -61,10 +62,10 @@ class Config:
6162
opts: CommandsOptions = _dataclasses.field(default_factory=CommandsOptions)
6263
"""Command-line options for each command used by sessions."""
6364

64-
sessions: set[str] = _dataclasses.field(default_factory=set)
65+
sessions: list[str] = _dataclasses.field(default_factory=lambda: [])
6566
"""List of sessions to run."""
6667

67-
source_paths: set[str] = _dataclasses.field(default_factory=set)
68+
source_paths: list[str] = _dataclasses.field(default_factory=lambda: [])
6869
"""List of paths containing source files that should be analyzed by the sessions.
6970
7071
Source paths are inspected for `__init__.py` files to look for packages.
@@ -77,7 +78,7 @@ class Config:
7778
checking.
7879
"""
7980

80-
extra_paths: set[str] = _dataclasses.field(default_factory=set)
81+
extra_paths: list[str] = _dataclasses.field(default_factory=lambda: [])
8182
"""List of extra paths to be analyzed by the sessions.
8283
8384
These are not inspected for packages, as they are passed verbatim to the
@@ -91,7 +92,7 @@ def __post_init__(self) -> None:
9192
"""
9293
for path in _util.discover_paths():
9394
if path not in self.extra_paths:
94-
self.extra_paths.add(path)
95+
self.extra_paths.append(path)
9596

9697
def copy(self, /) -> Self:
9798
"""Create a new object as a copy of self.
@@ -101,7 +102,7 @@ def copy(self, /) -> Self:
101102
"""
102103
return _dataclasses.replace(self)
103104

104-
def path_args(self, session: _nox.Session, /) -> set[str]:
105+
def path_args(self, session: _nox.Session, /) -> list[str]:
105106
"""Return the file paths to run the checks on.
106107
107108
If positional arguments are present in the nox session, those are used
@@ -115,13 +116,13 @@ def path_args(self, session: _nox.Session, /) -> set[str]:
115116
The file paths to run the checks on.
116117
"""
117118
if session.posargs:
118-
return set(session.posargs)
119+
return session.posargs
119120

120-
return {
121-
str(p) for p in _util.existing_paths(self.source_paths | self.extra_paths)
122-
}
121+
return list(
122+
str(p) for p in _util.existing_paths(self.source_paths + self.extra_paths)
123+
)
123124

124-
def package_args(self, session: _nox.Session, /) -> set[str]:
125+
def package_args(self, session: _nox.Session, /) -> list[str]:
125126
"""Return the package names to run the checks on.
126127
127128
If positional arguments are present in the nox session, those are used
@@ -138,7 +139,7 @@ def package_args(self, session: _nox.Session, /) -> set[str]:
138139
The package names found in the `source_paths`.
139140
"""
140141
if session.posargs:
141-
return set(session.posargs)
142+
return session.posargs
142143

143144
sources_package_dirs_with_roots = (
144145
(p, _util.find_toplevel_package_dirs(p))
@@ -155,7 +156,7 @@ def package_args(self, session: _nox.Session, /) -> set[str]:
155156
_util.path_to_package(p) for p in _util.existing_paths(self.extra_paths)
156157
)
157158

158-
return {*source_packages, *extra_packages}
159+
return list(_itertools.chain(source_packages, extra_packages))
159160

160161

161162
_config: Config | None = None

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,24 @@
5656

5757
common_config = _config.Config(
5858
opts=common_command_options.copy(),
59-
sessions={
59+
sessions=[
6060
"formatting",
6161
"mypy",
6262
"pylint",
6363
"docstrings",
6464
"pytest_min",
6565
"pytest_max",
66-
},
67-
source_paths={
66+
],
67+
source_paths=[
6868
"src",
69-
},
70-
extra_paths={
69+
],
70+
extra_paths=[
7171
"benchmarks",
7272
"docs",
7373
"examples",
7474
"noxfile.py",
7575
"tests",
76-
},
76+
],
7777
)
7878
"""Default configuration for all types of repositories."""
7979

@@ -90,9 +90,9 @@
9090
common_config,
9191
opts=api_command_options,
9292
# We don't check the sources at all because they are automatically generated.
93-
source_paths=set(),
93+
source_paths=[],
9494
# We adapt the path to the tests.
95-
extra_paths=set(_util.replace(common_config.extra_paths, {"tests": "pytests"})),
95+
extra_paths=list(_util.replace(common_config.extra_paths, {"tests": "pytests"})),
9696
)
9797
"""Default configuration for APIs.
9898

0 commit comments

Comments
 (0)