GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ruff/scripts/bump-workspace-crate-versions.py at rustpython-0.16.10 · RustPython/ruff

Expand file tree

/

bump-workspace-crate-versions.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
139 lines (117 loc) · 5.06 KB
/

bump-workspace-crate-versions.py

Copy path

File metadata and controls

139 lines (117 loc) · 5.06 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Naively increment the patch version of each crate in the workspace.
#
# This excludes crates which are versioned with Ruff's command-line interface.
#
# After incrementing the version in each member `Cargo.toml`, it updates the version pins in the
# root `Cargo.toml` to match.
# /// script
# requires-python = ">=3.13"
# dependencies = []
#
# [tool.ty.rules]
# truthiness-test-of-none-union = "warn"
# blanket-ignore-comment = "warn"
# missing-type-argument = "warn"
# possibly-unresolved-reference = "warn"
# unsound-return-statement = "warn"
# unsound-yield = "warn"
# unsupported-dynamic-base = "warn"
# division-by-zero = "warn"
# dynamic-function-decorator-return = "warn"
# unsound-assignment = "warn"
# redundant-condition-strict = "warn"
# disjoint-cast = "warn"
# missing-direct-dependency = "warn"
#
# [tool.uv]
# no-build = true
# exclude-newer = "P7D"
# ///
from __future__ import annotations
import json
import pathlib
import subprocess
import tomllib
NO_BUMP_CRATES = {"ruff", "ruff_linter", "ruff_wasm"}
def main() -> None:
# Pre-sync NO_BUMP_CRATES versions before running cargo metadata.
#
# Rooster updates crate versions but isn't workspace-aware, so it doesn't update
# the workspace dependency pins in the root Cargo.toml. This can cause cargo metadata
# to fail with version mismatches (e.g., when going from 0.15.x to 0.16.0).
# We fix the pins first by reading the crate versions directly.
script_dir = pathlib.Path(__file__).parent
workspace_manifest = script_dir.parent / "Cargo.toml"
workspace_manifest_contents = workspace_manifest.read_text()
parsed_workspace_manifest = tomllib.loads(workspace_manifest_contents)
for crate_name in NO_BUMP_CRATES:
crate_manifest = script_dir.parent / "crates" / crate_name / "Cargo.toml"
if not crate_manifest.exists():
continue
crate_version = tomllib.loads(crate_manifest.read_text())["package"]["version"]
manifest_dependency = parsed_workspace_manifest["workspace"][
"dependencies"
].get(crate_name)
if manifest_dependency is None:
continue
manifest_version = manifest_dependency["version"]
if manifest_version != crate_version:
workspace_manifest_contents = workspace_manifest_contents.replace(
f'{crate_name} = {{ version = "{manifest_version}"',
f'{crate_name} = {{ version = "{crate_version}"',
)
workspace_manifest.write_text(workspace_manifest_contents)
# Now cargo metadata will succeed.
result = subprocess.run(
["cargo", "metadata", "--format-version", "1"],
capture_output=True,
text=True,
check=True,
)
content = json.loads(result.stdout)
packages = {package["id"]: package for package in content["packages"]}
workspace_manifest_contents = workspace_manifest.read_text()
parsed_workspace_manifest = tomllib.loads(workspace_manifest_contents)
version_changes = {}
for workspace_member in content["workspace_members"]:
manifest = pathlib.Path(packages[workspace_member]["manifest_path"])
name = packages[workspace_member]["name"]
# Only crates released to crates.io participate in the workspace release sequence.
if packages[workspace_member].get("publish") == []:
continue
# For the members we're not bumping, we'll still make sure that the version pinned in the
# workspace manifest matches the version of the crate. This is done because Rooster isn't
# Cargo workspace aware and won't otherwise bump these when updating the member `Cargo.toml`
# files.
if name in NO_BUMP_CRATES:
manifest_dependency = parsed_workspace_manifest["workspace"][
"dependencies"
].get(name)
if manifest_dependency is None:
continue
manifest_version = manifest_dependency["version"]
metadata_version = packages[workspace_member]["version"]
if manifest_version != metadata_version:
version_changes[name] = (manifest_version, metadata_version)
continue
# For other members, bump the patch version.
version = packages[workspace_member]["version"]
version_parts = [int(part) for part in version.split(".")]
new_version = f"{version_parts[0]}.{version_parts[1]}.{version_parts[2] + 1}"
contents = manifest.read_text()
contents = contents.replace(
'version = "' + version + '"',
'version = "' + new_version + '"',
1,
)
version_changes[name] = (version, new_version)
manifest.write_text(contents)
# Update all the pins in the workspace root.
for name, (old_version, new_version) in version_changes.items():
workspace_manifest_contents = workspace_manifest_contents.replace(
f'{name} = {{ version = "{old_version}"',
f'{name} = {{ version = "{new_version}"',
)
workspace_manifest.write_text(workspace_manifest_contents)
if __name__ == "__main__":
main()
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.