update python.ts
This commit is contained in:
@@ -11,9 +11,9 @@ import {
|
||||
resolveFilename,
|
||||
term,
|
||||
writeStringToFile,
|
||||
} from "https://global.hatter.ink/script/get/@16/deno-commons-mod.ts";
|
||||
import { parseArgs } from "jsr:@std/cli/parse-args";
|
||||
import { assertEquals } from "jsr:@std/assert";
|
||||
} 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";
|
||||
|
||||
const PYTHON_CONFIG_FILE = "~/.config/python-config.json";
|
||||
const PYTHON_VENV_DEFAULT_BASE_DIR = "~/.venv/";
|
||||
@@ -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=
|
||||
|
||||
Reference in New Issue
Block a user