Skip to content

Commit 715bde0

Browse files
cliffhallclaude
andcommitted
Apply PEP 440's exclusive-bound rules; preview the supersession note in a dry run
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent 93c8df4 commit 715bde0

4 files changed

Lines changed: 85 additions & 17 deletions

File tree

‎scripts/lib/pep440.mjs‎

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,51 @@ function clauseMatches(version, clause) {
138138
);
139139
}
140140
const d = compareVersions(version, operand);
141-
return op === "<"
142-
? d < 0
143-
: op === "<="
144-
? d <= 0
145-
: op === ">"
146-
? d > 0
147-
: d >= 0;
141+
if (op === "<") return d < 0 && !isPreOf(version, operand);
142+
if (op === ">") return d > 0 && !isPostOf(version, operand);
143+
return op === "<=" ? d <= 0 : d >= 0;
144+
}
145+
146+
/** Same epoch and release, compared with trailing zeros ignored. */
147+
function sameRelease(a, b) {
148+
return compareVersions(releaseOnly(a), releaseOnly(b)) === 0;
149+
}
150+
151+
function releaseOnly(v) {
152+
const { epoch, release } = parseVersion(v);
153+
return `${epoch}!${release.join(".")}`;
154+
}
155+
156+
/**
157+
* PEP 440's exclusive `<V` "MUST NOT allow a pre-release of the specified
158+
* version unless the specified version is itself a pre-release": `<2.0`
159+
* excludes `2.0rc1`, which sorts below it.
160+
*/
161+
function isPreOf(version, operand) {
162+
const v = parseVersion(version);
163+
const o = parseVersion(operand);
164+
return (
165+
(v.pre !== null || v.dev !== null) &&
166+
o.pre === null &&
167+
o.dev === null &&
168+
sameRelease(version, operand)
169+
);
170+
}
171+
172+
/**
173+
* PEP 440's exclusive `>V` "MUST NOT allow a post-release of the given
174+
* version unless V itself is a post release": `>1.0` excludes `1.0.post1`,
175+
* which sorts above it.
176+
*/
177+
function isPostOf(version, operand) {
178+
const v = parseVersion(version);
179+
const o = parseVersion(operand);
180+
return (
181+
v.post !== null &&
182+
o.post === null &&
183+
sameRelease(version, operand) &&
184+
JSON.stringify(v.pre) === JSON.stringify(o.pre)
185+
);
148186
}
149187

150188
/**

‎scripts/lib/pep440.test.mjs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ test("satisfies handles ==, !=, wildcards, ~= and the empty specifier", () => {
7979
assert.equal(satisfies("9.9", ""), true);
8080
});
8181

82+
test("exclusive bounds follow PEP 440's pre- and post-release rules", () => {
83+
assert.equal(satisfies("2.0rc1", "<2.0"), false);
84+
assert.equal(satisfies("2.0.dev1", "<2.0"), false);
85+
assert.equal(satisfies("1.9", "<2.0"), true);
86+
assert.equal(satisfies("2.0a1", "<2.0rc1"), true);
87+
assert.equal(satisfies("2.0.0rc1", "<2"), false);
88+
assert.equal(satisfies("1.0.post1", ">1.0"), false);
89+
assert.equal(satisfies("1.0.post2", ">1.0.post1"), true);
90+
assert.equal(satisfies("1.0.1", ">1.0"), true);
91+
// The inclusive forms are plain ordering.
92+
assert.equal(satisfies("2.0rc1", "<=2.0"), true);
93+
assert.equal(satisfies("1.0.post1", ">=1.0"), true);
94+
});
95+
8296
test("satisfies throws instead of guessing", () => {
8397
assert.throws(() => satisfies("1.0", "about 1.0"), /specifier clause/);
8498
assert.throws(() => satisfies("1.0", "~=1"), /two release segments/);

‎scripts/sdk-watch.mjs‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -647,23 +647,27 @@ export function main({
647647
);
648648
}
649649

650-
// Any OPEN issue for an older target of this group is now stale. In a
651-
// dry run there is no new number to point at.
652-
if (number === null) continue;
650+
// Any OPEN issue for an older target of this group is now stale. A
651+
// dry run has no new number yet, so it previews the note with a
652+
// placeholder, and nothing can have announced an issue that does not
653+
// exist.
653654
for (const stale of forGroup) {
654655
if (stale.number === number || stale.state !== "OPEN") continue;
655656
if (compare(stale.marker.target, state.target) >= 0) continue;
656-
const announced = issueComments(repo, stale.number, spawn).some(
657-
(c) =>
658-
isAutomationComment(c) &&
659-
parseSupersededMarker(c.body) === String(number),
660-
);
657+
const announced =
658+
number !== null &&
659+
issueComments(repo, stale.number, spawn).some(
660+
(c) =>
661+
isAutomationComment(c) &&
662+
parseSupersededMarker(c.body) === String(number),
663+
);
661664
if (announced) continue;
665+
const shown = number ?? "NEW";
662666
writer.comment(
663667
stale.number,
664-
buildSupersededComment(number, state.target, stale.marker.target),
668+
buildSupersededComment(shown, state.target, stale.marker.target),
665669
);
666-
log(`${SWEEP}: noted that #${number} supersedes #${stale.number}`);
670+
log(`${SWEEP}: noted that #${shown} supersedes #${stale.number}`);
667671
}
668672
} catch (error) {
669673
// One group's failure must not cost another group its issue.

‎scripts/sdk-watch.test.mjs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,18 @@ test("a forged marker from an outsider suppresses nothing", (t) => {
537537
assert.match(world.warnings.join("\n"), /"octocat"/);
538538
});
539539

540+
test("a dry run previews the supersession note too", (t) => {
541+
const world = fakeWorld({
542+
issues: [sweepIssue(9, "python-sdk", "2.2.0")],
543+
files: files({ "src/memory/package.json": "{}", "package.json": "{}" }),
544+
});
545+
run(world, { output: outputFile(t), dryRun: true });
546+
assert.equal(writes(world.calls).length, 0);
547+
const out = world.lines.join("\n");
548+
assert.match(out, /would comment on #9/);
549+
assert.match(out, /Superseded by #NEW/);
550+
});
551+
540552
test("a newer release supersedes the open older issue, once", (t) => {
541553
const older = sweepIssue(9, "python-sdk", "2.2.0");
542554
const noTs = files({ "src/memory/package.json": "{}", "package.json": "{}" });

0 commit comments

Comments
 (0)