update python.ts

This commit is contained in:
2026-01-27 22:42:18 +08:00
parent 95486035e5
commit c1e2768139
4 changed files with 48 additions and 17 deletions

View File

@@ -235,6 +235,10 @@ class Term {
return `\x1b[1m${message}\x1b[0m`;
}
under(message: string): string {
return `\x1b[4m${message}\x1b[0m`;
}
red(message: string): string {
return `\x1b[31m${message}\x1b[0m`;
}
@@ -246,6 +250,18 @@ class Term {
yellow(message: string): string {
return `\x1b[33m${message}\x1b[0m`;
}
blue(message: string): string {
return `\x1b[34m${message}\x1b[0m`;
}
pink(message: string): string {
return `\x1b[35m${message}\x1b[0m`;
}
cyan(message: string): string {
return `\x1b[36m${message}\x1b[0m`;
}
}
export const term = new Term();

View File

@@ -11,7 +11,7 @@ import {
resolveFilename,
term,
writeStringToFile,
} from "https://global.hatter.ink/script/get/@16/deno-commons-mod.ts";
} from "https://global.hatter.ink/script/get/@18/deno-commons-mod.ts";
import {parseArgs} from "jsr:@std/cli/parse-args";
import {assertEquals} from "jsr:@std/assert";
@@ -33,6 +33,7 @@ interface PythonVersion {
interface PythonVenv {
version: string;
path: string;
alias?: string[];
comment?: string;
}
@@ -128,6 +129,7 @@ ${term.green("python.ts")} ${
async function addVirtualEnv(
pythonVersion: string | null,
pythonVenv: string,
alias?: string,
comment?: string,
): Promise<void> {
const pythonConfig = await loadPythonConfig();
@@ -184,6 +186,9 @@ async function addVirtualEnv(
comment ? (", user comment: " + comment) : ""
}`,
};
if (alias) {
newPythonVenvProfile.alias = [alias];
}
if (!pythonConfig.profiles) {
pythonConfig.profiles = {};
}
@@ -239,10 +244,15 @@ async function handlePython(args: string[]) {
maxVersionLength - version.length,
);
console.log(
"- Python:",
version,
pythonVersion,
"-",
"version:",
term.green(term.bold(version)),
";path:",
term.blue(pythonVersion.path),
";comment:",
term.yellow(term.under(pythonVersion.comment)),
);
// console.log("- Python:", version, pythonVersion,);
}
}
@@ -351,10 +361,15 @@ python.ts venv [--name|-n filter-name]`);
filterProfilesCount++;
console.log(
"-",
venv,
term.blue(term.bold(term.under(venv))),
term.yellow(
pythonVenvProfile.alias
? `[alias: ${pythonVenvProfile.alias.join(", ")}]`
: "-",
),
pythonVenvProfile,
`, active virtual environment command: ${
term.green("source <(python.ts active-venv " + venv + ")")
term.under("source <(python.ts active " + venv + ")")
}`,
);
},
@@ -373,7 +388,7 @@ python.ts venv [--name|-n filter-name]`);
async function handleAddVenv(args: string[]) {
const flags = parseArgs(args, {
boolean: ["help"],
string: ["version", "venv", "comment"],
string: ["version", "venv", "comment", "alias"],
alias: {
V: "version",
c: "comment",
@@ -393,7 +408,7 @@ python.ts add-venv --version 3.10 --venv test-env [--comment comment]`);
log.error("Venv is missing");
return;
}
await addVirtualEnv(flags.version, flags.venv, flags.comment);
await addVirtualEnv(flags.version, flags.venv, flags.alias, flags.comment);
}
async function handleRemoveVenv(args: string[]) {
@@ -531,5 +546,5 @@ Deno.test("versionSort", () => {
assertEquals(["3.7", "3.10", "3.10.1", "3.11"], versions2);
});
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260127T221900+08:00.MEYCIQC/ePZbN/H3JAOhZ43u
// 4ek90MK1IFKLKTynP9RHYRgxTAIhALWtaXAarv25CKcd1ok4AYfuw5ooR68smBzOokmBsEfI
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260127T224153+08:00.MEUCIQCuTKNb0y+N137tvQw+
// 47AFPWoCz5WaUSCJOUpcQBKDNwIgFxvsWvHCgWh5jpCjoQWURwLjAHsN9ze5K5X7KkVUuEM=

View File

@@ -168,11 +168,11 @@
},
"python.ts": {
"script_name": "python.ts",
"script_length": 16299,
"script_sha256": "774cde4fc706489444e4ba0a88bb5db16cb8fe3f16ea37d1468d9ff4e8b78975",
"script_length": 16879,
"script_sha256": "c1a526302f1f72801fa73b6dba5dca5929cdbe5d578f44691bbcf898c559444d",
"script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/python-ts/main.ts",
"publish_time": 1768236234264,
"update_time": 1769523568468
"update_time": 1769524924109
},
"random.ts": {
"script_name": "random.ts",

View File

@@ -21,8 +21,8 @@
},
"python-ts": {
"script_name": "python-ts",
"script_length": 16299,
"script_sha256": "774cde4fc706489444e4ba0a88bb5db16cb8fe3f16ea37d1468d9ff4e8b78975"
"script_length": 16879,
"script_sha256": "c1a526302f1f72801fa73b6dba5dca5929cdbe5d578f44691bbcf898c559444d"
},
"sigstore-verify-ts": {
"script_name": "sigstore-verify-ts",