Skip to content

Commit

Permalink
feat(uv): update spec (#2531)
Browse files Browse the repository at this point in the history
  • Loading branch information
BalliAsghar authored Dec 31, 2024
1 parent 7c8ae53 commit 23feabb
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions src/uv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,36 @@

const dependenciesGenerator: Fig.Generator = {
script: {
command: "sh",
command: "bash",
args: [
"-c",
"cat pyproject.toml | grep 'dependencies = ' -A 10 | grep -Eo '\"[^\"]+\"' | cut -d'>' -f1 | tr -d '\"'",
'awk \'/dependencies = \\[/ {f=1; next} /\\]/ {f=0} f && /"/ {line = $0; gsub(/^[ \\t]*"/, "", line); sub(/>=.*$/, "", line); gsub(/",?$/, "", line); print line}\' pyproject.toml',
],
},
postProcess: (out) => {
return out.split("\n").map((line) => {
return {
name: line,
description: "Dependency",
icon: "📦",
priority: 80,
};
});
},
};

const commandGenerator: Fig.Generator = {
script: {
command: "bash",
args: ["-c", `uv run | grep -E '^- ' | sed 's/^- //'`],
},
postProcess: (out) => {
return out.split("\n").map((line) => {
return {
name: line,
description: "Command",
icon: "fig://icon?type=command",
priority: 80,
};
});
},
Expand Down Expand Up @@ -276,7 +295,7 @@ const runOptions: Fig.Option[] = [
description: "Include dependencies from all dependency groups",
},
{
name: "-m",
name: ["-m", "--module"],
description: "Run a Python module",
},
{
Expand Down Expand Up @@ -330,7 +349,7 @@ const runOptions: Fig.Option[] = [
description: "Run without updating the `uv.lock` file",
},
{
name: "-s",
name: ["-s", "--script"],
description: "Run the given path as a Python script",
},
{
Expand Down Expand Up @@ -1507,7 +1526,15 @@ const selfSubcommands: Fig.Subcommand[] = [
];

const subcommands: Fig.Subcommand[] = [
{ name: "run", description: "Run a command or script", options: runOptions },
{
name: "run",
description: "Run a command or script",
options: runOptions,
args: {
name: "command",
generators: commandGenerator,
},
},
{
name: "init",
description: "Create a new project",
Expand All @@ -1522,7 +1549,6 @@ const subcommands: Fig.Subcommand[] = [
{
name: "add",
description: "Add dependencies to the project",
loadSpec: "uv/add",
args: {
name: "packages",
description: "Packages to add",
Expand All @@ -1540,7 +1566,6 @@ const subcommands: Fig.Subcommand[] = [
{
name: "remove",
description: "Remove dependencies from the project",
loadSpec: "uv/remove",
args: {
name: "dependencies",
description: "Dependencies to remove",
Expand All @@ -1559,7 +1584,6 @@ const subcommands: Fig.Subcommand[] = [
{
name: "sync",
description: "Update the project's environment",
loadSpec: "uv/sync",
options: [
...syncOptions,
...indexOptions,
Expand All @@ -1572,7 +1596,6 @@ const subcommands: Fig.Subcommand[] = [
{
name: "lock",
description: "Update the project's lockfile",
loadSpec: "uv/lock",
options: [
...lockOptions,
...indexOptions,
Expand All @@ -1595,7 +1618,6 @@ const subcommands: Fig.Subcommand[] = [
{
name: "tree",
description: "Display the project's dependency tree",
loadSpec: "uv/tree",
options: [
...treeOptions,
...indexOptions,
Expand All @@ -1612,7 +1634,6 @@ const subcommands: Fig.Subcommand[] = [
{
name: "tool",
description: "Run and install commands provided by Python packages",
loadSpec: "uv/tool",
subcommands: toolSubcommands,
options: [
...pythonOptions.filter(
Expand Down Expand Up @@ -1645,7 +1666,6 @@ const subcommands: Fig.Subcommand[] = [
{
name: "pip",
description: "Manage Python packages with a pip-compatible interface",
loadSpec: "uv/pip",
subcommands: pipSubcommands,
options: [
...cacheOptions.filter(
Expand All @@ -1664,6 +1684,7 @@ const subcommands: Fig.Subcommand[] = [
description: "Create a virtual environment",
options: [
...pythonOptions,
...venvOptions,
...indexOptions.filter(
(option) =>
option.name !== "--index-strategy" &&
Expand Down

0 comments on commit 23feabb

Please sign in to comment.