From 660cf999fa548828d4806edf4bba5fa7b7270494 Mon Sep 17 00:00:00 2001 From: Julien Malard-Adam Date: Sat, 14 Dec 2024 09:34:59 +0530 Subject: [PATCH 01/14] Add unicode entrypoint tests --- tests/test_utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index 22c262db..3f251422 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -259,6 +259,16 @@ class TestParseEntryPoints: ], id="cli-and-gui", ), + pytest.param( + """ + [console_scripts] + நான் = ஓர்.ஒருங்குறி:கட்டளை + """, + [ + (" ", "ஓர்.ஒருங்குறி", "கட்டளை", "console"), + ], + id="unicode", + ), ], ) def test_valid(self, script, expected): From adb619382ca94d373def192e35f13077bd66c6b0 Mon Sep 17 00:00:00 2001 From: Julien Malard-Adam Date: Sat, 14 Dec 2024 09:48:45 +0530 Subject: [PATCH 02/14] Fix for unicode identifiers --- src/installer/utils.py | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/installer/utils.py b/src/installer/utils.py index 7df3e055..61cec2df 100644 --- a/src/installer/utils.py +++ b/src/installer/utils.py @@ -65,16 +65,6 @@ "WheelFilename", ["distribution", "version", "build_tag", "tag"] ) -# Adapted from https://github.com/python/importlib_metadata/blob/v3.4.0/importlib_metadata/__init__.py#L90 -_ENTRYPOINT_REGEX = re.compile( - r""" - (?P[\w.]+)\s* - (:\s*(?P[\w.]+))\s* - (?P\[.*\])?\s*$ - """, - re.VERBOSE | re.UNICODE, -) - # According to https://www.python.org/dev/peps/pep-0427/#id7 SCHEME_NAMES = cast(AllSchemes, ("purelib", "platlib", "headers", "scripts", "data")) @@ -244,16 +234,14 @@ def parse_entrypoints(text: str) -> Iterable[tuple[str, str, str, "ScriptSection for name, value in config.items(section): assert isinstance(name, str) - match = _ENTRYPOINT_REGEX.match(value) - assert match + assert ":" in value - module = match.group("module") - assert isinstance(module, str) + module, attrs = [x.strip() for x in value.split(":", 1)] + assert len(module) - attrs = match.group("attrs") # TODO: make this a proper error, which can be caught. - assert attrs is not None - assert isinstance(attrs, str) + assert len(attrs) + assert all(x.isidentifier() for x in attrs.split(".")) script_section = cast("ScriptSection", section[: -len("_scripts")]) From 42e7c6678852515e4ad5fe4521b34b1e522d6690 Mon Sep 17 00:00:00 2001 From: Julien Malard-Adam Date: Sat, 14 Dec 2024 09:52:29 +0530 Subject: [PATCH 03/14] Fix test --- tests/test_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 3f251422..42af6e69 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -262,10 +262,10 @@ class TestParseEntryPoints: pytest.param( """ [console_scripts] - நான் = ஓர்.ஒருங்குறி:கட்டளை + "நான்" = "ஓர்.ஒருங்குறி:கட்டளை" """, [ - (" ", "ஓர்.ஒருங்குறி", "கட்டளை", "console"), + ("நான்", "ஓர்.ஒருங்குறி", "கட்டளை", "console"), ], id="unicode", ), From 096c3c6db7151f28bdadb97307b15bdde7640805 Mon Sep 17 00:00:00 2001 From: Julien Malard-Adam Date: Sat, 14 Dec 2024 09:57:23 +0530 Subject: [PATCH 04/14] Fix tests --- tests/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 42af6e69..f61fb491 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -262,7 +262,7 @@ class TestParseEntryPoints: pytest.param( """ [console_scripts] - "நான்" = "ஓர்.ஒருங்குறி:கட்டளை" + நான் = ஓர்.ஒருங்குறி:கட்டளை """, [ ("நான்", "ஓர்.ஒருங்குறி", "கட்டளை", "console"), From 7ecc194c89953ca2154d02b36e5ebe5c54b8ab87 Mon Sep 17 00:00:00 2001 From: Julien Malard-Adam Date: Sat, 14 Dec 2024 11:04:59 +0530 Subject: [PATCH 05/14] Assert `module` is identifier --- src/installer/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/installer/utils.py b/src/installer/utils.py index 61cec2df..3c489fd0 100644 --- a/src/installer/utils.py +++ b/src/installer/utils.py @@ -237,7 +237,7 @@ def parse_entrypoints(text: str) -> Iterable[tuple[str, str, str, "ScriptSection assert ":" in value module, attrs = [x.strip() for x in value.split(":", 1)] - assert len(module) + assert module.isidentifier() # TODO: make this a proper error, which can be caught. assert len(attrs) From ad98b72af78acd902050accbc5325be49b330f7b Mon Sep 17 00:00:00 2001 From: Julien Malard-Adam Date: Sat, 14 Dec 2024 11:10:11 +0530 Subject: [PATCH 06/14] Add error messages --- src/installer/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/installer/utils.py b/src/installer/utils.py index 3c489fd0..aac8d54c 100644 --- a/src/installer/utils.py +++ b/src/installer/utils.py @@ -237,11 +237,11 @@ def parse_entrypoints(text: str) -> Iterable[tuple[str, str, str, "ScriptSection assert ":" in value module, attrs = [x.strip() for x in value.split(":", 1)] - assert module.isidentifier() + assert module.isidentifier(), f"{module} is not a valid identifier" # TODO: make this a proper error, which can be caught. - assert len(attrs) - assert all(x.isidentifier() for x in attrs.split(".")) + assert len(attrs), "Attributes are empty" + assert all(x.isidentifier() for x in attrs.split(".")), f"{attrs} are not all valid identifiers" script_section = cast("ScriptSection", section[: -len("_scripts")]) From 5f4d964c7a975a564b11476153df2b83b7cdb6c3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 14 Dec 2024 05:40:21 +0000 Subject: [PATCH 07/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/installer/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/installer/utils.py b/src/installer/utils.py index aac8d54c..35289bb0 100644 --- a/src/installer/utils.py +++ b/src/installer/utils.py @@ -241,7 +241,9 @@ def parse_entrypoints(text: str) -> Iterable[tuple[str, str, str, "ScriptSection # TODO: make this a proper error, which can be caught. assert len(attrs), "Attributes are empty" - assert all(x.isidentifier() for x in attrs.split(".")), f"{attrs} are not all valid identifiers" + assert all( + x.isidentifier() for x in attrs.split(".") + ), f"{attrs} are not all valid identifiers" script_section = cast("ScriptSection", section[: -len("_scripts")]) From 7ffd66163f4f22364c34d7935734bb54003bd9a9 Mon Sep 17 00:00:00 2001 From: Julien Malard-Adam Date: Sat, 14 Dec 2024 11:12:26 +0530 Subject: [PATCH 08/14] Oops --- src/installer/utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/installer/utils.py b/src/installer/utils.py index 35289bb0..ff73bdb7 100644 --- a/src/installer/utils.py +++ b/src/installer/utils.py @@ -237,14 +237,14 @@ def parse_entrypoints(text: str) -> Iterable[tuple[str, str, str, "ScriptSection assert ":" in value module, attrs = [x.strip() for x in value.split(":", 1)] - assert module.isidentifier(), f"{module} is not a valid identifier" + assert all( + x.isidentifier() for x in module.split(".") + ), f"{module} are not all valid identifiers" # TODO: make this a proper error, which can be caught. assert len(attrs), "Attributes are empty" - assert all( - x.isidentifier() for x in attrs.split(".") - ), f"{attrs} are not all valid identifiers" - + assert attrs.isidentifier(), f"{attrs} is not a valid identifier" + script_section = cast("ScriptSection", section[: -len("_scripts")]) yield name, module, attrs, script_section From 6c4fc2bb0a733ef1b09fa8e28b1597acb6497733 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 14 Dec 2024 05:42:36 +0000 Subject: [PATCH 09/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/installer/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/installer/utils.py b/src/installer/utils.py index ff73bdb7..606125d1 100644 --- a/src/installer/utils.py +++ b/src/installer/utils.py @@ -244,7 +244,7 @@ def parse_entrypoints(text: str) -> Iterable[tuple[str, str, str, "ScriptSection # TODO: make this a proper error, which can be caught. assert len(attrs), "Attributes are empty" assert attrs.isidentifier(), f"{attrs} is not a valid identifier" - + script_section = cast("ScriptSection", section[: -len("_scripts")]) yield name, module, attrs, script_section From 0961c11cd40cf7ff19c21e6c531d2f8d5fdb61ea Mon Sep 17 00:00:00 2001 From: Julien Malard-Adam Date: Fri, 7 Feb 2025 16:08:59 -0500 Subject: [PATCH 10/14] Parse and ignore extras --- src/installer/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/installer/utils.py b/src/installer/utils.py index 606125d1..8edd8456 100644 --- a/src/installer/utils.py +++ b/src/installer/utils.py @@ -241,6 +241,9 @@ def parse_entrypoints(text: str) -> Iterable[tuple[str, str, str, "ScriptSection x.isidentifier() for x in module.split(".") ), f"{module} are not all valid identifiers" + if "[" in attrs and "]" in attrs: + attrs, extras = [x.strip() for x in value.split("[", 1)] + # TODO: make this a proper error, which can be caught. assert len(attrs), "Attributes are empty" assert attrs.isidentifier(), f"{attrs} is not a valid identifier" From bf0faae3c134e9df17db12b68ff72f81163bba9e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 7 Feb 2025 21:09:21 +0000 Subject: [PATCH 11/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/installer/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/installer/utils.py b/src/installer/utils.py index 8edd8456..5186204b 100644 --- a/src/installer/utils.py +++ b/src/installer/utils.py @@ -237,9 +237,9 @@ def parse_entrypoints(text: str) -> Iterable[tuple[str, str, str, "ScriptSection assert ":" in value module, attrs = [x.strip() for x in value.split(":", 1)] - assert all( - x.isidentifier() for x in module.split(".") - ), f"{module} are not all valid identifiers" + assert all(x.isidentifier() for x in module.split(".")), ( + f"{module} are not all valid identifiers" + ) if "[" in attrs and "]" in attrs: attrs, extras = [x.strip() for x in value.split("[", 1)] From fe1158e4b18ccb000681c0c8c1984dd7827737df Mon Sep 17 00:00:00 2001 From: Julien Malard-Adam Date: Fri, 7 Feb 2025 16:10:07 -0500 Subject: [PATCH 12/14] Add test for extras in console scripts --- tests/test_utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index f61fb491..f1196e00 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -269,6 +269,16 @@ class TestParseEntryPoints: ], id="unicode", ), + pytest.param( + """ + [console_scripts] + நான் = ஓர்.ஒருங்குறி:கட்டளை[some, extras] + """, + [ + ("நான்", "ஓர்.ஒருங்குறி", "கட்டளை", "console"), + ], + id="unicode", + ), ], ) def test_valid(self, script, expected): From de994ceff48c202cf3e4a6bd1e1083dcb7773180 Mon Sep 17 00:00:00 2001 From: Julien Malard-Adam Date: Fri, 7 Feb 2025 16:14:27 -0500 Subject: [PATCH 13/14] Fix extras string (no commas) --- tests/test_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index f1196e00..5e50b9e0 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -272,12 +272,12 @@ class TestParseEntryPoints: pytest.param( """ [console_scripts] - நான் = ஓர்.ஒருங்குறி:கட்டளை[some, extras] + நான் = ஓர்.ஒருங்குறி:கட்டளை[கூடுதல்] """, [ ("நான்", "ஓர்.ஒருங்குறி", "கட்டளை", "console"), ], - id="unicode", + id="unicode with extras", ), ], ) From 982caac234345d9434ba0b48f489fa3e5d7623bc Mon Sep 17 00:00:00 2001 From: Julien Malard-Adam Date: Fri, 7 Feb 2025 16:15:08 -0500 Subject: [PATCH 14/14] Fix splitting of attrs and extras --- src/installer/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/installer/utils.py b/src/installer/utils.py index 5186204b..e27644cc 100644 --- a/src/installer/utils.py +++ b/src/installer/utils.py @@ -242,7 +242,7 @@ def parse_entrypoints(text: str) -> Iterable[tuple[str, str, str, "ScriptSection ) if "[" in attrs and "]" in attrs: - attrs, extras = [x.strip() for x in value.split("[", 1)] + attrs, extras = [x.strip() for x in attrs.split("[", 1)] # TODO: make this a proper error, which can be caught. assert len(attrs), "Attributes are empty"