Skip to content

Commit a42600e

Browse files
authored
Always unset the required-version option during ecosystem checks (astral-sh#9593)
Uses our existing configuration overrides to unset the `required-version` option in ecosystem projects during checks. The downside to this approach, is we will now update the config file of _every_ project (with a config file). This roughly normalizes the configuration file, as we don't preserve comments and such. We could instead do a more targeted approach applying this override to projects which we know use this setting 🤷‍♀️
1 parent 49a445a commit a42600e

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

‎python/ruff-ecosystem/ruff_ecosystem/projects.py‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ def __post_init__(self):
5050
)
5151

5252

53+
ALWAYS_CONFIG_OVERRIDES = {
54+
# Always unset the required version or we'll fail
55+
"required-version": None
56+
}
57+
58+
5359
@dataclass(frozen=True)
5460
class ConfigOverrides(Serializable):
5561
"""
@@ -89,18 +95,23 @@ def patch_config(
8995
"""
9096
Temporarily patch the Ruff configuration file in the given directory.
9197
"""
98+
dot_ruff_toml = dirpath / ".ruff.toml"
9299
ruff_toml = dirpath / "ruff.toml"
93100
pyproject_toml = dirpath / "pyproject.toml"
94101

95102
# Prefer `ruff.toml` over `pyproject.toml`
96-
if ruff_toml.exists():
103+
if dot_ruff_toml.exists():
104+
path = dot_ruff_toml
105+
base = []
106+
elif ruff_toml.exists():
97107
path = ruff_toml
98108
base = []
99109
else:
100110
path = pyproject_toml
101111
base = ["tool", "ruff"]
102112

103113
overrides = {
114+
**ALWAYS_CONFIG_OVERRIDES,
104115
**self.always,
105116
**(self.when_preview if preview else self.when_no_preview),
106117
}
@@ -117,17 +128,30 @@ def patch_config(
117128
contents = None
118129
toml = {}
119130

131+
# Do not write a toml file if it does not exist and we're just nulling values
132+
if all((value is None for value in overrides.values())):
133+
yield
134+
return
135+
120136
# Update the TOML, using `.` to descend into nested keys
121137
for key, value in overrides.items():
122-
logger.debug(f"Setting {key}={value!r} in {path}")
138+
if value is not None:
139+
logger.debug(f"Setting {key}={value!r} in {path}")
140+
else:
141+
logger.debug(f"Restoring {key} to default in {path}")
123142

124143
target = toml
125144
names = base + key.split(".")
126145
for name in names[:-1]:
127146
if name not in target:
128147
target[name] = {}
129148
target = target[name]
130-
target[names[-1]] = value
149+
150+
if value is None:
151+
# Remove null values i.e. restore to default
152+
target.pop(names[-1], None)
153+
else:
154+
target[names[-1]] = value
131155

132156
tomli_w.dump(toml, path.open("wb"))
133157

0 commit comments

Comments
 (0)