mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 12:29:28 +00:00
Always unset the required-version
option during ecosystem checks (#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 🤷♀️
This commit is contained in:
parent
49a445a23d
commit
a42600e9a2
1 changed files with 27 additions and 3 deletions
|
@ -50,6 +50,12 @@ class Project(Serializable):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
ALWAYS_CONFIG_OVERRIDES = {
|
||||||
|
# Always unset the required version or we'll fail
|
||||||
|
"required-version": None
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class ConfigOverrides(Serializable):
|
class ConfigOverrides(Serializable):
|
||||||
"""
|
"""
|
||||||
|
@ -89,11 +95,15 @@ class ConfigOverrides(Serializable):
|
||||||
"""
|
"""
|
||||||
Temporarily patch the Ruff configuration file in the given directory.
|
Temporarily patch the Ruff configuration file in the given directory.
|
||||||
"""
|
"""
|
||||||
|
dot_ruff_toml = dirpath / ".ruff.toml"
|
||||||
ruff_toml = dirpath / "ruff.toml"
|
ruff_toml = dirpath / "ruff.toml"
|
||||||
pyproject_toml = dirpath / "pyproject.toml"
|
pyproject_toml = dirpath / "pyproject.toml"
|
||||||
|
|
||||||
# Prefer `ruff.toml` over `pyproject.toml`
|
# Prefer `ruff.toml` over `pyproject.toml`
|
||||||
if ruff_toml.exists():
|
if dot_ruff_toml.exists():
|
||||||
|
path = dot_ruff_toml
|
||||||
|
base = []
|
||||||
|
elif ruff_toml.exists():
|
||||||
path = ruff_toml
|
path = ruff_toml
|
||||||
base = []
|
base = []
|
||||||
else:
|
else:
|
||||||
|
@ -101,6 +111,7 @@ class ConfigOverrides(Serializable):
|
||||||
base = ["tool", "ruff"]
|
base = ["tool", "ruff"]
|
||||||
|
|
||||||
overrides = {
|
overrides = {
|
||||||
|
**ALWAYS_CONFIG_OVERRIDES,
|
||||||
**self.always,
|
**self.always,
|
||||||
**(self.when_preview if preview else self.when_no_preview),
|
**(self.when_preview if preview else self.when_no_preview),
|
||||||
}
|
}
|
||||||
|
@ -117,9 +128,17 @@ class ConfigOverrides(Serializable):
|
||||||
contents = None
|
contents = None
|
||||||
toml = {}
|
toml = {}
|
||||||
|
|
||||||
|
# Do not write a toml file if it does not exist and we're just nulling values
|
||||||
|
if all((value is None for value in overrides.values())):
|
||||||
|
yield
|
||||||
|
return
|
||||||
|
|
||||||
# Update the TOML, using `.` to descend into nested keys
|
# Update the TOML, using `.` to descend into nested keys
|
||||||
for key, value in overrides.items():
|
for key, value in overrides.items():
|
||||||
|
if value is not None:
|
||||||
logger.debug(f"Setting {key}={value!r} in {path}")
|
logger.debug(f"Setting {key}={value!r} in {path}")
|
||||||
|
else:
|
||||||
|
logger.debug(f"Restoring {key} to default in {path}")
|
||||||
|
|
||||||
target = toml
|
target = toml
|
||||||
names = base + key.split(".")
|
names = base + key.split(".")
|
||||||
|
@ -127,6 +146,11 @@ class ConfigOverrides(Serializable):
|
||||||
if name not in target:
|
if name not in target:
|
||||||
target[name] = {}
|
target[name] = {}
|
||||||
target = target[name]
|
target = target[name]
|
||||||
|
|
||||||
|
if value is None:
|
||||||
|
# Remove null values i.e. restore to default
|
||||||
|
target.pop(names[-1], None)
|
||||||
|
else:
|
||||||
target[names[-1]] = value
|
target[names[-1]] = value
|
||||||
|
|
||||||
tomli_w.dump(toml, path.open("wb"))
|
tomli_w.dump(toml, path.open("wb"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue