nat-n / poethepoet

A task runner that works well with poetry.
https://poethepoet.natn.io/
MIT License
1.39k stars 56 forks source link

"Task names must start with a letter or underscore" error in 0.26.0 #218

Closed DouglasBlackwood closed 3 months ago

DouglasBlackwood commented 4 months ago

Hi

I just noticed a weird behavior with the latest release 0.26.0. Here is what I got when I run poe.

$ poe
Poe the Poet - A task runner that works well with poetry.
version 0.26.0

Error: Invalid task 'missing-imports'
     | Task names must start with a letter or underscore.

USAGE
  poe [-h] [-v | -q] [-C PATH] [--ansi | --no-ansi] task [task arguments]

GLOBAL OPTIONS
  -h, --help            Show this help page and exit
  --version             Print the version and exit
  -v, --verbose         Increase command output (repeatable)
  -q, --quiet           Decrease command output (repeatable)
  -d, --dry-run         Print the task contents but don't actually run it
  -C PATH, --directory PATH
                        Specify where to find the pyproject.toml
  --ansi                Force enable ANSI output
  --no-ansi             Force disable ANSI output

CONFIGURED TASKS
  linters               Run linters
  test                  Run test suite
  shell                 Run poetry shell with containers
  missing-imports       Run python import checks
  serve                 Start mergify-shadow-office API
  serve-prod            Start mergify-shadow-office API like production
  dump-create-database  Generate the database SQL schemas
  revision              Create a new database revision file
  yesqa                 Run yesqa
  docker                Build docker images (eg: -t my-testing-image --target saas-web)
  semgrep               Run SAST tools
  setup                 Sync poetry virtualenv
  api-schemas           Build API schemas

It looks like a regression due to the recent refactor.

nat-n commented 3 months ago

Hi @DouglasBlackwood, thanks for reporting this!

The looks annoying... does it stop you from being able to run tasks?

It's hard for me to tell what could be causing it. Could you help me understand how to reproduce this? An example pyproject.toml file to reproduce this would be super helpful!

DouglasBlackwood commented 3 months ago

Yeah, we have this problem in a couple of repositories. I'll try to reproduce it in a pet project tomorrow.

DouglasBlackwood commented 3 months ago

Looks like the problem occurs when we call a script. Here is a simple poe.toml file to reproduce it.

[tool.poe.executor]
type = "poetry"

[tool.poe.tasks.linters]
deps = ["setup"]
help = "Run linters"
default_item_type = "cmd"
sequence = ["ruff check .", "ruff format --check ."]

[tool.poe.tasks.test]
deps = ["setup"]
help = "Run test suite"
cmd = "pytest -vv"

[tool.poe.tasks.setup]
help = "Sync poetry virtualenv"
executor = { type = "simple" }
default_item_type = "cmd"
sequence = ["./tools/poetry-ci-install.sh"]

We create a setup task to install dependencies before tests. The script behaves differently in the CI and on our computer, so we must use a Shell script.

We get the error Error: Invalid task 'setup' | Task names must start with a letter or underscore.. It fails using Poe 0.26.0 but worked on the previous version 0.25.1.

There is no issue if we define the setup task like so.

[tool.poe.tasks.setup]
help = "Sync poetry virtualenv"
executor = { type = "simple" }
default_item_type = "cmd"
sequence = ["poetry install --sync"]

Or like so

[tool.poe.tasks.setup]
help = "Sync poetry virtualenv"
executor = { type = "simple" }
cmd = "./tools/poetry-ci-install.sh"

It has something to do with sequence and shell scripts I guess. The error message might be something else than Task names must start with a letter or underscore.

Here is the pyproject.toml I used.

[tool.poetry]
name = "poe-task-name-issue"
version = "0.1.0"
description = ""
authors = ["Charly Laurent <charly.laurent@mergify.com>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12"

[tool.poetry.group.dev.dependencies]
poethepoet = "^0.26.0"
pytest = "^8.2.0"
ruff = "^0.4.2"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poe]
include = ["poe.toml"]
nat-n commented 3 months ago

Thanks @DouglasBlackwood for the example! This issue is now fixed in v0.26.1 🚀