Skip to content

Commit

Permalink
feat: poetry port (#100)
Browse files Browse the repository at this point in the history
* wip: poetry port

* feat: poetry port

Added a hook into pipi port to inject dependencies.

* fix: fmt & lint

* fix: typing

* fix: `dependencies` field visibility

* fix: naming & formatting
  • Loading branch information
luckasRanarison authored Oct 16, 2024
1 parent 7b19bc7 commit 4c1295f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
1 change: 1 addition & 0 deletions ports/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export { default as node } from "./node.ts";
export { default as npmi } from "./npmi.ts";
export { default as opentofu_ghrel } from "./opentofu_ghrel.ts";
export { default as pipi } from "./pipi.ts";
export { default as poetry } from "./poetry.ts";
export { default as pnpm } from "./pnpm.ts";
export { default as protoc } from "./protoc.ts";
export { default as ruff } from "./ruff.ts";
Expand Down
11 changes: 10 additions & 1 deletion ports/pipi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export const manifest = {

const confValidator = zod.object({
packageName: zod.string().regex(/[a-z0-9._-]*/),
peerDeps: zod.array(zod.object({
name: zod.string(),
version: zod.string().nullish(),
})).nullish(),
}).passthrough();

export type PipiInstallConf =
Expand Down Expand Up @@ -98,9 +102,14 @@ export class Port extends PortBase {
conf.packageName,
args.installVersion,
);

const dependencies = conf.peerDeps?.map((dep) => (
dep.version ? [dep.name, dep.version].join("==") : dep.name
)) ?? [];

await $`${
depExecShimPath(std_ports.cpy_bs_ghrel, "python3", args.depArts)
} -m pip -qq install ${conf.packageName}==${args.installVersion}`
} -m pip -qq install ${conf.packageName}==${args.installVersion} ${dependencies}`
.env(
{
...depPathEnvs,
Expand Down
70 changes: 70 additions & 0 deletions ports/poetry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {
defaultLatestStable,
InstallConfigSimple,
osXarch,
zod,
} from "../port.ts";
import { Port as PipiPort } from "./pipi.ts";
import {
ALL_ARCH,
ALL_OS,
DownloadArgs,
InstallArgs,
InstallConfigLiteX,
ListAllArgs,
} from "../modules/ports/types.ts";
import * as std_ports from "../modules/ports/std.ts";

export const manifest = {
ty: "denoWorker@v1" as const,
name: "poetry",
version: "0.1.0",
moduleSpecifier: import.meta.url,
buildDeps: [std_ports.cpy_bs_ghrel],
platforms: osXarch([...ALL_OS], [...ALL_ARCH]),
};

const confValidator = zod.object({
plugins: zod.array(zod.object({
name: zod.string(),
version: zod.string().nullish(),
})).nullish(),
}).passthrough();

export type PoetryInstallConf =
& InstallConfigSimple
& zod.input<typeof confValidator>;

export default function conf(config: PoetryInstallConf = {}) {
return {
...config,
port: manifest,
};
}

const toPipiConfig = (config: InstallConfigLiteX) => ({
...config,
packageName: "poetry",
peerDeps: config.plugins,
});

export class Port extends PipiPort {
listAll(args: ListAllArgs) {
return super.listAll({ ...args, config: toPipiConfig(args.config) });
}

latestStable(args: ListAllArgs): Promise<string> {
return defaultLatestStable(this, {
...args,
config: toPipiConfig(args.config),
});
}

download(args: DownloadArgs) {
return super.download({ ...args, config: toPipiConfig(args.config) });
}

install(args: InstallArgs) {
return super.install({ ...args, config: toPipiConfig(args.config) });
}
}

0 comments on commit 4c1295f

Please sign in to comment.