Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: filter packages in pipi port #101

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions modules/ports/pipi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { logger, semver } from "../../port.ts";
import { ListAllArgs } from "./types.ts";

export type PackageMetadataSimple = {
files: [{ filename: string; "requires-python"?: string }];
versions: string[];
};

export function resolveCompatibleVersions(
args: ListAllArgs,
metadata: PackageMetadataSimple,
) {
throw new Error("TODO: inject buildDepConfigs in ListAllargs");

const pythonDep = args.config.buildDepConfigs!.cpy_bs_ghrel as {
version: string;
};
const pythonVersion = semver.parseRange(pythonDep.version);
const versions = [];

for (const file of metadata.files) {
const match = file.filename.match(/(\d+\.\d+\.\d+.*)\.tar\.gz/);

if (
match &&
testPythonCompablity(pythonVersion, file["requires-python"])
) {
versions.push(match[1]);
}
}

return versions;
}

function testPythonCompablity(version: semver.Range, required?: string) {
if (!required) return true;

return required.split(",")
.map((v) => v.replaceAll(" ", ""))
.every((v) => testVersionSpecifier(version, v));
}

function testVersionSpecifier(version: semver.Range, specifier: string) {
const negate = specifier.startsWith("!=");
const specifierRange = semver.parseRange(
negate ? specifier.slice(2) : specifier,
);
const result = semver.rangeIntersects(version, specifierRange);

return negate ? !result : result;
}
10 changes: 6 additions & 4 deletions ports/pipi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import {
} from "../port.ts";
import cpy_bs from "./cpy_bs.ts";
import * as std_ports from "../modules/ports/std.ts";
import {
PackageMetadataSimple,
resolveCompatibleVersions,
} from "../modules/ports/pipi.ts";

export const manifest = {
ty: "denoWorker@v1" as const,
Expand Down Expand Up @@ -51,11 +55,9 @@ export class Port extends PortBase {
`https://pypi.org/simple/${conf.packageName}/`,
)
.header("Accept", "application/vnd.pypi.simple.v1+json")
.json() as {
versions: string[];
};
.json() as PackageMetadataSimple;

return metadata.versions;
return resolveCompatibleVersions(args, metadata);
}

latestStable(args: ListAllArgs): Promise<string> {
Expand Down
Loading