Index
ruff_sync ¶
Ruff sync package.
This package provides tools to synchronize ruff configuration across projects.
__all__
module-attribute
¶
__all__ = [
"Arguments",
"Config",
"FetchResult",
"OutputFormat",
"RuffConfigFileName",
"__version__",
"check",
"fetch_upstream_config",
"get_config",
"get_formatter",
"get_ruff_config",
"get_ruff_tool_table",
"is_ruff_toml_file",
"main",
"merge_ruff_toml",
"pull",
"resolve_raw_url",
"to_git_url",
"toml_ruff_parse",
]
Arguments ¶
Bases: NamedTuple
CLI arguments for the ruff-sync tool.
Source code in src/ruff_sync/cli.py
fields
cached
classmethod
¶
OutputFormat ¶
Bases: str, Enum
Output formats for the CLI.
Source code in src/ruff_sync/constants.py
Config ¶
Bases: TypedDict
Configuration schema for [tool.ruff-sync] in pyproject.toml.
Source code in src/ruff_sync/core.py
FetchResult ¶
Bases: NamedTuple
Result of fetching an upstream configuration.
Source code in src/ruff_sync/core.py
RuffConfigFileName ¶
Bases: str, Enum
Enumeration of Ruff configuration filenames.
Source code in src/ruff_sync/core.py
tried_order
classmethod
¶
Return the order in which configuration files should be tried.
get_config
cached
¶
Read [tool.ruff-sync] configuration from pyproject.toml.
Examples:
>>> import pathlib
>>> config = get_config(pathlib.Path("."))
>>> if "upstream" in config:
... print(f"Syncing from {config['upstream']}")
Source code in src/ruff_sync/cli.py
main ¶
Run the ruff-sync CLI.
Source code in src/ruff_sync/cli.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | |
check
async
¶
Check if the local pyproject.toml / ruff.toml is in sync with the upstream.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
0 if in sync, 1 if out of sync. |
Examples:
>>> import asyncio
>>> from ruff_sync.cli import Arguments
>>> from httpx import URL
>>> import pathlib
>>> args = Arguments(
... command="check",
... upstream=URL("https://github.com/org/repo/blob/main/pyproject.toml"),
... to=pathlib.Path("pyproject.toml"),
... exclude=[],
... )
>>> # asyncio.run(check(args))
Source code in src/ruff_sync/core.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 | |
fetch_upstream_config
async
¶
Fetch the upstream pyproject.toml either via HTTP or git clone.
Source code in src/ruff_sync/core.py
get_ruff_config ¶
Get the ruff section or document from a TOML string.
If it does not exist and it is a pyproject.toml, create it.
Source code in src/ruff_sync/core.py
is_ruff_toml_file ¶
Return True if the path or URL indicates a ruff.toml file.
This handles: - Plain paths (e.g. "ruff.toml", ".ruff.toml", "configs/ruff.toml") - URLs with query strings or fragments (e.g. "ruff.toml?ref=main", "ruff.toml#L10") by examining only the path component (or the part before any query/fragment).
Source code in src/ruff_sync/core.py
merge_ruff_toml ¶
Merge the source and upstream tool ruff config with better whitespace preservation.
Examples:
>>> from tomlkit import parse
>>> source = parse("[tool.ruff]\nline-length = 80")
>>> upstream = parse("[tool.ruff]\nline-length = 100")["tool"]["ruff"]
>>> merged = merge_ruff_toml(source, upstream)
>>> print(merged.as_string())
[tool.ruff]
line-length = 100
Source code in src/ruff_sync/core.py
pull
async
¶
Pull the upstream ruff config and apply it to the source.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
0 on success, 1 on failure. |
Examples:
>>> import asyncio
>>> from ruff_sync.cli import Arguments
>>> from httpx import URL
>>> import pathlib
>>> args = Arguments(
... command="pull",
... upstream=URL("https://github.com/org/repo/blob/main/pyproject.toml"),
... to=pathlib.Path("pyproject.toml"),
... exclude=["lint.isort"],
... init=True,
... )
>>> # asyncio.run(pull(args))
Source code in src/ruff_sync/core.py
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 | |
resolve_raw_url ¶
Convert a GitHub or GitLab repository/blob URL to a raw content URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
URL
|
The URL to resolve. |
required |
branch
|
str
|
The default branch to use for repo URLs. |
'main'
|
path
|
str | None
|
The directory prefix for pyproject.toml. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
URL |
URL
|
The resolved raw content URL, or the original URL if no conversion applies. |
Source code in src/ruff_sync/core.py
to_git_url ¶
Attempt to convert a browser or raw URL to a git (SSH) URL.
Supports GitHub and GitLab.
Source code in src/ruff_sync/core.py
toml_ruff_parse ¶
Parse a TOML string for the tool.ruff section excluding certain ruff configs.
Source code in src/ruff_sync/core.py
get_formatter ¶
Return the corresponding formatter for the given format.