Skip to content

poetry install generates invalid python code for console scrips dependent on extras #8899

@couling

Description

@couling
  • Poetry version: 1.7.1
  • Python version: 3.11.14
  • OS version and name: MacOS
  • pyproject.toml: Documented example under scripts. Eg:
[tool.poetry]
name = "poetry-example"
version = "0.1.0"
description = ""
authors = []
readme = "README.md"

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

# Documented code
[tool.poetry.scripts]
devtest = { reference = "poetry_example:test.run_tests", extras = ["test"], type = "console" }

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
  • I am on the latest stable Poetry version, installed using a recommended method.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have consulted the FAQ and blog for any relevant entries or release notes.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

poetry install generates invalid python for console scrips dependent on extras. If you create a project with the documented toml example and then try to run the script:

% poetry install
Installing dependencies from lock file

Installing the current project: poetry-example (0.1.0)

% source .venv/bin/activate

% devtest
Traceback (most recent call last):
  File "/Users/philip/Documents/Development/scratch/venv/bin/devtest", line 6, in <module>
    sys.exit(test.run_tests[test]())
TypeError: 'function' object is not subscriptable

It seems the generated script is wrong. Eg:

#!/Users/philip/Documents/Development/scratch/venv/bin/python
import sys
from poetry_example import test

if __name__ == '__main__':
    sys.exit(test.run_tests[test]())

This should have been:

    sys.exit(test.run_tests())

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions