Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecated string defined scripts in favor of reference. Enabled gui scripts. #743

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/poetry/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,17 @@ def validate(
)

# Checking for scripts with extras
# Checking for string scripts
if "scripts" in config:
scripts = config["scripts"]
config_extras = config.get("extras", {})

for name, script in scripts.items():
if isinstance(script, str):
result["warnings"].append(
"String defined scripts are deprecated in favor of reference definition"
)

if not isinstance(script, dict):
continue

Expand Down
5 changes: 3 additions & 2 deletions src/poetry/core/json/schemas/poetry-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@
"type": "string",
"enum": [
"file",
"console"
"console",
"gui"
]
},
"extras": {
Expand All @@ -644,7 +645,7 @@
"properties": {
"callable": {
"$ref": "#/definitions/script-legacy",
"description": "The entry point of the script. Deprecated in favour of reference."
"description": "The entry point of the script. Deprecated in favor of reference."
},
"extras": {
"type": "array",
Expand Down
17 changes: 14 additions & 3 deletions src/poetry/core/masonry/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,17 @@ def convert_entry_points(self) -> dict[str, list[str]]:
# Scripts -> Entry points
for name, specification in self._poetry.local_config.get("scripts", {}).items():
if isinstance(specification, str):
# TODO: deprecate this in favour or reference
warnings.warn(
"String defined scripts are deprecated in favor of reference definition",
DeprecationWarning,
stacklevel=1,
)
specification = {"reference": specification, "type": "console"}

if specification.get("type") != "console":
if (
specification.get("type") != "console"
and specification.get("type") != "gui"
):
continue

extras = specification.get("extras", [])
Expand All @@ -318,8 +325,12 @@ def convert_entry_points(self) -> dict[str, list[str]]:
extras = f"[{', '.join(extras)}]" if extras else ""
reference = specification.get("reference")

if reference:
if not reference:
continue
if specification.get("type") == "console":
result["console_scripts"].append(f"{name} = {reference}{extras}")
if specification.get("type") == "gui":
result["gui_scripts"].append(f"{name} = {reference}{extras}")

# Plugins -> entry points
plugins = self._poetry.local_config.get("plugins", {})
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/complete.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pytest = "^3.0"
pytest-cov = "^2.4"

[tool.poetry.scripts]
my-script = 'my_package:main'
my-script = { reference = "my_package:main", type = "console" }
sample_pyscript = { reference = "script-files/sample_script.py", type= "file" }
sample_shscript = { reference = "script-files/sample_script.sh", type= "file" }

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/pep_517_backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ pytest = "7.1.3"
preview = true

[tool.poetry.scripts]
my-script = "my_package:main"
my-script = { reference = "my_package:main", type = "console"}
2 changes: 1 addition & 1 deletion tests/fixtures/sample_project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pytest = "~3.4"


[tool.poetry.scripts]
my-script = "my_package:main"
my-script = { reference = "my_package:main", type = "console"}


[tool.poetry.plugins."blogtool.parsers"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ pytest = "~3.4"
time = ["pendulum"]

[tool.poetry.scripts]
my-script = "my_package:main"
my-2nd-script = "my_package:main2"
my-script = { reference = "my_package:main", type = "console" }
my-2nd-script = { reference = "my_package:main2", type = "console" }
extra-script = {reference = "my_package.extra:main", extras = ["time"], type = "console"}
4 changes: 2 additions & 2 deletions tests/masonry/builders/fixtures/complete/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ pytest = "~3.4"
time = ["pendulum"]

[tool.poetry.scripts]
my-script = "my_package:main"
my-2nd-script = "my_package:main2"
my-script = { reference = "my_package:main", type = "console" }
my-2nd-script = { reference = "my_package:main2", type = "console" }
file-script = { reference = "bin/script.sh", type = "file" }
extra-script = { reference = "my_package.extra:main", extras = ["time"], type = "console" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ pytest = "~3.4"
time = ["pendulum"]

[tool.poetry.scripts]
my-script = "my_package:main"
my-2nd-script = "my_package:main2"
my-script = { reference = "my_package:main", type="console"}
my-2nd-script = { reference = "my_package:main2", type="console"}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ pytest = "~3.4"
time = ["pendulum"]

[tool.poetry.scripts]
my-script = "my_package:main"
my-2nd-script = "my_package:main2"
my-script = {reference = "my_package:main", type = "console"}
my-2nd-script = {reference = "my_package:main2", type = "console"}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ pytest = "~3.4"
time = ["pendulum"]

[tool.poetry.scripts]
my-script = "my_package:main"
my-2nd-script = "my_package:main2"
my-script = { reference = "my_package:main", type = "console" }
my-2nd-script = { reference = "my_package:main2", type = "console" }
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ python = "~2.7 || ^3.6"
[tool.poetry.dev-dependencies]

[tool.poetry.scripts]
my-script = "my_package:main"
my-script = { reference = "my_package:main", type = "console" }
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ pytest = "~3.4"
time = ["pendulum"]

[tool.poetry.scripts]
my-script = "my_package:main"
my-2nd-script = "my_package:main2"
my-script = {reference = "my_package:main", type="console"}
my-2nd-script = {reference = "my_package:main2", type="console"}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ pytest = "~3.4"
time = ["pendulum"]

[tool.poetry.scripts]
my-script = "my_package:main"
my-2nd-script = "my_package:main2"
my-script = { reference = "my_package:main", type = "console"}
my-2nd-script = { reference = "my_package:main2", type = "console"}
extra-script = {reference = "my_package.extra:main", extras = ["time"], type = "console"}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pytest = "~3.4"
time = ["pendulum"]

[tool.poetry.scripts]
my-script = "my_package:main"
my-2nd-script = "my_package:main2"
my-script = { reference = "my_package:main", type = "console" }
my-2nd-script = { reference = "my_package:main2", type = "console" }

[tool.poetry.urls]
"Issue Tracker" = "https://github.com/python-poetry/poetry/issues"
4 changes: 2 additions & 2 deletions tests/masonry/builders/fixtures/with-include/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ pytest = "~3.4"
time = ["pendulum"]

[tool.poetry.scripts]
my-script = "my_package:main"
my-2nd-script = "my_package:main2"
my-script = { reference = "my_package:main", type="console" }
my-2nd-script = { reference = "my_package:main2", type="console" }
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ pytest = "~3.4"
time = ["pendulum"]

[tool.poetry.scripts]
my-script = "my_package:main"
my-2nd-script = "my_package:main2"
my-script = { reference = "my_package:main", type = "console"}
my-2nd-script = { reference = "my_package:main2", type = "console"}
1 change: 1 addition & 0 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ def test_validate_strict_fails_strict_and_non_strict() -> None:
" https://packaging.python.org/en/latest/specifications/entry-points/#data-model"
" for details."
),
("String defined scripts are deprecated in favor of reference definition"),
],
}

Expand Down
Loading