From 16be29d04f544c7a6d11a2024dd2649a2d4f4e54 Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Fri, 7 May 2021 02:38:52 +0200 Subject: [PATCH] cleanup script file implementation This change refactors implementation and tests relating to script file specifications. Relates-to: #40 Relates-to: python-poetry#241 --- poetry/core/masonry/builders/builder.py | 69 +++++++-------- .../complete/bin/{script1.sh => script.sh} | 0 .../builders/fixtures/complete/pyproject.toml | 7 +- .../fixtures/missing_script_files/README.rst | 2 - .../missing_script_files/__init__.py | 0 .../missing_script_files/pyproject.toml | 15 ---- .../script_callable_legacy_string/README.rst | 2 + .../my_package/__init__.py | 1 + .../pyproject.toml | 19 ++++ .../script_callable_legacy_table/README.rst | 2 + .../my_package/__init__.py | 1 + .../pyproject.toml | 21 +++++ .../script_file_invalid_definition/README.rst | 4 - .../bin/script.sh | 1 - .../pyproject.toml | 15 ---- .../__init__.py | 0 .../script_reference_console/README.rst | 2 + .../my_package/__init__.py | 1 + .../script_reference_console/pyproject.toml | 21 +++++ .../fixtures/script_reference_file/README.rst | 2 + .../script_reference_file/bin/script.sh | 3 + .../my_package/__init__.py | 1 + .../script_reference_file/pyproject.toml | 19 ++++ .../README.rst | 2 + .../bin/script.sh | 3 + .../my_package/__init__.py | 1 + .../pyproject.toml | 19 ++++ .../script_reference_file_missing/README.rst | 2 + .../my_package/__init__.py | 1 + .../pyproject.toml | 19 ++++ tests/masonry/builders/test_builder.py | 87 ++++++++++++++++++- tests/masonry/builders/test_complete.py | 9 +- tests/masonry/builders/test_sdist.py | 4 +- tests/masonry/test_api.py | 1 - 34 files changed, 264 insertions(+), 92 deletions(-) rename tests/masonry/builders/fixtures/complete/bin/{script1.sh => script.sh} (100%) delete mode 100644 tests/masonry/builders/fixtures/missing_script_files/README.rst delete mode 100644 tests/masonry/builders/fixtures/missing_script_files/missing_script_files/__init__.py delete mode 100644 tests/masonry/builders/fixtures/missing_script_files/pyproject.toml create mode 100644 tests/masonry/builders/fixtures/script_callable_legacy_string/README.rst create mode 100644 tests/masonry/builders/fixtures/script_callable_legacy_string/my_package/__init__.py create mode 100644 tests/masonry/builders/fixtures/script_callable_legacy_string/pyproject.toml create mode 100644 tests/masonry/builders/fixtures/script_callable_legacy_table/README.rst create mode 100644 tests/masonry/builders/fixtures/script_callable_legacy_table/my_package/__init__.py create mode 100644 tests/masonry/builders/fixtures/script_callable_legacy_table/pyproject.toml delete mode 100644 tests/masonry/builders/fixtures/script_file_invalid_definition/README.rst delete mode 100644 tests/masonry/builders/fixtures/script_file_invalid_definition/bin/script.sh delete mode 100644 tests/masonry/builders/fixtures/script_file_invalid_definition/pyproject.toml delete mode 100644 tests/masonry/builders/fixtures/script_file_invalid_definition/script_file_invalid_definition/__init__.py create mode 100644 tests/masonry/builders/fixtures/script_reference_console/README.rst create mode 100644 tests/masonry/builders/fixtures/script_reference_console/my_package/__init__.py create mode 100644 tests/masonry/builders/fixtures/script_reference_console/pyproject.toml create mode 100644 tests/masonry/builders/fixtures/script_reference_file/README.rst create mode 100644 tests/masonry/builders/fixtures/script_reference_file/bin/script.sh create mode 100644 tests/masonry/builders/fixtures/script_reference_file/my_package/__init__.py create mode 100644 tests/masonry/builders/fixtures/script_reference_file/pyproject.toml create mode 100644 tests/masonry/builders/fixtures/script_reference_file_invalid_definition/README.rst create mode 100644 tests/masonry/builders/fixtures/script_reference_file_invalid_definition/bin/script.sh create mode 100644 tests/masonry/builders/fixtures/script_reference_file_invalid_definition/my_package/__init__.py create mode 100644 tests/masonry/builders/fixtures/script_reference_file_invalid_definition/pyproject.toml create mode 100644 tests/masonry/builders/fixtures/script_reference_file_missing/README.rst create mode 100644 tests/masonry/builders/fixtures/script_reference_file_missing/my_package/__init__.py create mode 100644 tests/masonry/builders/fixtures/script_reference_file_missing/pyproject.toml diff --git a/poetry/core/masonry/builders/builder.py b/poetry/core/masonry/builders/builder.py index 7aa2dfd7c..9797b1e10 100644 --- a/poetry/core/masonry/builders/builder.py +++ b/poetry/core/masonry/builders/builder.py @@ -285,50 +285,36 @@ def convert_entry_points(self) -> Dict[str, List[str]]: result = defaultdict(list) # Scripts -> Entry points - for name, ep in self._poetry.local_config.get("scripts", {}).items(): - extras: str = "" - module_path: str = "" + for name, specification in self._poetry.local_config.get("scripts", {}).items(): + if isinstance(specification, str): + # TODO: deprecate this in favour or reference + specification = {"reference": specification, "type": "console"} - # Currently we support 2 legacy and 1 new format: - # (legacy) my_script = 'my_package.main:entry' - # (legacy) my_script = { callable = 'my_package.main:entry' } - # (supported) my_script = { reference = 'my_package.main:entry', type = "console" } - - if isinstance(ep, str): + if "callable" in specification: warnings.warn( - "This way of declaring console scripts is deprecated and will be removed in a future version. " - 'Use reference = "{}", type = "console" instead.'.format(ep), + f"Use of callable in script specification ({name}) is deprecated. Use reference instead.", DeprecationWarning, ) - extras = "" - module_path = ep - elif isinstance(ep, dict) and ( - ep.get("type") == "console" - or "callable" in ep # Supporting both new and legacy format for now - ): - if "callable" in ep: - warnings.warn( - "Using the keyword callable is deprecated and will be removed in a future version. " - 'Use reference = "{}", type = "console" instead.'.format( - ep["callable"] - ), - DeprecationWarning, - ) + specification = { + "reference": specification["callable"], + "type": "console", + } - extras = "[{}]".format(", ".join(ep["extras"])) - module_path = ep.get("reference", ep.get("callable")) - else: + if specification.get("type") != "console": continue - result["console_scripts"].append( - "{} = {}{}".format(name, module_path, extras) - ) + extras = specification.get("extras", []) + extras = f"[{', '.join(extras)}]" if extras else "" + reference = specification.get("reference") + + if reference: + result["console_scripts"].append(f"{name} = {reference}{extras}") # Plugins -> entry points plugins = self._poetry.local_config.get("plugins", {}) for groupname, group in plugins.items(): - for name, ep in sorted(group.items()): - result[groupname].append("{} = {}".format(name, ep)) + for name, specification in sorted(group.items()): + result[groupname].append(f"{name} = {specification}") for groupname in result: result[groupname] = sorted(result[groupname]) @@ -338,21 +324,26 @@ def convert_entry_points(self) -> Dict[str, List[str]]: def convert_script_files(self) -> List[Path]: script_files: List[Path] = [] - for _, ep in self._poetry.local_config.get("scripts", {}).items(): - if isinstance(ep, dict) and ep.get("type") == "file": - source = ep["reference"] + for name, specification in self._poetry.local_config.get("scripts", {}).items(): + if isinstance(specification, dict) and specification.get("type") == "file": + source = specification["reference"] if Path(source).is_absolute(): raise RuntimeError( - "{} is an absolute path. Expected relative path.".format(source) + f"{source} in {name} is an absolute path. Expected relative path." ) abs_path = Path.joinpath(self._path, source) if not abs_path.exists(): - raise RuntimeError("{} file-script is not found.".format(abs_path)) + raise RuntimeError( + f"{abs_path} in script specification ({name}) is not found." + ) + if not abs_path.is_file(): - raise RuntimeError("{} file-script is not a file.".format(abs_path)) + raise RuntimeError( + f"{abs_path} in script specification ({name}) is not a file." + ) script_files.append(abs_path) diff --git a/tests/masonry/builders/fixtures/complete/bin/script1.sh b/tests/masonry/builders/fixtures/complete/bin/script.sh similarity index 100% rename from tests/masonry/builders/fixtures/complete/bin/script1.sh rename to tests/masonry/builders/fixtures/complete/bin/script.sh diff --git a/tests/masonry/builders/fixtures/complete/pyproject.toml b/tests/masonry/builders/fixtures/complete/pyproject.toml index 711005450..8b7d2c6b6 100644 --- a/tests/masonry/builders/fixtures/complete/pyproject.toml +++ b/tests/masonry/builders/fixtures/complete/pyproject.toml @@ -36,7 +36,7 @@ cachy = { version = "^0.2.0", extras = ["msgpack"] } [tool.poetry.dependencies.pendulum] version = "^1.4" -markers= 'python_version ~= "2.7" and sys_platform == "win32" or python_version in "3.4 3.5"' +markers = 'python_version ~= "2.7" and sys_platform == "win32" or python_version in "3.4 3.5"' optional = true [tool.poetry.dev-dependencies] @@ -48,9 +48,8 @@ time = ["pendulum"] [tool.poetry.scripts] my-script = "my_package:main" my-2nd-script = "my_package:main2" -extra-script-legacy = {callable = "my_package.extra_legacy:main", extras = ["time"]} -extra-script = {reference = "my_package.extra:main", extras = ["time"], type = "console"} -sh-script = {reference = "bin/script1.sh", type = "file"} +file-script = { reference = "bin/script.sh", type = "file" } +extra-script = { reference = "my_package.extra:main", extras = ["time"], type = "console" } [tool.poetry.urls] diff --git a/tests/masonry/builders/fixtures/missing_script_files/README.rst b/tests/masonry/builders/fixtures/missing_script_files/README.rst deleted file mode 100644 index f127696c5..000000000 --- a/tests/masonry/builders/fixtures/missing_script_files/README.rst +++ /dev/null @@ -1,2 +0,0 @@ -Missing Script Files -======== \ No newline at end of file diff --git a/tests/masonry/builders/fixtures/missing_script_files/missing_script_files/__init__.py b/tests/masonry/builders/fixtures/missing_script_files/missing_script_files/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/masonry/builders/fixtures/missing_script_files/pyproject.toml b/tests/masonry/builders/fixtures/missing_script_files/pyproject.toml deleted file mode 100644 index 94eee3fb1..000000000 --- a/tests/masonry/builders/fixtures/missing_script_files/pyproject.toml +++ /dev/null @@ -1,15 +0,0 @@ -[tool.poetry] -name = "missing-script-files" -version = "0.1" -description = "Some description." -authors = [ - "Sébastien Eustace " -] -readme = "README.rst" - -[tool.poetry.scripts] -missing_file = {reference = "not_existing_folder/not_existing_file.sh", type = "file"} - - -[tool.poetry.dependencies] -python = "3.6" \ No newline at end of file diff --git a/tests/masonry/builders/fixtures/script_callable_legacy_string/README.rst b/tests/masonry/builders/fixtures/script_callable_legacy_string/README.rst new file mode 100644 index 000000000..f7fe15470 --- /dev/null +++ b/tests/masonry/builders/fixtures/script_callable_legacy_string/README.rst @@ -0,0 +1,2 @@ +My Package +========== diff --git a/tests/masonry/builders/fixtures/script_callable_legacy_string/my_package/__init__.py b/tests/masonry/builders/fixtures/script_callable_legacy_string/my_package/__init__.py new file mode 100644 index 000000000..10aa336ce --- /dev/null +++ b/tests/masonry/builders/fixtures/script_callable_legacy_string/my_package/__init__.py @@ -0,0 +1 @@ +__version__ = "1.2.3" diff --git a/tests/masonry/builders/fixtures/script_callable_legacy_string/pyproject.toml b/tests/masonry/builders/fixtures/script_callable_legacy_string/pyproject.toml new file mode 100644 index 000000000..2c949a9d5 --- /dev/null +++ b/tests/masonry/builders/fixtures/script_callable_legacy_string/pyproject.toml @@ -0,0 +1,19 @@ +[tool.poetry] +name = "my-package" +version = "1.2.3" +description = "Some description." +authors = [ + "Poetry Maintainers " +] +license = "MIT" +readme = "README.rst" + +[tool.poetry.dependencies] +python = "^3.6" + +[tool.poetry.dev-dependencies] + +[tool.poetry.extras] + +[tool.poetry.scripts] +script-legacy = "my_package:main" diff --git a/tests/masonry/builders/fixtures/script_callable_legacy_table/README.rst b/tests/masonry/builders/fixtures/script_callable_legacy_table/README.rst new file mode 100644 index 000000000..f7fe15470 --- /dev/null +++ b/tests/masonry/builders/fixtures/script_callable_legacy_table/README.rst @@ -0,0 +1,2 @@ +My Package +========== diff --git a/tests/masonry/builders/fixtures/script_callable_legacy_table/my_package/__init__.py b/tests/masonry/builders/fixtures/script_callable_legacy_table/my_package/__init__.py new file mode 100644 index 000000000..10aa336ce --- /dev/null +++ b/tests/masonry/builders/fixtures/script_callable_legacy_table/my_package/__init__.py @@ -0,0 +1 @@ +__version__ = "1.2.3" diff --git a/tests/masonry/builders/fixtures/script_callable_legacy_table/pyproject.toml b/tests/masonry/builders/fixtures/script_callable_legacy_table/pyproject.toml new file mode 100644 index 000000000..cab2488f5 --- /dev/null +++ b/tests/masonry/builders/fixtures/script_callable_legacy_table/pyproject.toml @@ -0,0 +1,21 @@ +[tool.poetry] +name = "my-package" +version = "1.2.3" +description = "Some description." +authors = [ + "Poetry Maintainers " +] +license = "MIT" +readme = "README.rst" + +[tool.poetry.dependencies] +python = "^3.6" + +[tool.poetry.dev-dependencies] + +[tool.poetry.extras] +time = [] + +[tool.poetry.scripts] +script-legacy = { callable = "my_package.extra_legacy:main" } +extra-script-legacy = { callable = "my_package.extra_legacy:main", extras = ["time"] } diff --git a/tests/masonry/builders/fixtures/script_file_invalid_definition/README.rst b/tests/masonry/builders/fixtures/script_file_invalid_definition/README.rst deleted file mode 100644 index 4f2f20661..000000000 --- a/tests/masonry/builders/fixtures/script_file_invalid_definition/README.rst +++ /dev/null @@ -1,4 +0,0 @@ -Script File Invalid Definition -======== - -This is a use case where the user provides a pyproject.toml where the file script definition is wrong. \ No newline at end of file diff --git a/tests/masonry/builders/fixtures/script_file_invalid_definition/bin/script.sh b/tests/masonry/builders/fixtures/script_file_invalid_definition/bin/script.sh deleted file mode 100644 index 2fcee7113..000000000 --- a/tests/masonry/builders/fixtures/script_file_invalid_definition/bin/script.sh +++ /dev/null @@ -1 +0,0 @@ -echo "Hello World" \ No newline at end of file diff --git a/tests/masonry/builders/fixtures/script_file_invalid_definition/pyproject.toml b/tests/masonry/builders/fixtures/script_file_invalid_definition/pyproject.toml deleted file mode 100644 index 7f2601769..000000000 --- a/tests/masonry/builders/fixtures/script_file_invalid_definition/pyproject.toml +++ /dev/null @@ -1,15 +0,0 @@ -[tool.poetry] -name = "script_file_invalid_definition" -version = "0.1" -description = "Some description." -authors = [ - "Sébastien Eustace " -] -readme = "README.rst" - -[tool.poetry.scripts] -invalid_definition = {reference = "bin/script.sh", type = "ffiillee"} - - -[tool.poetry.dependencies] -python = "3.6" \ No newline at end of file diff --git a/tests/masonry/builders/fixtures/script_file_invalid_definition/script_file_invalid_definition/__init__.py b/tests/masonry/builders/fixtures/script_file_invalid_definition/script_file_invalid_definition/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/masonry/builders/fixtures/script_reference_console/README.rst b/tests/masonry/builders/fixtures/script_reference_console/README.rst new file mode 100644 index 000000000..f7fe15470 --- /dev/null +++ b/tests/masonry/builders/fixtures/script_reference_console/README.rst @@ -0,0 +1,2 @@ +My Package +========== diff --git a/tests/masonry/builders/fixtures/script_reference_console/my_package/__init__.py b/tests/masonry/builders/fixtures/script_reference_console/my_package/__init__.py new file mode 100644 index 000000000..10aa336ce --- /dev/null +++ b/tests/masonry/builders/fixtures/script_reference_console/my_package/__init__.py @@ -0,0 +1 @@ +__version__ = "1.2.3" diff --git a/tests/masonry/builders/fixtures/script_reference_console/pyproject.toml b/tests/masonry/builders/fixtures/script_reference_console/pyproject.toml new file mode 100644 index 000000000..a55800b67 --- /dev/null +++ b/tests/masonry/builders/fixtures/script_reference_console/pyproject.toml @@ -0,0 +1,21 @@ +[tool.poetry] +name = "my-package" +version = "1.2.3" +description = "Some description." +authors = [ + "Poetry Maintainers " +] +license = "MIT" +readme = "README.rst" + +[tool.poetry.dependencies] +python = "^3.6" + +[tool.poetry.dev-dependencies] + +[tool.poetry.extras] +time = [] + +[tool.poetry.scripts] +script = { reference = "my_package.extra:main", type = "console" } +extra-script = { reference = "my_package.extra:main", extras = ["time"], type = "console" } diff --git a/tests/masonry/builders/fixtures/script_reference_file/README.rst b/tests/masonry/builders/fixtures/script_reference_file/README.rst new file mode 100644 index 000000000..f7fe15470 --- /dev/null +++ b/tests/masonry/builders/fixtures/script_reference_file/README.rst @@ -0,0 +1,2 @@ +My Package +========== diff --git a/tests/masonry/builders/fixtures/script_reference_file/bin/script.sh b/tests/masonry/builders/fixtures/script_reference_file/bin/script.sh new file mode 100644 index 000000000..2a9686ac6 --- /dev/null +++ b/tests/masonry/builders/fixtures/script_reference_file/bin/script.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +echo "Hello World!" \ No newline at end of file diff --git a/tests/masonry/builders/fixtures/script_reference_file/my_package/__init__.py b/tests/masonry/builders/fixtures/script_reference_file/my_package/__init__.py new file mode 100644 index 000000000..10aa336ce --- /dev/null +++ b/tests/masonry/builders/fixtures/script_reference_file/my_package/__init__.py @@ -0,0 +1 @@ +__version__ = "1.2.3" diff --git a/tests/masonry/builders/fixtures/script_reference_file/pyproject.toml b/tests/masonry/builders/fixtures/script_reference_file/pyproject.toml new file mode 100644 index 000000000..973a94c14 --- /dev/null +++ b/tests/masonry/builders/fixtures/script_reference_file/pyproject.toml @@ -0,0 +1,19 @@ +[tool.poetry] +name = "my-package" +version = "1.2.3" +description = "Some description." +authors = [ + "Poetry Maintainers " +] +license = "MIT" +readme = "README.rst" + +[tool.poetry.dependencies] +python = "^3.6" + +[tool.poetry.dev-dependencies] + +[tool.poetry.extras] + +[tool.poetry.scripts] +sh-script = { reference = "bin/script.sh", type = "file" } diff --git a/tests/masonry/builders/fixtures/script_reference_file_invalid_definition/README.rst b/tests/masonry/builders/fixtures/script_reference_file_invalid_definition/README.rst new file mode 100644 index 000000000..f7fe15470 --- /dev/null +++ b/tests/masonry/builders/fixtures/script_reference_file_invalid_definition/README.rst @@ -0,0 +1,2 @@ +My Package +========== diff --git a/tests/masonry/builders/fixtures/script_reference_file_invalid_definition/bin/script.sh b/tests/masonry/builders/fixtures/script_reference_file_invalid_definition/bin/script.sh new file mode 100644 index 000000000..2a9686ac6 --- /dev/null +++ b/tests/masonry/builders/fixtures/script_reference_file_invalid_definition/bin/script.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +echo "Hello World!" \ No newline at end of file diff --git a/tests/masonry/builders/fixtures/script_reference_file_invalid_definition/my_package/__init__.py b/tests/masonry/builders/fixtures/script_reference_file_invalid_definition/my_package/__init__.py new file mode 100644 index 000000000..10aa336ce --- /dev/null +++ b/tests/masonry/builders/fixtures/script_reference_file_invalid_definition/my_package/__init__.py @@ -0,0 +1 @@ +__version__ = "1.2.3" diff --git a/tests/masonry/builders/fixtures/script_reference_file_invalid_definition/pyproject.toml b/tests/masonry/builders/fixtures/script_reference_file_invalid_definition/pyproject.toml new file mode 100644 index 000000000..7c6aa5627 --- /dev/null +++ b/tests/masonry/builders/fixtures/script_reference_file_invalid_definition/pyproject.toml @@ -0,0 +1,19 @@ +[tool.poetry] +name = "my-package" +version = "1.2.3" +description = "Some description." +authors = [ + "Poetry Maintainers " +] +license = "MIT" +readme = "README.rst" + +[tool.poetry.dependencies] +python = "^3.6" + +[tool.poetry.dev-dependencies] + +[tool.poetry.extras] + +[tool.poetry.scripts] +invalid_definition = { reference = "bin/script.sh", type = "ffiillee" } diff --git a/tests/masonry/builders/fixtures/script_reference_file_missing/README.rst b/tests/masonry/builders/fixtures/script_reference_file_missing/README.rst new file mode 100644 index 000000000..f7fe15470 --- /dev/null +++ b/tests/masonry/builders/fixtures/script_reference_file_missing/README.rst @@ -0,0 +1,2 @@ +My Package +========== diff --git a/tests/masonry/builders/fixtures/script_reference_file_missing/my_package/__init__.py b/tests/masonry/builders/fixtures/script_reference_file_missing/my_package/__init__.py new file mode 100644 index 000000000..10aa336ce --- /dev/null +++ b/tests/masonry/builders/fixtures/script_reference_file_missing/my_package/__init__.py @@ -0,0 +1 @@ +__version__ = "1.2.3" diff --git a/tests/masonry/builders/fixtures/script_reference_file_missing/pyproject.toml b/tests/masonry/builders/fixtures/script_reference_file_missing/pyproject.toml new file mode 100644 index 000000000..973a94c14 --- /dev/null +++ b/tests/masonry/builders/fixtures/script_reference_file_missing/pyproject.toml @@ -0,0 +1,19 @@ +[tool.poetry] +name = "my-package" +version = "1.2.3" +description = "Some description." +authors = [ + "Poetry Maintainers " +] +license = "MIT" +readme = "README.rst" + +[tool.poetry.dependencies] +python = "^3.6" + +[tool.poetry.dev-dependencies] + +[tool.poetry.extras] + +[tool.poetry.scripts] +sh-script = { reference = "bin/script.sh", type = "file" } diff --git a/tests/masonry/builders/test_builder.py b/tests/masonry/builders/test_builder.py index af634e5e4..590266421 100644 --- a/tests/masonry/builders/test_builder.py +++ b/tests/masonry/builders/test_builder.py @@ -159,23 +159,104 @@ def test_metadata_with_url_dependencies(): def test_missing_script_files_throws_error(): builder = Builder( Factory().create_poetry( - Path(__file__).parent / "fixtures" / "missing_script_files" + Path(__file__).parent / "fixtures" / "script_reference_file_missing" ) ) with pytest.raises(RuntimeError) as err: builder.convert_script_files() - assert "file-script is not found." in err.value.args[0] + assert "is not found." in err.value.args[0] def test_invalid_script_files_definition(): with pytest.raises(RuntimeError) as err: Builder( Factory().create_poetry( - Path(__file__).parent / "fixtures" / "script_file_invalid_definition" + Path(__file__).parent + / "fixtures" + / "script_reference_file_invalid_definition" ) ) assert "configuration is invalid" in err.value.args[0] assert "[scripts.invalid_definition]" in err.value.args[0] + + +@pytest.mark.parametrize( + "fixture", + [ + "script_callable_legacy_table", + ], +) +def test_entrypoint_scripts_legacy_warns(fixture): + with pytest.warns(DeprecationWarning): + Builder( + Factory().create_poetry(Path(__file__).parent / "fixtures" / fixture) + ).convert_entry_points() + + +@pytest.mark.parametrize( + "fixture, result", + [ + ( + "script_callable_legacy_table", + { + "console_scripts": [ + "extra-script-legacy = my_package.extra_legacy:main", + "script-legacy = my_package.extra_legacy:main", + ] + }, + ), + ( + "script_callable_legacy_string", + {"console_scripts": ["script-legacy = my_package:main"]}, + ), + ( + "script_reference_console", + { + "console_scripts": [ + "extra-script = my_package.extra:main[time]", + "script = my_package.extra:main", + ] + }, + ), + ( + "script_reference_file", + {}, + ), + ], +) +@pytest.mark.filterwarnings("ignore::DeprecationWarning") +def test_builder_convert_entry_points(fixture, result): + entry_points = Builder( + Factory().create_poetry(Path(__file__).parent / "fixtures" / fixture) + ).convert_entry_points() + assert entry_points == result + + +@pytest.mark.parametrize( + "fixture, result", + [ + ( + "script_callable_legacy_table", + [], + ), + ( + "script_callable_legacy_string", + [], + ), + ( + "script_reference_console", + [], + ), + ( + "script_reference_file", + [Path("bin") / "script.sh"], + ), + ], +) +def test_builder_convert_script_files(fixture, result): + project_root = Path(__file__).parent / "fixtures" / fixture + script_files = Builder(Factory().create_poetry(project_root)).convert_script_files() + assert [p.relative_to(project_root) for p in script_files] == result diff --git a/tests/masonry/builders/test_complete.py b/tests/masonry/builders/test_complete.py index 7b7a986c8..50e919552 100644 --- a/tests/masonry/builders/test_complete.py +++ b/tests/masonry/builders/test_complete.py @@ -223,10 +223,10 @@ def test_complete(): try: assert "my_package/sub_pgk1/extra_file.xml" not in zip.namelist() - assert "my-package-1.2.3.data/scripts/script1.sh" in zip.namelist() + assert "my-package-1.2.3.data/scripts/script.sh" in zip.namelist() assert ( "Hello World" - in zip.read("my-package-1.2.3.data/scripts/script1.sh").decode() + in zip.read("my-package-1.2.3.data/scripts/script.sh").decode() ) entry_points = zip.read("my_package-1.2.3.dist-info/entry_points.txt") @@ -236,7 +236,6 @@ def test_complete(): == """\ [console_scripts] extra-script=my_package.extra:main[time] -extra-script-legacy=my_package.extra_legacy:main[time] my-2nd-script=my_package:main2 my-script=my_package:main @@ -307,7 +306,6 @@ def test_complete(): "my_package/sub_pkg1/__init__.py", "my_package/sub_pkg2/__init__.py", "my_package/sub_pkg2/data2/data.json", - "my-package-1.2.3.data/scripts/script1.sh", "my_package-1.2.3.dist-info/entry_points.txt", "my_package-1.2.3.dist-info/LICENSE", "my_package-1.2.3.dist-info/WHEEL", @@ -345,7 +343,7 @@ def test_complete_no_vcs(): "my_package/sub_pkg1/__init__.py", "my_package/sub_pkg2/__init__.py", "my_package/sub_pkg2/data2/data.json", - "my-package-1.2.3.data/scripts/script1.sh", + "my-package-1.2.3.data/scripts/script.sh", "my_package/sub_pkg3/foo.py", "my_package-1.2.3.dist-info/entry_points.txt", "my_package-1.2.3.dist-info/LICENSE", @@ -364,7 +362,6 @@ def test_complete_no_vcs(): == """\ [console_scripts] extra-script=my_package.extra:main[time] -extra-script-legacy=my_package.extra_legacy:main[time] my-2nd-script=my_package:main2 my-script=my_package:main diff --git a/tests/masonry/builders/test_sdist.py b/tests/masonry/builders/test_sdist.py index 3bb8c0411..c1ed3dc6c 100644 --- a/tests/masonry/builders/test_sdist.py +++ b/tests/masonry/builders/test_sdist.py @@ -126,11 +126,11 @@ def test_make_setup(): assert ns["entry_points"] == { "console_scripts": [ "extra-script = my_package.extra:main[time]", - "extra-script-legacy = my_package.extra_legacy:main[time]", "my-2nd-script = my_package:main2", "my-script = my_package:main", ] } + assert ns["scripts"] == ["bin/script.sh"] assert ns["extras_require"] == { 'time:python_version ~= "2.7" and sys_platform == "win32" or python_version in "3.4 3.5"': [ "pendulum>=1.4,<2.0" @@ -171,7 +171,7 @@ def test_find_files_to_add(): [ Path("LICENSE"), Path("README.rst"), - Path("bin/script1.sh"), + Path("bin/script.sh"), Path("my_package/__init__.py"), Path("my_package/data1/test.json"), Path("my_package/sub_pkg1/__init__.py"), diff --git a/tests/masonry/test_api.py b/tests/masonry/test_api.py index 47afe6ae7..e0c73ab4c 100644 --- a/tests/masonry/test_api.py +++ b/tests/masonry/test_api.py @@ -133,7 +133,6 @@ def test_prepare_metadata_for_build_wheel(): entry_points = """\ [console_scripts] extra-script=my_package.extra:main[time] -extra-script-legacy=my_package.extra_legacy:main[time] my-2nd-script=my_package:main2 my-script=my_package:main