Skip to content

Commit

Permalink
feat: run tasks defined ini [tool.poetry.tasks]
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer committed May 10, 2023
1 parent a27d35e commit c1632fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/poetry/console/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ class RunCommand(EnvCommand):

def handle(self) -> int:
args = self.argument("args")
script = args[0]
tasks = self.poetry.local_config.get("tasks")
scripts = self.poetry.local_config.get("scripts")

if scripts and script in scripts:
return self.run_script(scripts[script], args)
if tasks and args[0] in tasks:
cmd = tasks[args[0]].split()
args = [*cmd, *args]

elif scripts and args[0] in scripts:
return self.run_script(scripts[args[0]], args)

try:
return self.env.execute(*args)
except FileNotFoundError:
self.line_error(f"<error>Command not found: <c1>{script}</c1></error>")
self.line_error(f"<error>Command not found: <c1>{args[0]}</c1></error>")
return 1

@property
Expand Down
9 changes: 9 additions & 0 deletions src/poetry/json/schemas/poetry.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
"items": {
"$ref": "#/definitions/repository"
}
},
"tasks": {
"type": "object",
"description": "A hash of tasks to run",
"patternProperties": {
"^[a-zA-Z-_.0-9]+$": {
"type": "string"
}
}
}
},
"definitions": {
Expand Down

0 comments on commit c1632fa

Please sign in to comment.